Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
add shieldsPanelReducer test for duplicated blocked resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jul 2, 2018
1 parent 1ecc712 commit 7bfc047
Showing 1 changed file with 99 additions and 4 deletions.
103 changes: 99 additions & 4 deletions test/app/background/reducers/shieldsPanelReducerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,7 @@ describe('braveShieldsPanelReducer', () => {
httpsRedirectedResources: [],
javascriptBlockedResources: [
'https://a.com/index.js',
'https://b.com/index.js',
'https://a.com/index.js'
'https://b.com/index.js'
]
}
},
Expand All @@ -657,6 +656,54 @@ describe('braveShieldsPanelReducer', () => {
})
})

it('increments JS blocking consecutively without duplicates', function () {
this.tabId = 2
let nextState = shieldsPanelReducer(state, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'javascript',
tabId: this.tabId,
subresource: 'https://a.com/index.js'
}
})
assert.deepEqual(
nextState.tabs[this.tabId].javascriptBlockedResources,
[ 'https://a.com/index.js' ]
)

nextState = shieldsPanelReducer(nextState, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'javascript',
tabId: this.tabId,
subresource: 'https://b.com/index.js'
}
})
assert.deepEqual(
nextState.tabs[this.tabId].javascriptBlockedResources,
[
'https://a.com/index.js',
'https://b.com/index.js'
]
)

nextState = shieldsPanelReducer(nextState, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'javascript',
tabId: this.tabId,
subresource: 'https://b.com/index.js'
}
})
assert.deepEqual(
nextState.tabs[this.tabId].javascriptBlockedResources,
[
'https://a.com/index.js',
'https://b.com/index.js'
]
)
})

it('increments for fingerprinting blocked', function () {
let nextState = shieldsPanelReducer(state, {
type: types.RESOURCE_BLOCKED,
Expand Down Expand Up @@ -747,7 +794,7 @@ describe('braveShieldsPanelReducer', () => {
details: {
blockType: 'ads',
tabId: 2,
subresource: 'https://test.brave.com'
subresource: 'https://test2.brave.com'
}
})
assert.deepEqual(nextState, {
Expand All @@ -774,7 +821,7 @@ describe('braveShieldsPanelReducer', () => {
trackersBlockedResources: [],
adsBlockedResources: [
'https://test.brave.com',
'https://test.brave.com'
'https://test2.brave.com'
],
fingerprintingBlockedResources: [],
httpsRedirectedResources: [],
Expand All @@ -786,6 +833,54 @@ describe('braveShieldsPanelReducer', () => {
}
})
})
it('increases same count consecutively without duplicates', function () {
this.tabId = 2
let nextState = shieldsPanelReducer(state, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'ads',
tabId: this.tabId,
subresource: 'https://test.brave.com'
}
})
assert.deepEqual(
nextState.tabs[this.tabId].adsBlockedResources,
[ 'https://test.brave.com' ]
)

nextState = shieldsPanelReducer(nextState, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'ads',
tabId: this.tabId,
subresource: 'https://test2.brave.com'
}
})
assert.deepEqual(
nextState.tabs[this.tabId].adsBlockedResources,
[
'https://test.brave.com',
'https://test2.brave.com'
]
)

nextState = shieldsPanelReducer(nextState, {
type: types.RESOURCE_BLOCKED,
details: {
blockType: 'ads',
tabId: this.tabId,
subresource: 'https://test2.brave.com'
}
})
assert.deepEqual(
nextState.tabs[this.tabId].adsBlockedResources,
[
'https://test.brave.com',
'https://test2.brave.com'
]
)
})

it('increases different tab counts separately', function () {
let nextState = deepFreeze(shieldsPanelReducer(state, {
type: types.RESOURCE_BLOCKED,
Expand Down

0 comments on commit 7bfc047

Please sign in to comment.