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

Commit

Permalink
Fix unit test by native module mock
Browse files Browse the repository at this point in the history
Auditors: @NejcZdovc
  • Loading branch information
bbondy committed Apr 25, 2017
1 parent 753feda commit ad18376
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/unit/app/browser/ads/adBlockUtilTest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* global describe, it */
/* global before, describe, it */

require('../../../braveUnit')
const assert = require('assert')
const {URL} = require('url')
const fakeAdBlock = require('../../../lib/fakeAdBlock')
const mockery = require('mockery')

const site = new URL('https://www.brave.com')
const thirdPartyResource = new URL('https://www.coffee.com/logo.png')
const firstPartyResource = new URL('https://www.brave.com/logo.png')
const {shouldDoAdBlockCheck} = require('../../../../../app/browser/ads/adBlockUtil')

describe('adBlockUtil test', function () {
let shouldDoAdBlockCheck
before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('ad-block', fakeAdBlock)
shouldDoAdBlockCheck = require('../../../../../app/browser/ads/adBlockUtil').shouldDoAdBlockCheck
})
describe('shouldDoAdBlockCheck', function () {
it('http protocol allows ad block checks', function () {
assert.ok(shouldDoAdBlockCheck('script', new URL('https://www.brave.com'), thirdPartyResource, false))
Expand Down
1 change: 1 addition & 0 deletions test/unit/app/browser/reducers/tabsReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('tabsReducer', function () {
}]
})
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('leveldown', {})
mockery.registerMock('./webContentsCache', {
getWebContents: (tabId) => ({
canGoBack: () => true,
Expand Down
24 changes: 24 additions & 0 deletions test/unit/lib/fakeAdBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fakeAdBlock = {
FilterOptions: {
noFilterOption: 0,
script: 0o1,
image: 0o2,
stylesheet: 0o4,
object: 0o10,
xmlHttpRequest: 0o20,
objectSubrequest: 0o40,
subdocument: 0o100,
document: 0o200,
other: 0o400,
xbl: 0o1000,
collapse: 0o2000,
doNotTrack: 0o4000,
elemHide: 0o10000,
thirdParty: 0o20000,
notThirdParty: 0o40000
},
AdBlockClient: function () {
}
}

module.exports = fakeAdBlock

2 comments on commit ad18376

@bsclifton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!! 😄 ++

@NejcZdovc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.