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

Commit

Permalink
Added unit test for new shouldSkipCookie method
Browse files Browse the repository at this point in the history
Auditors: @darkdh

Test Plan:
`npm run unittest -- --grep="importer unit tests"`
  • Loading branch information
bsclifton committed Oct 10, 2017
1 parent bff78c9 commit 8583ccb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const shouldSkipCookie = (cookie) => {
}
return false
}
module.exports.shouldSkipCookie = shouldSkipCookie

importer.on('add-cookies', (e, cookies) => {
for (let i = 0; i < cookies.length; ++i) {
Expand Down
35 changes: 35 additions & 0 deletions test/unit/app/importerTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* global describe, before, after, it */
const mockery = require('mockery')
const assert = require('assert')

require('../braveUnit')

describe('importer unit tests', function () {
let importer
const fakeElectron = require('../lib/fakeElectron')

before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('./adBlock', {adBlockResourceName: 'adblock'})
importer = require('../../../app/importer')
})

after(function () {
mockery.disable()
})

describe('shouldSkipCookie', function () {
it('returns true if domain is google and URL is one which has a mismatch', function () {
assert.equal(importer.shouldSkipCookie({domain: '.google.com', url: 'https://notifications.google.com'}), true)
})

it('returns false for other cases', function () {
assert.equal(importer.shouldSkipCookie({domain: '.brave.com', url: 'https://brave.com'}), false)
})
})
})
5 changes: 4 additions & 1 deletion test/unit/lib/fakeElectron.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ const fakeElectron = {
extensions: {
createTab: function () {}
},
autoUpdater: new EventEmitter()
autoUpdater: new EventEmitter(),
importer: {
on: () => {}
}
}

module.exports = fakeElectron

1 comment on commit 8583ccb

@darkdh
Copy link
Member

@darkdh darkdh commented on 8583ccb Oct 11, 2017

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.