updates to make tests work

This commit is contained in:
Kendall Werts 2020-02-25 11:10:15 -06:00
parent a66cdbf0bd
commit 4920f478fb
4 changed files with 93 additions and 52 deletions

View file

@ -1,11 +1,11 @@
const {initializeWithTab} = require("../common"); const {initializeWithTab} = require("../common");
describe("Assignment Feature", function () { describe("Assignment Reopen Feature", function () {
const url = "http://example.com"; const url = "http://example.com";
beforeEach(async function () { beforeEach(async function () {
this.webExt = await initializeWithTab({ this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-2", cookieStoreId: "firefox-default",
url url
}); });
}); });
@ -18,63 +18,100 @@ describe("Assignment Feature", function () {
beforeEach(async function () { beforeEach(async function () {
// popup click to set assignment for activeTab.url // popup click to set assignment for activeTab.url
await this.webExt.popup.helper.clickElementById("always-open-in"); await this.webExt.popup.helper.clickElementById("always-open-in");
console.log("done"); await this.webExt.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item");
await this.webExt.popup.helper.clickElementByQuerySelectorAll(".menu-item");
//await this.webExt.popup.helper.clickElementById("container-page-assigned");
}); });
describe("open new Tab with the assigned URL in the default container", function () { it("should open the page in the assigned container", async function () {
let newTab; // should have created a new tab with the confirm page
beforeEach(async function () { this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({
let tabs = await this.webExt.background.browser.tabs.query({}); active: true,
console.log("tabs", tabs); cookieStoreId: "firefox-container-4",
// new Tab opening activeTab.url in default container index: 1,
newTab = await this.webExt.background.browser.tabs._create({ openerTabId: null,
cookieStoreId: "firefox-default", url: "http://example.com"
url
}, {
options: {
webRequestError: true // because request is canceled due to reopening
}
});
tabs = await this.webExt.background.browser.tabs.query({});
console.log("tabs", tabs)
});
it("should open the confirm page", async function () {
// should have created a new tab with the confirm page
this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({
url: "http://example.com",
cookieStoreId: undefined,
openerTabId: null,
index: 2,
active: true
});
});
it("should remove the new Tab that got opened in the default container", function () {
this.webExt.background.browser.tabs.remove.should.have.been.calledWith(newTab.id);
}); });
}); });
describe("click the 'Always open in' checkbox in the popup again", function () { });
});
describe("Assignment Comfirm Page Feature", function () {
const url = "http://example.com";
beforeEach(async function () {
this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-4",
url
});
});
afterEach(function () {
this.webExt.destroy();
});
describe("open new Tab with the assigned URL in the default container", function () {
let newTab;
beforeEach(async function () {
await this.webExt.popup.helper.clickElementById("always-open-in");
await this.webExt.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item");
// new Tab opening activeTab.url in default container
newTab = await this.webExt.background.browser.tabs._create({
cookieStoreId: "firefox-default",
url
}, {
options: {
webRequestError: true // because request is canceled due to reopening
}
});
});
it("should open the confirm page", async function () {
// should have created a new tab with the confirm page
this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({
url: "moz-extension://fake/confirm-page.html?" +
`url=${encodeURIComponent(url)}` +
`&cookieStoreId=${this.webExt.tab.cookieStoreId}`,
cookieStoreId: undefined,
openerTabId: null,
index: 2,
active: true
});
});
it("should remove the new Tab that got opened in the default container", function () {
this.webExt.background.browser.tabs.remove.should.have.been.calledWith(newTab.id);
});
describe("Set assignment to 'never ask' ", function () {
beforeEach(async function () { beforeEach(async function () {
// popup click to remove assignment for activeTab.url // click confirm page to always open in container
await this.webExt.popup.helper.clickElementById("container-page-assigned"); await this.webExt.document.getElementById("never-ask").click();
await this.webExt.document.getElementById("confirm").click();
}); });
describe("open new Tab with the no longer assigned URL in the default container", function () { describe("open new Tab with url set to 'never ask' ", function () {
beforeEach(async function () { beforeEach(async function () {
// new Tab opening activeTab.url in default container // new Tab trying to open url in default container
await this.webExt.background.browser.tabs._create({ await this.webExt.background.browser.tabs._create({
cookieStoreId: "firefox-default", cookieStoreId: "firefox-default",
url url
}); });
const tabs = await this.webExt.background.browser.tabs.query({});
console.log("tabs", tabs);
}); });
it("should not open the confirm page", async function () { it("should not open the confirm page", async function () {
// should not have created a new tab // should have created a new tab with the assigned url
this.webExt.background.browser.tabs.create.should.not.have.been.called; this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({
url,
cookieStoreId: "firefox-container-4",
openerTabId: null,
index: 3,
active: true
});
}); });
}); });
}); });

View file

@ -23,7 +23,7 @@ describe("Containers Management", function () {
describe("removing it afterwards", function () { describe("removing it afterwards", function () {
beforeEach(async function () { beforeEach(async function () {
await this.webExt.popup.helper.clickElementById("manage-containers-link"); await this.webExt.popup.helper.clickElementById("manage-containers-link");
await this.webExt.popup.helper.clickElementByQuerySelectorAll(".menu-item", "last"); await this.webExt.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item", "last");
await this.webExt.popup.helper.clickElementById("delete-container-button"); await this.webExt.popup.helper.clickElementById("delete-container-button");
await this.webExt.popup.helper.clickElementById("delete-container-ok-link"); await this.webExt.popup.helper.clickElementById("delete-container-ok-link");
}); });

View file

@ -5,11 +5,12 @@ describe("External Webextensions", function () {
beforeEach(async function () { beforeEach(async function () {
this.webExt = await initializeWithTab({ this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1", cookieStoreId: "firefox-container-4",
url url
}); });
await this.webExt.popup.helper.clickElementById("container-page-assigned"); await this.webExt.popup.helper.clickElementById("always-open-in");
await this.webExt.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item", "last");
}); });
afterEach(function () { afterEach(function () {
@ -17,7 +18,7 @@ describe("External Webextensions", function () {
}); });
describe("with contextualIdentities permissions", function () { describe("with contextualIdentities permissions", function () {
it.only("should be able to get assignments", async function () { it("should be able to get assignments", async function () {
this.webExt.background.browser.management.get.resolves({ this.webExt.background.browser.management.get.resolves({
permissions: ["contextualIdentities"] permissions: ["contextualIdentities"]
}); });
@ -32,7 +33,7 @@ describe("External Webextensions", function () {
const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender); const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
const answer = await promise; const answer = await promise;
expect(answer.userContextId === "1").to.be.true; expect(answer.userContextId === "4").to.be.true;
expect(answer.neverAsk === false).to.be.true; expect(answer.neverAsk === false).to.be.true;
expect( expect(
Object.prototype.hasOwnProperty.call( Object.prototype.hasOwnProperty.call(

View file

@ -4,11 +4,12 @@ describe("#940", function () {
describe("when other onBeforeRequestHandlers are faster and redirect with the same requestId", function () { describe("when other onBeforeRequestHandlers are faster and redirect with the same requestId", function () {
it("should not open two confirm pages", async function () { it("should not open two confirm pages", async function () {
const webExtension = await initializeWithTab({ const webExtension = await initializeWithTab({
cookieStoreId: "firefox-container-1", cookieStoreId: "firefox-container-4",
url: "http://example.com" url: "http://example.com"
}); });
await webExtension.popup.helper.clickElementById("container-page-assigned"); await webExtension.popup.helper.clickElementById("always-open-in");
await webExtension.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item");
const responses = {}; const responses = {};
await webExtension.background.browser.tabs._create({ await webExtension.background.browser.tabs._create({
@ -36,10 +37,12 @@ describe("#940", function () {
beforeEach(async function () { beforeEach(async function () {
this.webExt = await initializeWithTab({ this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1", cookieStoreId: "firefox-container-4",
url: "https://www.youtube.com" url: "https://www.youtube.com"
}); });
await this.webExt.popup.helper.clickElementById("container-page-assigned");
await this.webExt.popup.helper.clickElementById("always-open-in");
await this.webExt.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item");
global.clock = sinon.useFakeTimers(); global.clock = sinon.useFakeTimers();
this.redirectedRequest = async (options = {}) => { this.redirectedRequest = async (options = {}) => {