From a3f3413a01586e2d3af4faa43d14654168aaff45 Mon Sep 17 00:00:00 2001 From: Sherry Ma Date: Mon, 9 Mar 2020 17:18:14 -0400 Subject: [PATCH] added test cases for manually assigning URL --- src/js/popup.js | 4 +- test/issues/1670.test.js | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 test/issues/1670.test.js diff --git a/src/js/popup.js b/src/js/popup.js index b238864..356d71a 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1875,7 +1875,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { const tabId = currentTab.id; const fullURL = this.checkUrl(url); - if (fullURL !== "") { + if (fullURL !== null) { // Assign URL to container await Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false); @@ -1897,7 +1897,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { let newURL = url; if (!url.match(validUrl)) { - return ""; + return null; } if (!url.match(regexhttp) && !url.match(regexhttps)) { diff --git a/test/issues/1670.test.js b/test/issues/1670.test.js new file mode 100644 index 0000000..fe8ae84 --- /dev/null +++ b/test/issues/1670.test.js @@ -0,0 +1,81 @@ +// const expect = require("chai").expect; +const {initializeWithTab} = require("../common"); + +describe("#1670", function () { + beforeEach(async function () { + this.webExt = await initializeWithTab(); + }); + + afterEach(function () { + this.webExt.destroy(); + }); + + describe("creating a new container", function () { + beforeEach(async function () { + await this.webExt.popup.helper.clickElementById("container-add-link"); + await this.webExt.popup.helper.clickElementById("edit-container-ok-link"); + }); + + it("should create it in the browser as well", function () { + this.webExt.background.browser.contextualIdentities.create.should.have.been.calledOnce; + }); + + describe("manually assign a valid URL to a container", function () { + const exampleUrl = "https://github.com/mozilla/multi-account-containers"; + beforeEach(async function () { + await this.webExt.popup.helper.clickElementById("edit-containers-link"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll(".edit-container-icon", "last"); + this.webExt.popup.window.document.getElementById("edit-container-panel-site-input").value = exampleUrl; + await this.webExt.popup.helper.clickElementById("edit-container-site-link"); + }); + + it("should assign the URL to a container", function () { + this.webExt.background.browser.contextualIdentities.create.should.have.been.calledOnce; + }); + }); + + describe("manually assign valid URL without protocol to a container", function () { + const exampleUrl = "github.com/mozilla/multi-account-containers"; + beforeEach(async function () { + await this.webExt.popup.helper.clickElementById("edit-containers-link"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll(".edit-container-icon", "last"); + this.webExt.popup.window.document.getElementById("edit-container-panel-site-input").value = exampleUrl; + await this.webExt.popup.helper.clickElementById("edit-container-site-link"); + }); + + it("should assign the URL without protocol to a container", function () { + this.webExt.background.browser.contextualIdentities.create.should.have.been.calledOnce; + }); + }); + + describe("manually assign an invalid URL to a container", function () { + const exampleUrl = "github"; + beforeEach(async function () { + await this.webExt.popup.helper.clickElementById("edit-containers-link"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll(".edit-container-icon", "last"); + this.webExt.popup.window.document.getElementById("edit-container-panel-site-input").value = exampleUrl; + await this.webExt.popup.helper.clickElementById("edit-container-site-link"); + }); + + it("should not assign the URL to a container", function () { + // console.log(this.webExt.background.browser.contextualIdentities); + // expect( console.log.calledOnce ).to.be.true; + this.webExt.background.browser.contextualIdentities.update.should.not.have.been.called; + }); + }); + + describe("manually assign empty URL to a container", function () { + const exampleUrl = ""; + beforeEach(async function () { + await this.webExt.popup.helper.clickElementById("edit-containers-link"); + await this.webExt.popup.helper.clickElementByQuerySelectorAll(".edit-container-icon", "last"); + this.webExt.popup.window.document.getElementById("edit-container-panel-site-input").value = exampleUrl; + await this.webExt.popup.helper.clickElementById("edit-container-site-link"); + }); + + it("should not assign the URL to a container", function () { + this.webExt.background.browser.contextualIdentities.update.should.not.have.been.called; + }); + }); + }); +}); \ No newline at end of file