Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only update resources blocked after shields is active for the site #2507

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export default function shieldsPanelReducer (state: State = { tabs: {}, windows:
state = shieldsPanelState.updateResourceBlocked(
state, tabId, action.details.blockType, action.details.subresource)
if (tabId === currentTabId) {
shieldsPanelState.updateShieldsIconBadgeText(state)
const isShieldsActive: boolean = shieldsPanelState.isShieldsActive(state, tabId)
if (isShieldsActive) {
shieldsPanelState.updateShieldsIconBadgeText(state)
}
}
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const getActiveTabId: shieldState.GetActiveTabId = (state) => state.windo

export const getActiveTabData: shieldState.GetActiveTabData = (state) => state.tabs[getActiveTabId(state)]

export const isShieldsActive = (state: shieldState.State, tabId: number): boolean => {
if (!state.tabs[tabId]) {
return false
}
return state.tabs[tabId].braveShields !== 'block'
}

export const updateActiveTab: shieldState.UpdateActiveTab = (state, windowId, tabId) => {
let windows: shieldState.Windows = { ...state.windows } || {}
windows[windowId] = tabId
Expand Down
34 changes: 34 additions & 0 deletions components/test/brave_extension/state/shieldsPanelState_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ describe('shieldsPanelState test', () => {
})
})
})
describe('isShieldsActive', () => {
it('returns false if tab id can not be found', () => {
const assertion = shieldsPanelState.isShieldsActive(state, 123123123123)
expect(assertion).toBe(false)
})
it('returns false if braveShields is set to `block`', () => {
const newState: State = deepFreeze({
...state,
tabs: {
...state.tabs,
2: {
...state.tabs[2],
braveShields: 'block'
}
}
})
const assertion = shieldsPanelState.isShieldsActive(newState, 2)
expect(assertion).toBe(false)
})
it('returns true if braveShields is not set to block', () => {
const newState: State = deepFreeze({
...state,
tabs: {
...state.tabs,
2: {
...state.tabs[2],
braveShields: 'allow'
}
}
})
const assertion = shieldsPanelState.isShieldsActive(newState, 2)
expect(assertion).toBe(true)
})
})
describe('updateActiveTab', () => {
it('can update focused window', () => {
expect(shieldsPanelState.updateActiveTab(state, 1, 4)).toEqual({
Expand Down