-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'webextensions-add-unit-tests' into 'master'
Add unit tests for WebExtensions add-ons See merge request clear-code/browserselector!72
- Loading branch information
Showing
11 changed files
with
184 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
((js-mode . ((indent-tabs-mode . nil) | ||
(js-indent-level . 2) | ||
(js-switch-indent-offset . 2)))) |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ ipch/ | |
*_i.[ch] | ||
*_p.[ch] | ||
*.zip | ||
webextensions/testee |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
tools/ | ||
*/dev/ | ||
*/enterprise-dev/ | ||
testee/ | ||
test/ |
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
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,50 @@ | ||
global.chrome = { | ||
alarms: { | ||
create: function() { | ||
}, | ||
onAlarm: { | ||
addListener: function() { | ||
} | ||
}, | ||
}, | ||
runtime: { | ||
sendNativeMessage: function() { | ||
}, | ||
}, | ||
tabs: { | ||
onCreated: { | ||
addListener: function() { | ||
} | ||
}, | ||
onRemoved: { | ||
addListener: function() { | ||
} | ||
}, | ||
onUpdated: { | ||
addListener: function() { | ||
} | ||
}, | ||
}, | ||
windows: { | ||
onCreated: { | ||
addListener: function() { | ||
} | ||
}, | ||
onRemoved: { | ||
addListener: function() { | ||
} | ||
}, | ||
}, | ||
webRequest: { | ||
onBeforeRequest: { | ||
addListener: function() { | ||
}, | ||
}, | ||
}, | ||
webNavigation: { | ||
onCommitted: { | ||
addListener: function() { | ||
} | ||
}, | ||
}, | ||
}; |
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,33 @@ | ||
const assert = require('assert'); | ||
const chromestub = require('./chrome-stub.js'); | ||
|
||
describe('getHost', () => { | ||
const redirectors = [ | ||
{ browser: 'chrome', module: require('../testee/chrome.js') }, | ||
{ browser: 'edge', module: require('../testee/edge.js') }, | ||
].forEach(({browser, module}) => { | ||
describe(browser, () => { | ||
const redirector = module.redirector; | ||
it('http: extract host name', () => { | ||
const url = 'http://www.google.com/'; | ||
assert.equal(redirector._getHost(url), 'www.google.com'); | ||
}); | ||
it('https: extract host name', () => { | ||
const url = 'https://www.google.com/'; | ||
assert.equal(redirector._getHost(url), 'www.google.com'); | ||
}); | ||
it('exclude account', () => { | ||
const url = 'https://foobar:[email protected]/'; | ||
assert.equal(redirector._getHost(url), 'www.google.com'); | ||
}); | ||
// TODO: | ||
// Although C++ implementation intends to exclude port number, JavaScript | ||
// one includes it. So that this test always fails with current code. | ||
// We may need to fix it. | ||
it('exclude port number' /*, () => { | ||
const url = 'https://www.google.com:8080/'; | ||
assert.equal(redirector._getHost(url), 'www.google.com'); | ||
}*/); | ||
}); | ||
}); | ||
}); |
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,65 @@ | ||
const assert = require('assert'); | ||
const chromestub = require('./chrome-stub.js'); | ||
|
||
describe('isRedirectURL', () => { | ||
const redirectors = [ | ||
{ browser: 'chrome', module: require('../testee/chrome.js') }, | ||
{ browser: 'edge', module: require('../testee/edge.js') }, | ||
].forEach(({browser, module}) => { | ||
const redirector = module.redirector; | ||
describe(browser, () => { | ||
const baseConfig = { | ||
DefaultBrowser: browser, | ||
SecondBrowser: "", | ||
FirefoxCommannd: "", | ||
CloseEmptyTab: 1, | ||
OnlyOnAnchorClick: 0, | ||
UseRegex: 0, | ||
URLPatterns: [], | ||
HostNamePatterns: [], | ||
ZonePatterns: [], | ||
} | ||
function config(URLPatterns = [], HostNamePatterns = [], additionals = {}) { | ||
const config = {...baseConfig, ...additionals}; | ||
config.URLPatterns = [...config.URLPatterns, ...URLPatterns]; | ||
config.HostNamePatterns = [...config.HostNamePatterns, ...HostNamePatterns]; | ||
return config; | ||
} | ||
describe('Empty redirect pattern', () => { | ||
it(`Should not redirect when default browser is ${browser}`, () => { | ||
const url = 'http://www.google.com/'; | ||
assert.equal(redirector.isRedirectURL(baseConfig, url), false); | ||
}); | ||
it(`Should redirect when default browser is not ${browser}`, () => { | ||
const defaultBrowser = browser === 'edge' ? 'chrome' : 'edge'; | ||
const url = 'http://www.google.com/'; | ||
assert.equal(redirector.isRedirectURL(config([], [], {DefaultBrowser: defaultBrowser}), url), true); | ||
}); | ||
}); | ||
describe('URL patterns', () => { | ||
it(`Match redirect pattern`, () => { | ||
const url = 'http://www.example.com/'; | ||
const conf = config([['http*://*.example.com/*', 'firefox']]) | ||
assert.equal(redirector.isRedirectURL(conf, url), true); | ||
}); | ||
it(`Unmatch redirect pattern`, () => { | ||
const url = 'http://www.google.com/'; | ||
const conf = config([['http*://*.example.com/*', 'firefox']]) | ||
assert.equal(redirector.isRedirectURL(conf, url), false); | ||
}); | ||
}); | ||
describe('HostName patterns', () => { | ||
it(`Match redirect pattern`, () => { | ||
const url = 'http://www.example.com/'; | ||
const conf = config([], [['*.example.com', 'firefox']]) | ||
assert.equal(redirector.isRedirectURL(conf, url), true); | ||
}); | ||
it(`Unmatch redirect pattern`, () => { | ||
const url = 'http://www.google.com/'; | ||
const conf = config([], [['*.example.com', 'firefox']]) | ||
assert.equal(redirector.isRedirectURL(conf, url), false); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |