fixed cookiestoreIDmap
This commit is contained in:
parent
10d08f2ac9
commit
33909d147a
3 changed files with 224 additions and 35 deletions
|
@ -79,13 +79,10 @@ const identityState = {
|
||||||
|
|
||||||
async getCookieStoreIDuuidMap() {
|
async getCookieStoreIDuuidMap() {
|
||||||
const containers = {};
|
const containers = {};
|
||||||
const containerInfo = await identityState.storageArea.area.get();
|
const identities = await browser.contextualIdentities.query({});
|
||||||
for(const configKey of Object.keys(containerInfo)) {
|
for(const identity of identities) {
|
||||||
if (configKey.includes("identitiesState@@_")) {
|
const containerInfo = await this.storageArea.get(identity.cookieStoreId);
|
||||||
const container = containerInfo[configKey];
|
containers[identity.cookieStoreId] = containerInfo.macAddonUUID;
|
||||||
const cookieStoreId = configKey.replace(/^identitiesState@@_/, "");
|
|
||||||
containers[cookieStoreId] = container.macAddonUUID;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return containers;
|
return containers;
|
||||||
},
|
},
|
||||||
|
|
|
@ -62,14 +62,14 @@ const sync = {
|
||||||
await addToDeletedSitesList(options.siteStoreKey);
|
await addToDeletedSitesList(options.siteStoreKey);
|
||||||
if (options && options.undelete)
|
if (options && options.undelete)
|
||||||
await removeFromDeletedSitesList(options.undelete);
|
await removeFromDeletedSitesList(options.undelete);
|
||||||
if (SYNC_DEBUG) {
|
// if (SYNC_DEBUG) {
|
||||||
const storage = await sync.storageArea.get();
|
// const storage = await sync.storageArea.get();
|
||||||
console.log("inSync: ", storage);
|
// console.log("inSync: ", storage);
|
||||||
const localStorage = await browser.storage.local.get();
|
// const localStorage = await browser.storage.local.get();
|
||||||
console.log("inLocal:", localStorage);
|
// console.log("inLocal:", localStorage);
|
||||||
console.log("idents: ", await browser.contextualIdentities.query({}));
|
// console.log("idents: ", await browser.contextualIdentities.query({}));
|
||||||
}
|
// }
|
||||||
|
console.log("Backed up!");
|
||||||
await sync.checkForListenersMaybeAdd();
|
await sync.checkForListenersMaybeAdd();
|
||||||
|
|
||||||
async function updateSyncIdentities() {
|
async function updateSyncIdentities() {
|
||||||
|
@ -160,7 +160,9 @@ const sync = {
|
||||||
sync.storageArea.onChangedListener
|
sync.storageArea.onChangedListener
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! await hasContextualIdentityListeners()) {
|
const hasCIListener = await hasContextualIdentityListeners();
|
||||||
|
|
||||||
|
if (!hasCIListener) {
|
||||||
addContextualIdentityListeners();
|
addContextualIdentityListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +178,9 @@ const sync = {
|
||||||
sync.storageArea.onChangedListener
|
sync.storageArea.onChangedListener
|
||||||
);
|
);
|
||||||
|
|
||||||
if (await hasContextualIdentityListeners()) {
|
const hasCIListener = await hasContextualIdentityListeners();
|
||||||
|
|
||||||
|
if (hasCIListener) {
|
||||||
removeContextualIdentityListeners();
|
removeContextualIdentityListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,9 +194,8 @@ const sync = {
|
||||||
if (SYNC_DEBUG) {
|
if (SYNC_DEBUG) {
|
||||||
const syncInfo = await sync.storageArea.get();
|
const syncInfo = await sync.storageArea.get();
|
||||||
const localInfo = await browser.storage.local.get();
|
const localInfo = await browser.storage.local.get();
|
||||||
console.log("inSync: ", syncInfo);
|
const idents = await browser.contextualIdentities.query({});
|
||||||
console.log("inLocal: ", localInfo);
|
console.log("Initial State:", {syncInfo, localInfo, idents});
|
||||||
console.log("indents: ", await browser.contextualIdentities.query({}));
|
|
||||||
}
|
}
|
||||||
await sync.checkForListenersMaybeRemove();
|
await sync.checkForListenersMaybeRemove();
|
||||||
console.log("runSync");
|
console.log("runSync");
|
||||||
|
@ -252,6 +255,7 @@ async function reconcileIdentities(){
|
||||||
// now compare all containers for matching names.
|
// now compare all containers for matching names.
|
||||||
for (const syncIdentity of syncIdentities) {
|
for (const syncIdentity of syncIdentities) {
|
||||||
syncIdentity.macAddonUUID = cookieStoreIDmap[syncIdentity.cookieStoreId];
|
syncIdentity.macAddonUUID = cookieStoreIDmap[syncIdentity.cookieStoreId];
|
||||||
|
if (syncIdentity.macAddonUUID){
|
||||||
const localMatch = localIdentities.find(
|
const localMatch = localIdentities.find(
|
||||||
localIdentity => localIdentity.name === syncIdentity.name
|
localIdentity => localIdentity.name === syncIdentity.name
|
||||||
);
|
);
|
||||||
|
@ -269,6 +273,8 @@ async function reconcileIdentities(){
|
||||||
await ifNamesMatch(syncIdentity, localMatch);
|
await ifNamesMatch(syncIdentity, localMatch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// if no macAddonUUID, there is a problem with the sync info and it needs to be ignored.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ifNamesMatch(syncIdentity, localMatch) {
|
async function ifNamesMatch(syncIdentity, localMatch) {
|
||||||
|
@ -291,7 +297,6 @@ async function ifNamesMatch(syncIdentity, localMatch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync is truth. If all is the same, update the local uuid to match sync
|
// Sync is truth. If all is the same, update the local uuid to match sync
|
||||||
await identityState.updateUUID(
|
await identityState.updateUUID(
|
||||||
localMatch.cookieStoreId,
|
localMatch.cookieStoreId,
|
||||||
|
|
|
@ -243,6 +243,64 @@ browser.tests = {
|
||||||
console.log("Finished!");
|
console.log("Finished!");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async CIerrorTest() {
|
||||||
|
await browser.tests.stopSyncListeners();
|
||||||
|
console.log("Test state from sync that duped everything initially");
|
||||||
|
|
||||||
|
await this.setState(
|
||||||
|
CI_ERROR_TEST_SYNC,
|
||||||
|
CI_ERROR_TEST_LOCAL,
|
||||||
|
CI_ERROR_TEST_IDENTS,
|
||||||
|
CI_ERROR_TEST_SITES
|
||||||
|
);
|
||||||
|
|
||||||
|
await sync.runSync();
|
||||||
|
|
||||||
|
const getSync = await browser.storage.sync.get();
|
||||||
|
const getAssignedSites =
|
||||||
|
await assignManager.storageArea.getAssignedSites();
|
||||||
|
|
||||||
|
const identities = await browser.contextualIdentities.query({});
|
||||||
|
|
||||||
|
const localCookieStoreIDmap =
|
||||||
|
await identityState.getCookieStoreIDuuidMap();
|
||||||
|
|
||||||
|
console.assert(
|
||||||
|
Object.keys(getSync.cookieStoreIDmap).length === 7,
|
||||||
|
"cookieStoreIDmap should have 7 entries"
|
||||||
|
);
|
||||||
|
|
||||||
|
console.assert(
|
||||||
|
Object.keys(localCookieStoreIDmap).length === 8,
|
||||||
|
"localCookieStoreIDmap should have 8 entries"
|
||||||
|
);
|
||||||
|
|
||||||
|
console.assert(
|
||||||
|
identities.length === 7,
|
||||||
|
"There should be 7 identities"
|
||||||
|
);
|
||||||
|
|
||||||
|
console.assert(
|
||||||
|
Object.keys(getAssignedSites).length === 5,
|
||||||
|
"There should be 5 site assignments"
|
||||||
|
);
|
||||||
|
|
||||||
|
const personalContainer =
|
||||||
|
this.lookupIdentityBy(identities, {name: "Personal"});
|
||||||
|
console.log(personalContainer);
|
||||||
|
console.assert(
|
||||||
|
personalContainer.color === "red",
|
||||||
|
"Personal Container should be red"
|
||||||
|
);
|
||||||
|
const mozillaContainer =
|
||||||
|
this.lookupIdentityBy(identities, {name: "Mozilla"});
|
||||||
|
console.assert(
|
||||||
|
mozillaContainer.icon === "pet",
|
||||||
|
"Mozilla Container should be pet"
|
||||||
|
);
|
||||||
|
console.log("Finished!");
|
||||||
|
},
|
||||||
|
|
||||||
lookupIdentityBy(identities, options) {
|
lookupIdentityBy(identities, options) {
|
||||||
for (const identity of identities) {
|
for (const identity of identities) {
|
||||||
if (options && options.name) {
|
if (options && options.name) {
|
||||||
|
@ -555,3 +613,132 @@ const DUPE_TEST_IDENTS = [
|
||||||
"color": "yellow",
|
"color": "yellow",
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CI_ERROR_TEST_SYNC = {
|
||||||
|
"identities": [
|
||||||
|
{
|
||||||
|
"name": "Personal",
|
||||||
|
"icon": "fingerprint",
|
||||||
|
"iconUrl": "resource://usercontext-content/fingerprint.svg",
|
||||||
|
"color": "blue",
|
||||||
|
"colorCode": "#37adff",
|
||||||
|
"cookieStoreId": "firefox-container-6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mozilla",
|
||||||
|
"icon": "fruit",
|
||||||
|
"iconUrl": "resource://usercontext-content/fruit.svg",
|
||||||
|
"color": "purple",
|
||||||
|
"colorCode": "#af51f5",
|
||||||
|
"cookieStoreId": "firefox-container-8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Groceries, obviously",
|
||||||
|
"icon": "cart",
|
||||||
|
"iconUrl": "resource://usercontext-content/cart.svg",
|
||||||
|
"color": "yellow",
|
||||||
|
"colorCode": "#ffcb00",
|
||||||
|
"cookieStoreId": "firefox-container-9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Facebook",
|
||||||
|
"icon": "circle",
|
||||||
|
"iconUrl": "resource://usercontext-content/circle.svg",
|
||||||
|
"color": "blue",
|
||||||
|
"colorCode": "#37adff",
|
||||||
|
"cookieStoreId": "firefox-container-10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Work",
|
||||||
|
"icon": "briefcase",
|
||||||
|
"iconUrl": "resource://usercontext-content/briefcase.svg",
|
||||||
|
"color": "orange",
|
||||||
|
"colorCode": "#ff9f00",
|
||||||
|
"cookieStoreId": "firefox-container-11"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Greg's container",
|
||||||
|
"icon": "vacation",
|
||||||
|
"iconUrl": "resource://usercontext-content/vacation.svg",
|
||||||
|
"color": "yellow",
|
||||||
|
"colorCode": "#ffcb00",
|
||||||
|
"cookieStoreId": "firefox-container-14"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"deletedIdentityList": [
|
||||||
|
"8098140e-d406-4321-b4f5-24763b4f9513",
|
||||||
|
"73aebc7a-286f-408a-9a94-a06d29b288e0",
|
||||||
|
"8f153224-bbe8-4664-ba02-0293ddec3e78"
|
||||||
|
],
|
||||||
|
"cookieStoreIDmap": {
|
||||||
|
"firefox-container-10": "58956e95-43fb-44af-95c0-1ec8d83e1e13",
|
||||||
|
"firefox-container-11": "0269558d-6be7-487b-beb1-b720b346d09b",
|
||||||
|
"firefox-container-14": "e48d04cf-6277-4236-8f3d-611287d0caf2",
|
||||||
|
"firefox-container-6": "869a7563-030d-4a63-8a84-209270561d3c",
|
||||||
|
"firefox-container-8": "73aebc7a-286f-408a-9a94-a06d29b288e0",
|
||||||
|
"firefox-container-9": "4831fef4-6f43-47fb-a578-ccdc3ee7f883"
|
||||||
|
},
|
||||||
|
"assignedSites": {
|
||||||
|
"siteContainerMap@@_bugzilla.mozilla.org": {
|
||||||
|
"userContextId": "11",
|
||||||
|
"neverAsk": true,
|
||||||
|
"hostname": "bugzilla.mozilla.org"
|
||||||
|
},
|
||||||
|
"siteContainerMap@@_www.amazon.com": {
|
||||||
|
"userContextId": "14",
|
||||||
|
"neverAsk": false,
|
||||||
|
"hostname": "www.amazon.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deletedSiteList": [
|
||||||
|
"siteContainerMap@@_www.facebook.com"
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const CI_ERROR_TEST_LOCAL = {
|
||||||
|
"browserActionBadgesClicked": [
|
||||||
|
"6.1.1"
|
||||||
|
],
|
||||||
|
"containerTabsOpened": 6,
|
||||||
|
"onboarding-stage": 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
const CI_ERROR_TEST_SITES = [
|
||||||
|
"siteContainerMap@@_bugzilla.mozilla.org",
|
||||||
|
"siteContainerMap@@_www.bankofoklahoma.com",
|
||||||
|
"siteContainerMap@@_www.mozilla.org",
|
||||||
|
"siteContainerMap@@_www.reddit.com"
|
||||||
|
];
|
||||||
|
|
||||||
|
const CI_ERROR_TEST_IDENTS = [
|
||||||
|
{
|
||||||
|
"name": "Personal",
|
||||||
|
"icon": "fingerprint",
|
||||||
|
"color": "blue",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Work",
|
||||||
|
"icon": "briefcase",
|
||||||
|
"color": "orange",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Banking",
|
||||||
|
"icon": "dollar",
|
||||||
|
"color": "green",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mozilla",
|
||||||
|
"icon": "fruit",
|
||||||
|
"color": "purple",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Groceries, obviously",
|
||||||
|
"icon": "cart",
|
||||||
|
"color": "yellow",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Facebook",
|
||||||
|
"icon": "circle",
|
||||||
|
"color": "blue",
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
Loading…
Add table
Reference in a new issue