Skip to content

Commit

Permalink
fix scripts number being different across screens
Browse files Browse the repository at this point in the history
-
scripts now use the same method for checking scripts blocked
fix brave/brave-browser#4228
  • Loading branch information
cezaraugusto committed May 27, 2019
1 parent 2cb0d16 commit 8f1c408
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { unique } from '../helpers/arrayUtils'
import { getTotalResourcesBlocked } from '../helpers/shieldsUtils'
import { setBadgeText, setIcon } from '../background/api/browserActionAPI'
import { requestShieldPanelData } from '../background/api/shieldsAPI'
import { filterNoScriptInfoByWillBlockState } from '../helpers/noScriptUtils'

export const getActiveTabId: shieldState.GetActiveTabId = (state) => state.windows[state.currentWindowId]

Expand Down Expand Up @@ -50,7 +51,6 @@ export const updateTabShieldsData: shieldState.UpdateTabShieldsData = (state, ta
adsBlockedResources: [],
trackersBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
fingerprintingBlockedResources: []
},
...tabs[tabId],
Expand All @@ -73,7 +73,6 @@ export const updateResourceBlocked: shieldState.UpdateResourceBlocked = (state,
adsBlockedResources: [],
trackersBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
fingerprintingBlockedResources: []
},
...tabs[tabId]
Expand All @@ -91,8 +90,7 @@ export const updateResourceBlocked: shieldState.UpdateResourceBlocked = (state,
} else if (blockType === 'javascript') {
tabs[tabId].noScriptInfo = { ...tabs[tabId].noScriptInfo }
tabs[tabId].noScriptInfo[subresource] = { ...{ actuallyBlocked: true, willBlock: true, userInteracted: false } }
tabs[tabId].javascriptBlockedResources = unique([ ...tabs[tabId].javascriptBlockedResources, subresource ])
tabs[tabId].javascriptBlocked = tabs[tabId].javascriptBlockedResources.length
tabs[tabId].javascriptBlocked = filterNoScriptInfoByWillBlockState(Object.entries(tabs[tabId].noScriptInfo), true).length
} else if (blockType === 'fingerprinting') {
tabs[tabId].fingerprintingBlockedResources = unique([ ...tabs[tabId].fingerprintingBlockedResources, subresource ])
tabs[tabId].fingerprintingBlocked = tabs[tabId].fingerprintingBlockedResources.length
Expand All @@ -109,7 +107,7 @@ export const resetBlockingStats: shieldState.ResetBlockingStats = (state, tabId)

export const resetBlockingResources: shieldState.ResetBlockingResources = (state, tabId) => {
const tabs: shieldState.Tabs = { ...state.tabs }
tabs[tabId] = { ...tabs[tabId], ...{ adsBlockedResources: [], trackersBlockedResources: [], httpsRedirectedResources: [], javascriptBlockedResources: [], fingerprintingBlockedResources: [] } }
tabs[tabId] = { ...tabs[tabId], ...{ adsBlockedResources: [], trackersBlockedResources: [], httpsRedirectedResources: [], fingerprintingBlockedResources: [] } }
return { ...state, tabs }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface Tab {
adsBlockedResources: Array<string>
trackersBlockedResources: Array<string>
httpsRedirectedResources: Array<string>
javascriptBlockedResources: Array<string>
fingerprintingBlockedResources: Array<string>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ describe('cosmeticFilterReducer', () => {
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
trackersBlockedResources: []
}
},
Expand Down Expand Up @@ -345,7 +344,6 @@ describe('cosmeticFilterReducer', () => {
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
trackersBlockedResources: []
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ describe('braveShieldsPanelReducer', () => {
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
trackersBlockedResources: []
}
},
Expand Down Expand Up @@ -347,7 +346,6 @@ describe('braveShieldsPanelReducer', () => {
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
trackersBlockedResources: []
}
},
Expand Down Expand Up @@ -494,7 +492,6 @@ describe('braveShieldsPanelReducer', () => {
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
trackersBlockedResources: []
}
},
Expand Down Expand Up @@ -550,8 +547,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [ 'https://test.brave.com/index.js' ]
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -595,8 +591,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [ 'https://a.com/index.js' ]
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -639,11 +634,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [
'https://a.com/index.js',
'https://b.com/index.js'
]
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -686,11 +677,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [
'https://a.com/index.js',
'https://b.com/index.js'
]
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -732,8 +719,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [],
fingerprintingBlockedResources: [ 'https://test.brave.com' ],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -775,8 +761,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -819,8 +804,7 @@ describe('braveShieldsPanelReducer', () => {
'https://test2.brave.com'
],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -908,8 +892,7 @@ describe('braveShieldsPanelReducer', () => {
'https://test.brave.com'
],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -950,8 +933,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
},
3: {
adsBlocked: 1,
Expand All @@ -963,8 +945,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -1005,7 +986,6 @@ describe('braveShieldsPanelReducer', () => {
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: [],
trackersBlockedResources: []
}
},
Expand Down Expand Up @@ -1047,8 +1027,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [ 'https://test.brave.com' ],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
javascriptBlockedResources: []
httpsRedirectedResources: []
}
},
windows: {
Expand Down Expand Up @@ -1088,8 +1067,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [ 'https://test.brave.com' ],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [ 'https://test.brave.com' ],
javascriptBlockedResources: []
httpsRedirectedResources: [ 'https://test.brave.com' ]
}
},
windows: {
Expand Down Expand Up @@ -1130,8 +1108,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [ 'https://test.brave.com' ],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [ 'https://test.brave.com' ],
javascriptBlockedResources: [ 'https://test.brave.com/index.js' ]
httpsRedirectedResources: [ 'https://test.brave.com' ]
}
},
windows: {
Expand Down Expand Up @@ -1172,8 +1149,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [ 'https://test.brave.com' ],
adsBlockedResources: [ 'https://test.brave.com' ],
fingerprintingBlockedResources: [ 'https://test.brave.com' ],
httpsRedirectedResources: [ 'https://test.brave.com' ],
javascriptBlockedResources: [ 'https://test.brave.com/index.js' ]
httpsRedirectedResources: [ 'https://test.brave.com' ]
}
},
windows: {
Expand Down
Loading

0 comments on commit 8f1c408

Please sign in to comment.