Skip to content

Commit

Permalink
Merge pull request #2507 from brave/ca-888
Browse files Browse the repository at this point in the history
only update resources blocked after shields is active for the site
  • Loading branch information
cezaraugusto committed May 29, 2019
2 parents 6cbbbc6 + a2b6f9b commit adde903
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
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

0 comments on commit adde903

Please sign in to comment.