diff --git a/src/js/.eslintrc.js b/src/js/.eslintrc.js index f78079f..11cd71a 100644 --- a/src/js/.eslintrc.js +++ b/src/js/.eslintrc.js @@ -7,6 +7,7 @@ module.exports = { "badge": true, "backgroundLogic": true, "identityState": true, - "messageHandler": true + "messageHandler": true, + "sync": true } }; diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index 5c3f33e..8e82678 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -66,6 +66,7 @@ const assignManager = { this.setExempted(pageUrlorUrlKey, tabId); }); } + // eslint-disable-next-line require-atomic-updates data.identityMacAddonUUID = await identityState.lookupMACaddonUUID(data.userContextId); await this.area.set({ @@ -124,7 +125,7 @@ const assignManager = { for(const configKey of Object.keys(macConfigs)) { if (configKey.includes("siteContainerMap@@_")) { const cookieStoreId = - "firefox-container-" + macConfigs[configKey].userContextId; + "firefox-container-" + macConfigs[configKey].userContextId; const match = identitiesList.find( localIdentity => localIdentity.cookieStoreId === cookieStoreId ); diff --git a/src/js/background/index.html b/src/js/background/index.html index 78dbe21..c5c7889 100644 --- a/src/js/background/index.html +++ b/src/js/background/index.html @@ -14,11 +14,11 @@ ] --> + - diff --git a/src/js/background/sync.js b/src/js/background/sync.js index f4959eb..48a6270 100644 --- a/src/js/background/sync.js +++ b/src/js/background/sync.js @@ -160,10 +160,10 @@ const sync = { sync.storageArea.onChangedListener ); - const hasCIListener = await hasContextualIdentityListeners(); + const hasCIListener = await sync.hasContextualIdentityListeners(); if (!hasCIListener) { - await addContextualIdentityListeners(); + await sync.addContextualIdentityListeners(); } if (!hasStorageListener) { @@ -178,10 +178,10 @@ const sync = { sync.storageArea.onChangedListener ); - const hasCIListener = await hasContextualIdentityListeners(); + const hasCIListener = await sync.hasContextualIdentityListeners(); if (hasCIListener) { - await removeContextualIdentityListeners(); + await sync.removeContextualIdentityListeners(); } if (hasStorageListener) { @@ -210,6 +210,30 @@ const sync = { await sync.storageArea.backup(); return; }, + + async addContextualIdentityListeners(listenerList) { + if(!listenerList) listenerList = syncCIListenerList; + await browser.contextualIdentities.onCreated.addListener(listenerList[0]); + await browser.contextualIdentities.onRemoved.addListener(listenerList[1]); + await browser.contextualIdentities.onUpdated.addListener(listenerList[2]); + }, + + async removeContextualIdentityListeners(listenerList) { + if(!listenerList) listenerList = syncCIListenerList; + await browser.contextualIdentities.onCreated.removeListener(listenerList[0]); + await browser.contextualIdentities.onRemoved.removeListener(listenerList[1]); + await browser.contextualIdentities.onUpdated.removeListener(listenerList[2]); + }, + + async hasContextualIdentityListeners(listenerList) { + if(!listenerList) listenerList = syncCIListenerList; + return ( + await browser.contextualIdentities.onCreated.hasListener(listenerList[0]) && + await browser.contextualIdentities.onRemoved.hasListener(listenerList[1]) && + await browser.contextualIdentities.onUpdated.hasListener(listenerList[2]) + ); + } + }; sync.init(); @@ -381,7 +405,7 @@ async function reconcileSiteAssignments() { const deletedSiteList = await sync.storageArea.getDeletedSiteList(); for(const siteStoreKey of deletedSiteList) { - if (assignedSitesLocal.hasOwnProperty(siteStoreKey)) { + if (Object.prototype.hasOwnProperty.call(assignedSitesLocal,siteStoreKey)) { assignManager .storageArea .remove(siteStoreKey.replace(/^siteContainerMap@@_/, "https://")); @@ -416,6 +440,7 @@ async function setAssignmentWithUUID (assignedSite, urlKey) { const uuid = assignedSite.identityMacAddonUUID; const cookieStoreId = await identityState.lookupCookieStoreId(uuid); if (cookieStoreId) { + // eslint-disable-next-line require-atomic-updates assignedSite.userContextId = cookieStoreId .replace(/^firefox-container-/, ""); await assignManager.storageArea.set( @@ -434,26 +459,3 @@ const syncCIListenerList = [ sync.storageArea.addToDeletedList, sync.storageArea.backup ]; - -async function addContextualIdentityListeners(listenerList) { - if(!listenerList) listenerList = syncCIListenerList; - await browser.contextualIdentities.onCreated.addListener(listenerList[0]); - await browser.contextualIdentities.onRemoved.addListener(listenerList[1]); - await browser.contextualIdentities.onUpdated.addListener(listenerList[2]); -} - -async function removeContextualIdentityListeners(listenerList) { - if(!listenerList) listenerList = syncCIListenerList; - await browser.contextualIdentities.onCreated.removeListener(listenerList[0]); - await browser.contextualIdentities.onRemoved.removeListener(listenerList[1]); - await browser.contextualIdentities.onUpdated.removeListener(listenerList[2]); -} - -async function hasContextualIdentityListeners(listenerList) { - if(!listenerList) listenerList = syncCIListenerList; - return ( - await browser.contextualIdentities.onCreated.hasListener(listenerList[0]) && - await browser.contextualIdentities.onRemoved.hasListener(listenerList[1]) && - await browser.contextualIdentities.onUpdated.hasListener(listenerList[2]) - ); -} diff --git a/src/js/background/test.js b/src/js/background/test.js index 0f1c58f..166d0e8 100644 --- a/src/js/background/test.js +++ b/src/js/background/test.js @@ -365,12 +365,12 @@ browser.tests = { async stopSyncListeners() { await browser.storage.onChanged.removeListener(sync.storageArea.onChangedListener); - await removeContextualIdentityListeners(); + await sync.removeContextualIdentityListeners(); }, async startListeners() { await browser.storage.onChanged.addListener(sync.storageArea.onChangedListener); - await addContextualIdentityListeners(); + await sync.addContextualIdentityListeners(); }, }; diff --git a/test/features/external-webextensions.test.js b/test/features/external-webextensions.test.js index 485005c..76db303 100644 --- a/test/features/external-webextensions.test.js +++ b/test/features/external-webextensions.test.js @@ -27,7 +27,9 @@ describe("External Webextensions", () => { const answer = await promise; expect(answer.userContextId === "1").to.be.true; expect(answer.neverAsk === false).to.be.true; - expect(answer.hasOwnProperty("identityMacAddonUUID")).to.be.true; + expect( + Object.prototype.hasOwnProperty.call( + answer, "identityMacAddonUUID")).to.be.true; }); }); diff --git a/test/features/sync.test.js b/test/features/sync.test.js index 72656fa..61915e1 100644 --- a/test/features/sync.test.js +++ b/test/features/sync.test.js @@ -1,7 +1,6 @@ describe("Sync", () => { it("should init sync on startup", async () => { - console.log("!!!a") const tab = await helper.browser.initializeWithTab(); console.log(await background.browser.storage.local.get()); const mozContainer = await background.browser.contextualIdentities.create({ @@ -54,7 +53,6 @@ describe("Sync", () => { }); } })); - console.log("!!!c"); await background.browser.runtime.onStartup.addListener.yield(); await nextTick(); @@ -62,7 +60,6 @@ describe("Sync", () => { console.log(await background.browser.storage.local.get()); expect(sync.identities.length).to.equal(5); - console.log("!!!b"); }); }); \ No newline at end of file