From 4bcb908942abf21daa6bd470df9bcd49c28489c1 Mon Sep 17 00:00:00 2001 From: stoically Date: Thu, 19 Dec 2019 07:49:41 +0100 Subject: [PATCH] Feature test container sync initialization --- test/features/sync.test.js | 66 ++++++++++++++++++++++++++++++++++++++ test/setup.js | 4 +++ 2 files changed, 70 insertions(+) create mode 100644 test/features/sync.test.js diff --git a/test/features/sync.test.js b/test/features/sync.test.js new file mode 100644 index 0000000..8a9e3cb --- /dev/null +++ b/test/features/sync.test.js @@ -0,0 +1,66 @@ +describe("Sync", () => { + let tab; + beforeEach(async () => { + tab = await helper.browser.initializeWithTab(); + }); + + it.only("should init sync on startup", async () => { + const mozContainer = await background.browser.contextualIdentities.create({ + name: "Mozilla", + color: "red", + icon: "briefcase", + }); + + await background.browser.contextualIdentities.update("firefox-container-2", {color:"purple"}); + await background.browser.contextualIdentities.update("firefox-container-4", {icon:"pet"}); + + await Promise.all([ + { + userContextId: "1", + url: "https://twitter.com", + }, + { + userContextId: "2", + url: "https://www.facebook.com", + }, + { + userContextId: "4", + url: "https://www.linkedin.com", + neverAsk: true, + }, + { + userContextId: mozContainer.cookieStoreId.replace("firefox-container-", ""), + url: "https://developer.mozilla.org", + neverAsk: true, + } + ].map(async (assign) => { + await background.browser.tabs.update(tab.id, { + cookieStoreId: `firefox-container-${assign.userContextId}` + }); + + await background.browser.runtime.onMessage.addListener.yield({ + method: "setOrRemoveAssignment", + tabId: tab.id, + url: assign.url, + userContextId: assign.userContextId, + value: !true + }); + + if (assign.neverAsk) { + await nextTick(); + await background.browser.runtime.onMessage.addListener.yield({ + method: "neverAsk", + neverAsk: true, + pageUrl: assign.url, + }); + } + })); + + await background.browser.runtime.onStartup.addListener.yield(); + await nextTick(); + + const sync = await background.browser.storage.sync.get(); + + expect(sync.identities.length).to.equal(5); + }); +}); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js index 0cc45ee..b674ba0 100644 --- a/test/setup.js +++ b/test/setup.js @@ -5,6 +5,7 @@ if (!process.listenerCount("unhandledRejection")) { const path = require("path"); const chai = require("chai"); const sinonChai = require("sinon-chai"); +const crypto = require("crypto"); global.sinon = require("sinon"); global.expect = chai.expect; chai.should(); @@ -29,6 +30,9 @@ global.buildDom = async ({background = {}, popup = {}}) => { ...background.jsom, beforeParse(window) { window.browser.permissions.getAll.resolves({permissions: ["bookmarks"]}); + window.crypto = { + getRandomValues: arr => crypto.randomBytes(arr.length), + }; } } };