From 4920f478fb8f669b984ff4a076536bf923247d84 Mon Sep 17 00:00:00 2001 From: Kendall Werts Date: Tue, 25 Feb 2020 11:10:15 -0600 Subject: [PATCH] updates to make tests work --- test/features/assignment.test.js | 123 ++++++++++++------- test/features/containers.test.js | 2 +- test/features/external-webextensions.test.js | 9 +- test/issues/940.test.js | 11 +- 4 files changed, 93 insertions(+), 52 deletions(-) diff --git a/test/features/assignment.test.js b/test/features/assignment.test.js index da31a77..2ab858b 100644 --- a/test/features/assignment.test.js +++ b/test/features/assignment.test.js @@ -1,11 +1,11 @@ const {initializeWithTab} = require("../common"); -describe("Assignment Feature", function () { +describe("Assignment Reopen Feature", function () { const url = "http://example.com"; beforeEach(async function () { this.webExt = await initializeWithTab({ - cookieStoreId: "firefox-container-2", + cookieStoreId: "firefox-default", url }); }); @@ -18,63 +18,100 @@ describe("Assignment Feature", function () { beforeEach(async function () { // popup click to set assignment for activeTab.url await this.webExt.popup.helper.clickElementById("always-open-in"); - console.log("done"); - await this.webExt.popup.helper.clickElementByQuerySelectorAll(".menu-item"); - //await this.webExt.popup.helper.clickElementById("container-page-assigned"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll("#picker-identities-list > .menu-item"); }); - describe("open new Tab with the assigned URL in the default container", function () { - let newTab; - beforeEach(async function () { - let tabs = await this.webExt.background.browser.tabs.query({}); - console.log("tabs", tabs); - // 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 - } - }); - 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); + it("should open the page in the assigned container", async function () { + // should have created a new tab with the confirm page + this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({ + active: true, + cookieStoreId: "firefox-container-4", + index: 1, + openerTabId: null, + url: "http://example.com" }); }); - 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 () { - // popup click to remove assignment for activeTab.url - await this.webExt.popup.helper.clickElementById("container-page-assigned"); + // click confirm page to always open in container + 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 () { - // new Tab opening activeTab.url in default container + // new Tab trying to open url in default container await this.webExt.background.browser.tabs._create({ cookieStoreId: "firefox-default", url }); + const tabs = await this.webExt.background.browser.tabs.query({}); + console.log("tabs", tabs); }); it("should not open the confirm page", async function () { - // should not have created a new tab - this.webExt.background.browser.tabs.create.should.not.have.been.called; + // should have created a new tab with the assigned url + this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({ + url, + cookieStoreId: "firefox-container-4", + openerTabId: null, + index: 3, + active: true + }); }); }); }); diff --git a/test/features/containers.test.js b/test/features/containers.test.js index 36624ab..8d18c39 100644 --- a/test/features/containers.test.js +++ b/test/features/containers.test.js @@ -23,7 +23,7 @@ describe("Containers Management", function () { describe("removing it afterwards", function () { beforeEach(async function () { 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-ok-link"); }); diff --git a/test/features/external-webextensions.test.js b/test/features/external-webextensions.test.js index 63038d9..f47fe6a 100644 --- a/test/features/external-webextensions.test.js +++ b/test/features/external-webextensions.test.js @@ -5,11 +5,12 @@ describe("External Webextensions", function () { beforeEach(async function () { this.webExt = await initializeWithTab({ - cookieStoreId: "firefox-container-1", + cookieStoreId: "firefox-container-4", 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 () { @@ -17,7 +18,7 @@ describe("External Webextensions", 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({ permissions: ["contextualIdentities"] }); @@ -32,7 +33,7 @@ describe("External Webextensions", function () { const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender); 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( Object.prototype.hasOwnProperty.call( diff --git a/test/issues/940.test.js b/test/issues/940.test.js index bbe4a64..fce13d5 100644 --- a/test/issues/940.test.js +++ b/test/issues/940.test.js @@ -4,11 +4,12 @@ describe("#940", function () { describe("when other onBeforeRequestHandlers are faster and redirect with the same requestId", function () { it("should not open two confirm pages", async function () { const webExtension = await initializeWithTab({ - cookieStoreId: "firefox-container-1", + cookieStoreId: "firefox-container-4", 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 = {}; await webExtension.background.browser.tabs._create({ @@ -36,10 +37,12 @@ describe("#940", function () { beforeEach(async function () { this.webExt = await initializeWithTab({ - cookieStoreId: "firefox-container-1", + cookieStoreId: "firefox-container-4", 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(); this.redirectedRequest = async (options = {}) => {