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

Commit

Permalink
add tests for browserAction.setIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jun 25, 2018
1 parent b1bbd81 commit e10e5b0
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 32 deletions.
28 changes: 0 additions & 28 deletions test/app/background/api/badgeAPITest.ts

This file was deleted.

86 changes: 86 additions & 0 deletions test/app/background/api/browserActionAPITest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* global describe, it, before, after */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import 'mocha'
import * as sinon from 'sinon'
import * as assert from 'assert'
import * as browserActionAPI from '../../../../app/background/api/browserActionAPI'

describe('BrowserAction API', () => {
describe('setBadgeText', function () {
before(function () {
this.spy = sinon.spy(chrome.browserAction, 'setBadgeText')
this.text = '42'
browserActionAPI.setBadgeText(this.text)
})
after(function () {
this.spy.restore()
})
it('calls chrome.browserAction.setBadgeText with the text', function () {
assert(this.spy.calledOnce)
assert.deepEqual(this.spy.getCall(0).args[0], {
text: this.text
})
})
})
describe('setIcon', function () {
const enabledIconPath = '../../img/icon-16.png'
const disabledIconPath = '../../img/icon-16-disabled.png'
before(function () {
this.spy = sinon.spy(chrome.browserAction, 'setIcon')
this.url = 'https://brave.com'
this.tabId = 1
this.shieldsEnabled = true
})
after(function () {
this.spy.restore()
})
afterEach(function () {
this.spy.reset()
})
it('sets the enabled icon when protocol is http', function () {
this.url = 'http://not-very-awesome-http-page.com'
browserActionAPI.setIcon(this.url, this.tabId, this.shieldsEnabled)
assert.deepEqual(this.spy.getCall(0).args[0], {
path: enabledIconPath,
tabId: this.tabId
})
})
it('sets the enabled icon when protocol is https', function () {
this.url = 'https://very-awesome-https-page.com'
browserActionAPI.setIcon(this.url, this.tabId, this.shieldsEnabled)
assert.deepEqual(this.spy.getCall(0).args[0], {
path: enabledIconPath,
tabId: this.tabId
})
})
it('sets the disabled icon when the protocol is neither https nor http', function () {
this.url = 'brave://welcome'
browserActionAPI.setIcon(this.url, this.tabId, this.shieldsEnabled)
assert.deepEqual(this.spy.getCall(0).args[0], {
path: disabledIconPath,
tabId: this.tabId
})
})
it('sets the disabled icon when the protocol is http and shield is off', function () {
this.url = 'http://not-very-awesome-http-page.com'
this.shieldsEnabled = false
browserActionAPI.setIcon(this.url, this.tabId, this.shieldsEnabled)
assert.deepEqual(this.spy.getCall(0).args[0], {
path: disabledIconPath,
tabId: this.tabId
})
})
it('sets the disabled icon when the protocol is https and shield is off', function () {
this.url = 'https://very-awesome-https-page.com'
this.shieldsEnabled = false
browserActionAPI.setIcon(this.url, this.tabId, this.shieldsEnabled)
assert.deepEqual(this.spy.getCall(0).args[0], {
path: disabledIconPath,
tabId: this.tabId
})
})
})
})
8 changes: 5 additions & 3 deletions test/app/background/reducers/shieldsPanelReducerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as webNavigationTypes from '../../../../app/constants/webNavigationType
import shieldsPanelReducer from '../../../../app/background/reducers/shieldsPanelReducer'
import * as shieldsAPI from '../../../../app/background/api/shieldsAPI'
import * as tabsAPI from '../../../../app/background/api/tabsAPI'
import * as badgeAPI from '../../../../app/background/api/badgeAPI'
import * as browserActionAPI from '../../../../app/background/api/browserActionAPI'
import * as shieldsPanelState from '../../../../app/state/shieldsPanelState'
import { initialState } from '../../../testData'
import * as deepFreeze from 'deep-freeze-node'
Expand Down Expand Up @@ -112,7 +112,9 @@ describe('braveShieldsPanelReducer', () => {
windows: {
1: this.tabId
},
tabs: {}
tabs: {
[this.tabId]: { url: 'https://brave.com' }
}
})
shieldsPanelReducer(state, {
type: windowTypes.WINDOW_FOCUS_CHANGED,
Expand Down Expand Up @@ -419,7 +421,7 @@ describe('braveShieldsPanelReducer', () => {

describe('RESOURCE_BLOCKED', function () {
before(function () {
this.spy = sinon.spy(badgeAPI, 'setBadgeText')
this.spy = sinon.spy(browserActionAPI, 'setBadgeText')
})
after(function () {
this.spy.restore()
Expand Down
3 changes: 2 additions & 1 deletion test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export const getMockChrome = () => {
onStartup: new ChromeEvent()
},
browserAction: {
setBadgeText: function (text: string) { }
setBadgeText: function (text: string) { },
setIcon: function (icon: string, tabId: number) { }
},
tabs: {
queryAsync: function () {
Expand Down

0 comments on commit e10e5b0

Please sign in to comment.