Merge pull request #4 from CSCD01/issue-1670-backend

Issue 1670 backend
This commit is contained in:
Sherry Ma 2020-03-09 17:21:40 -04:00 committed by GitHub
commit 8164a69b19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 12 deletions

View file

@ -1092,32 +1092,36 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
const tabId = currentTab.id;
const fullURL = this.checkUrl(url);
// Assign URL to container
await Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false);
if (fullURL !== null) {
// Assign URL to container
await Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false);
// Clear form
document.querySelector("#edit-container-panel-site-input").value = "";
// Clear form
document.querySelector("#edit-container-panel-site-input").value = "";
// Show new assignments
const assignments = await Logic.getAssignmentObjectByContainer(userContextId);
this.showAssignedContainers(assignments);
// Show new assignments
const assignments = await Logic.getAssignmentObjectByContainer(userContextId);
this.showAssignedContainers(assignments);
}
},
checkUrl(url){
// append "https://" if protocol not found
const validUrl = /[\w.-]+(?:\.[\w.-]+)/g;
const regexWww = /.*www\..*/g;
const foundWww = url.match(regexWww);
const regexhttp = /^http:\/\/.*/g;
const regexhttps = /^https:\/\/.*/g;
const foundhttp = url.match(regexhttp);
const foundhttps = url.match(regexhttps);
let newURL = url;
if (!url.match(validUrl)) {
return null;
}
if (!foundhttp && !foundhttps) {
if (!url.match(regexhttp) && !url.match(regexhttps)) {
newURL = "https://" + url;
}
if (!foundWww) {
if (!url.match(regexWww)) {
if (newURL.match(regexhttp)) {
newURL = "http://www." + newURL.substring(7);
} else if (newURL.match(regexhttps)) {

81
test/issues/1670.test.js Normal file
View file

@ -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;
});
});
});
});