wrote tests tests for browser use

This commit is contained in:
Kendall Werts
2020-01-08 18:33:02 -06:00
parent 53f7dc4915
commit 3a7744b41b
4 changed files with 197 additions and 138 deletions
+21 -3
View File
@@ -39,19 +39,37 @@ const identityState = {
const storeKey = this.getContainerStoreKey(cookieStoreId);
return await this.area.remove([storeKey]);
},
/*
* Looks for abandoned identities keys in local storage, and makes sure all
* identities registered in the browser are also in local storage. (this
* appears to not always be the case based on how this.get() is written)
*/
async cleanup() {
const identitiesList = await browser.contextualIdentities.query({});
const macConfigs = await this.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_")) {
const cookieStoreId = String(configKey).replace(/^identitiesState@@_/, "");
const match = identitiesList.find(localIdentity => localIdentity.cookieStoreId === cookieStoreId);
if (!match && cookieStoreId !== "firefox-default") {
console.log("removed ", cookieStoreId, " from storage list");
const match = identitiesList.find(
localIdentity => localIdentity.cookieStoreId === cookieStoreId
);
if (cookieStoreId === "firefox-default") continue;
if (!match) {
this.remove(cookieStoreId);
continue;
}
if (!macConfigs[configKey].macAddonUUID) {
await identityState.addUUID(cookieStoreId);
}
}
}
for (const identity of identitiesList) {
// ensure all identities have an entry in local storage
const data = await this.get(identity.cookieStoreId);
await this.set(identity.cookieStoreId, data);
}
}
},