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

Commit

Permalink
tests for allow script once
Browse files Browse the repository at this point in the history
  • Loading branch information
yrliou committed May 4, 2018
1 parent 882c3ce commit 1212f6f
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 47 deletions.
11 changes: 10 additions & 1 deletion test/app/actions/shieldsPanelActionsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ describe('shieldsPanelActions', () => {
it('resourceBlocked action', () => {
const details: BlockDetails = {
blockType: 'ads',
tabId: 2
tabId: 2,
subresource: 'https://www.brave.com/test'
}
assert.deepEqual(actions.resourceBlocked(details), {
type: types.RESOURCE_BLOCKED,
Expand Down Expand Up @@ -91,4 +92,12 @@ describe('shieldsPanelActions', () => {
setting
})
})

it('allowScriptOriginsOnce action', () => {
const origins = ['https://a.com', 'https://b.com']
assert.deepEqual(actions.allowScriptOriginsOnce(origins), {
type: types.ALLOW_SCRIPT_ORIGINS_ONCE,
origins
})
})
})
29 changes: 29 additions & 0 deletions test/app/background/api/shieldsAPITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,33 @@ describe('Shields API', () => {
assert.equal(shieldsAPI.toggleShieldsValue('block'), 'allow')
})
})

describe('setAllowScriptOriginsOnce', function() {
before(function () {
this.spy = sinon.spy(chrome.braveShields, 'allowScriptsOnce')
this.p = shieldsAPI.setAllowScriptOriginsOnce(
['https://a.com/', 'https://b.com/'], 2)
})
after(function () {
this.spy.restore()
})
it('calls chrome.braveShields.allowScriptsOnce with the correct args', function () {
const arg0 = this.spy.getCall(0).args[0]
assert.deepEqual(arg0, ['https://a.com/', 'https://b.com/'])
const arg1 = this.spy.getCall(0).args[1]
assert.deepEqual(arg1, 2)
})
it('passes 3 args to chrome.braveShields.allowScriptsOnce', function () {
assert.equal(this.spy.getCall(0).args.length, 3) // include callback
})
it('resolves the returned promise', function (cb) {
this.p
.then(function() {
cb()
})
.catch((e: Error) => {
console.error(e.toString())
})
})
})
})
Loading

0 comments on commit 1212f6f

Please sign in to comment.