Container locking - fixed broken tests due to rebasing against master

This commit is contained in:
Francis McKenzie 2020-01-15 18:21:15 +01:00
parent 6f55671f8f
commit 42a9a6e766
4 changed files with 30 additions and 16 deletions

View file

@ -26,7 +26,7 @@
"stylelint-config-standard": "^16.0.0", "stylelint-config-standard": "^16.0.0",
"stylelint-order": "^0.3.0", "stylelint-order": "^0.3.0",
"web-ext": "^2.9.3", "web-ext": "^2.9.3",
"webextensions-jsdom": "^1.1.0" "webextensions-jsdom": "^1.1.1"
}, },
"homepage": "https://github.com/mozilla/multi-account-containers#readme", "homepage": "https://github.com/mozilla/multi-account-containers#readme",
"license": "MPL-2.0", "license": "MPL-2.0",

View file

@ -1,14 +1,14 @@
// https://github.com/mozilla/multi-account-containers/issues/847 // https://github.com/mozilla/multi-account-containers/issues/847
describe("Lock Feature", () => { describe("Lock Feature", () => {
const activeTab = { const url1 = "http://example.com";
id: 1, const url2 = "http://example2.com";
cookieStoreId: "firefox-container-1",
url: "http://example.com", let activeTab;
index: 0,
active: true
};
beforeEach(async () => { beforeEach(async () => {
await helper.browser.initializeWithTab(activeTab); activeTab = await helper.browser.initializeWithTab({
cookieStoreId: "firefox-container-1",
url: url1
});
}); });
describe("click the 'Always open in' checkbox in the popup", () => { describe("click the 'Always open in' checkbox in the popup", () => {
@ -18,9 +18,8 @@ describe("Lock Feature", () => {
}); });
describe("open different URL in same tab", () => { describe("open different URL in same tab", () => {
const differentURL = "http://example2.com";
beforeEach(async () => { beforeEach(async () => {
await helper.browser.browseToURL(activeTab.id, differentURL); await helper.browser.browseToURL(activeTab.id, url2);
}); });
it("should not open a new tab", () => { it("should not open a new tab", () => {
@ -32,20 +31,31 @@ describe("Lock Feature", () => {
await helper.popup.setContainerIsLocked(activeTab.cookieStoreId, true); await helper.popup.setContainerIsLocked(activeTab.cookieStoreId, true);
}); });
describe("open different URL in same tab", () => { describe("wait 2 seconds, then open different URL in same tab", () => {
beforeEach(async () => { beforeEach(async () => {
await helper.browser.browseToURL(activeTab.id, differentURL); // Note: must wait 2 seconds, because of code in messageHandler that assumes
// a newly-created tab is not 'genuine' until 2 seconds have elapsed since
// its creation.
// Unfortunately, this test runner recreates the tab at every single 'beforeEach',
// so messageHandler thinks the tab is not genuine and tries to remove it,
// meaning the below tests will (incorrectly) fail.
await global.sleep(2500);
await helper.browser.browseToURL(activeTab.id, url2);
}); });
it("should open a new tab in the default container", () => { it("should open a new tab in the default container", () => {
background.browser.tabs.create.should.have.been.calledWith(sinon.match({ background.browser.tabs.create.should.have.been.calledWith(sinon.match({
url: differentURL, url: url2,
cookieStoreId: "firefox-default", cookieStoreId: "firefox-default",
openerTabId: activeTab.id, openerTabId: activeTab.id,
index: activeTab.index + 1, index: activeTab.index + 1,
active: activeTab.active active: activeTab.active
})); }));
}); });
it("should not remove the original tab", () => {
background.browser.tabs.remove.should.not.have.been.called;
});
}); });
}); });
}); });

View file

@ -11,6 +11,8 @@ module.exports = {
} }
}, },
popup: { popup: {
// Required to access variables, because nyc messes up 'eval'
script: "function evalScript(v) { return eval(v); }",
jsdom: { jsdom: {
beforeParse(window) { beforeParse(window) {
window.browser.storage.local.set({ window.browser.storage.local.set({
@ -31,7 +33,6 @@ module.exports = {
return background.browser.tabs._create(tab, options); return background.browser.tabs._create(tab, options);
}, },
// https://github.com/mozilla/multi-account-containers/issues/847
async browseToURL(tabId, url) { async browseToURL(tabId, url) {
const [promise] = background.browser.webRequest.onBeforeRequest.addListener.yield({ const [promise] = background.browser.webRequest.onBeforeRequest.addListener.yield({
frameId: 0, frameId: 0,
@ -53,7 +54,7 @@ module.exports = {
// https://github.com/mozilla/multi-account-containers/issues/847 // https://github.com/mozilla/multi-account-containers/issues/847
async setContainerIsLocked(cookieStoreId, isLocked) { async setContainerIsLocked(cookieStoreId, isLocked) {
const Logic = popup.dom.window.eval("Logic"); const Logic = popup.window.evalScript("Logic");
const userContextId = Logic.userContextId(cookieStoreId); const userContextId = Logic.userContextId(cookieStoreId);
await Logic.lockOrUnlockContainer(userContextId, isLocked); await Logic.lockOrUnlockContainer(userContextId, isLocked);
} }

View file

@ -16,6 +16,9 @@ global.nextTick = () => {
}); });
}); });
}; };
global.sleep = (delay) => {
return new Promise((resolve) => { setTimeout(resolve, delay); });
};
global.helper = require("./helper"); global.helper = require("./helper");