Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* karma, mocha, chai setup * basic setup works * line endings fixed * mock test removed * getAll works with mock store returning promise * eslint file tab indented to 2 spaces * all tests pass, code cleanup * tests added * misc changes * code cleanup * all tests cleared! * firefox addon added to travis.yml * capture.init moved back * eslint rules disabled * console stmt removed * travis trials * travis trials * travis trials * travis trials * travis trials * travis trials * travis trials * travis trials * travis trials
- Loading branch information
1 parent
412ac62
commit 9f8680c
Showing
9 changed files
with
201 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
addons: | ||
firefox: latest | ||
before_script: | ||
- export DISPLAY=:99.0 | ||
- sh -e /etc/init.d/xvfb start | ||
- sleep 3 | ||
language: node_js | ||
node_js: | ||
- '6.1' | ||
- '6.1' | ||
notifications: | ||
slack: | ||
secure: Y3VDGf3FSYXhgjvE9+RqIi+kMGpRuecp6r8rzFrhV11ktPzhb5aaFs0+qpBIL/Ptz99yTiM2kaRl/DTYqdcBzWD664tZR8g0OEsossvtu/U9ujlOPxz2QVsSbPI+JE21RwvQFq4wmK/2RUzyEjEp0SU9mxGngrBtkqMOHv7cSu5vy4NL8sTzcSTt4rZNAadzQHkhnrPu+dizLYD3a1MReRI2SuQ5qgVz0yuifKa26YXrjqmN+q1weycp8wQX1f0ITeZwCkhSERMOWRCjooGdbYsR6Oe0xQ+E7A1GxXCH5np43JHxKV+Te5YOnAzthiV1rdOnJdqx10+vHdU6NIZhZwER4wy0Tjsz/kiGwnvhWW641qS2NFPRC0aa8URDGBKzt2A9dOwiJYZ/f49dOe3q04cu3q8QH3cwkwHCNqO1f5T5iwldqU4pWRGyhwiiF6P5hVFWiyQ8b5ATG5rBIWFKq2uyD3xe5R4evw5Ay+3JwFG4Ddt2/C4KWv4OldbpT5pbT1WVOAkKKoXf4G/w0j3gDbWbxTqNJMP2L+jFmkYVEVrNd8Xcb/SR7I5398YicKEfJUiz8Y+p+nIvauJ6pdb/Ee6aBECOdhSDkcUwg8bPn7p4cS+wsoEIjz0SQGIe45wJ2Zy5nwMcgG8OPJy6EwuZ0s8eUW6Lbc44al3bOs/MS+k= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
'use strict'; | ||
|
||
// When the user clicks browserAction icon in toolbar, run Lightbeam | ||
browser.browserAction.onClicked.addListener(runLightbeam); | ||
|
||
capture.init(); | ||
|
||
async function runLightbeam() { | ||
// Checks to see if Lightbeam is already open. Returns true if it is, false if not. | ||
async function isOpen() { | ||
const tabs = await browser.tabs.query({}); | ||
const fullUrl = browser.extension.getURL('index.html'); | ||
const lightbeamTabs = tabs.filter((tab) => { | ||
return (tab.url === fullUrl); | ||
}); | ||
return lightbeamTabs[0] || false; | ||
} | ||
|
||
const lightbeamTab = await isOpen(); | ||
if (!lightbeamTab) { | ||
// only open a new Lightbeam instance if one isn't already open. | ||
browser.tabs.create({url: 'index.html'}); | ||
} else if (!lightbeamTab.active) { | ||
// re-focus Lightbeam if it is already open but lost focus | ||
browser.tabs.update(lightbeamTab.id, {active: true}); | ||
} | ||
} | ||
/* eslint no-undef: "off" */ | ||
'use strict'; | ||
|
||
// When the user clicks browserAction icon in toolbar, run Lightbeam | ||
browser.browserAction.onClicked.addListener(runLightbeam); | ||
|
||
capture.init(); | ||
|
||
async function runLightbeam() { | ||
// Checks to see if Lightbeam is already open. | ||
// Returns true if it is, false if not. | ||
async function isOpen() { | ||
const tabs = await browser.tabs.query({}); | ||
const fullUrl = browser.extension.getURL('index.html'); | ||
const lightbeamTabs = tabs.filter((tab) => { | ||
return (tab.url === fullUrl); | ||
}); | ||
return lightbeamTabs[0] || false; | ||
} | ||
|
||
const lightbeamTab = await isOpen(); | ||
if (!lightbeamTab) { | ||
// only open a new Lightbeam instance if one isn't already open. | ||
browser.tabs.create({url: 'index.html'}); | ||
} else if (!lightbeamTab.active) { | ||
// re-focus Lightbeam if it is already open but lost focus | ||
browser.tabs.update(lightbeamTab.id, {active: true}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint no-undef: "off" */ | ||
|
||
/* | ||
* @todo resolve 'module' is undefined and turn 'on' the eslint rule | ||
*/ | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
singleRun: true, | ||
browsers: ['Firefox'], | ||
frameworks: ['mocha', 'chai'], | ||
files: [ | ||
'test/unit/*.test.js' | ||
], | ||
plugins: [ | ||
'karma-chai', | ||
'karma-firefox-launcher', | ||
'karma-mocha' | ||
] | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint no-undef: "off" */ | ||
/* eslint no-console: "off" */ | ||
|
||
/* | ||
* @todo resolve 'expect' is undefined and turn 'on' the above eslint rules | ||
* @todo use eslint-plugin-chai to resolve 'expect' | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('store.js', () => { | ||
describe('store get method', () => { | ||
const mockStore = { | ||
_websites: { | ||
'a1.com': { | ||
faviconUrl: '/link/to/url', | ||
firstAccess: 1234, | ||
lastAccess: 5678, | ||
thirdPartyRequests: { | ||
'a.com': { | ||
requestTime: 9012, | ||
cookies: [] | ||
}, | ||
'b.com': {}, | ||
'c.com': {} | ||
} | ||
}, | ||
'a2.com': {} | ||
}, | ||
|
||
getAll() { | ||
return Promise.resolve(this._websites); | ||
}, | ||
|
||
getFirstParty(hostname) { | ||
if (!hostname) { | ||
throw new Error('getFirstParty requires a valid hostname argument'); | ||
} | ||
|
||
return Promise.resolve(this._websites[hostname]); | ||
}, | ||
|
||
getThirdParties(hostname) { | ||
if (!hostname) { | ||
throw new Error('getFirstParty requires a valid hostname argument'); | ||
} | ||
|
||
const firstParty = this._websites[hostname]; | ||
if ('thirdPartyRequests' in firstParty) { | ||
return Promise.resolve(firstParty.thirdPartyRequests); | ||
} | ||
|
||
return Promise.resolve(null); | ||
} | ||
}; | ||
|
||
it('should get all websites from store', async () => { | ||
const websites = await mockStore.getAll(); | ||
expect(websites).to.deep.equal(mockStore._websites); | ||
}); | ||
|
||
it('should get website object for a1.com', async () => { | ||
const website = await mockStore.getFirstParty('a1.com'); | ||
expect(website).to.deep.equal(mockStore._websites['a1.com']); | ||
}); | ||
|
||
it('error thrown when hostname is not passed for getFirstParty()', | ||
async () => { | ||
try { | ||
await mockStore.getFirstParty(); | ||
} catch (err) { | ||
console.log('error from getFirstParty', err); | ||
} | ||
}); | ||
|
||
it('should get thirdPartyRequests for a1.com', async () => { | ||
const thirdParties = await mockStore.getThirdParties('a1.com'); | ||
const mockThirdParties = mockStore._websites['a1.com'].thirdPartyRequests; | ||
expect(thirdParties).to.deep.equal(mockThirdParties); | ||
}); | ||
|
||
it('error thrown when hostname is not passed for getThirdParties()', | ||
async () => { | ||
try { | ||
await mockStore.getThirdParties(); | ||
} catch (err) { | ||
console.log('error from getThirdParties', err); | ||
} | ||
}); | ||
|
||
it('should return null for getThirdParties()', async () => { | ||
const thirdPartyRequests = await mockStore.getThirdParties('a2.com'); | ||
expect(thirdPartyRequests).to.equal(null); | ||
}); | ||
}); | ||
}); |