working with tests
This commit is contained in:
@@ -26,6 +26,7 @@ describe("External Webextensions", () => {
|
||||
const [promise] = background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
|
||||
const answer = await promise;
|
||||
expect(answer).to.deep.equal({
|
||||
hostname: "example.com",
|
||||
userContextId: "1",
|
||||
neverAsk: false
|
||||
});
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
describe("Sync", () => {
|
||||
let tab;
|
||||
beforeEach(async () => {
|
||||
tab = await helper.browser.initializeWithTab();
|
||||
});
|
||||
|
||||
it.only("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({
|
||||
name: "Mozilla",
|
||||
color: "red",
|
||||
@@ -55,12 +54,55 @@ describe("Sync", () => {
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
console.log("!!!c");
|
||||
await background.browser.runtime.onStartup.addListener.yield();
|
||||
await nextTick();
|
||||
|
||||
const sync = await background.browser.storage.sync.get();
|
||||
console.log(await background.browser.storage.local.get());
|
||||
|
||||
expect(sync.identities.length).to.equal(5);
|
||||
console.log("!!!b");
|
||||
});
|
||||
});
|
||||
|
||||
it("should sync for the first time", async () => {
|
||||
const mozContainer = await background.browser.contextualIdentities.create({
|
||||
name:"Test",
|
||||
color:"green",
|
||||
icon:"pet"
|
||||
});
|
||||
console.log(await background.browser.contextualIdentities.query({}));
|
||||
await helper.browser.initSyncTest({localStorage:SYNC_TEST_1_LOCAL});
|
||||
console.log(await background.browser.storage.local.get());
|
||||
for (const containerName of SYNC_TEST_CONTAINERS) {
|
||||
const storageKeyString = "identitiesState@@_" + containerName;
|
||||
const answer = await background.browser.storage.local.get(storageKeyString);
|
||||
expect(answer[storageKeyString].hasOwnProperty("macAddonUUID")).to.be.true;
|
||||
}
|
||||
const storageKeyString = "identitiesState@@_" + mozContainer.cookieStoreId;
|
||||
const answer = await background.browser.storage.local.get(storageKeyString);
|
||||
expect(answer[storageKeyString].hasOwnProperty("macAddonUUID")).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
const SYNC_TEST_1_LOCAL = {
|
||||
"browserActionBadgesClicked":["6.1.1"],
|
||||
"containerTabsOpened":6,
|
||||
"identitiesState@@_firefox-container-1":{"hiddenTabs":[]},
|
||||
"identitiesState@@_firefox-container-2":{"hiddenTabs":[]},
|
||||
"identitiesState@@_firefox-container-3":{"hiddenTabs":[]},
|
||||
"identitiesState@@_firefox-container-4":{"hiddenTabs":[]},
|
||||
"identitiesState@@_firefox-container-6":{"hiddenTabs":[]},
|
||||
"identitiesState@@_firefox-default":{"hiddenTabs":[]},
|
||||
"onboarding-stage":5,
|
||||
"siteContainerMap@@_twitter.com":{"userContextId":"1","neverAsk":true},
|
||||
"siteContainerMap@@_www.facebook.com":{"userContextId":"2","neverAsk":true},
|
||||
"siteContainerMap@@_www.linkedin.com":{"userContextId":"4","neverAsk":false}
|
||||
};
|
||||
|
||||
const SYNC_TEST_CONTAINERS = [
|
||||
"firefox-container-1",
|
||||
"firefox-container-2",
|
||||
"firefox-container-3",
|
||||
"firefox-container-4"
|
||||
];
|
||||
+36
-1
@@ -19,6 +19,7 @@ module.exports = {
|
||||
"achievements": []
|
||||
});
|
||||
window.browser.storage.local.set.resetHistory();
|
||||
window.browser.storage.sync.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +30,41 @@ module.exports = {
|
||||
|
||||
async openNewTab(tab, options = {}) {
|
||||
return background.browser.tabs._create(tab, options);
|
||||
}
|
||||
},
|
||||
|
||||
async initSyncTest(details = {}) {
|
||||
if (!details.cookieStoreId) details.cookieStoreId = "firefox-default";
|
||||
if (!details.localStorage) {
|
||||
details.localStorage = {
|
||||
"browserActionBadgesClicked": [],
|
||||
"onboarding-stage": 5,
|
||||
"achievements": []
|
||||
};
|
||||
}
|
||||
if (!details.syncStorage) details.syncStorage = {};
|
||||
let tab;
|
||||
await buildDom({
|
||||
background: {
|
||||
async afterBuild(background) {
|
||||
tab = await background.browser.tabs._create({ cookieStoreId: details.cookieStoreId });
|
||||
}
|
||||
},
|
||||
popup: {
|
||||
jsdom: {
|
||||
beforeParse(window) {
|
||||
window.browser.storage.clear();
|
||||
window.browser.storage.local.set(details.localStorage);
|
||||
window.browser.storage.local.set.resetHistory();
|
||||
window.browser.storage.sync.clear();
|
||||
window.browser.storage.sync.set(details.syncStorage);
|
||||
window.browser.storage.sync.set.resetHistory();
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
return tab;
|
||||
},
|
||||
},
|
||||
|
||||
popup: {
|
||||
|
||||
Reference in New Issue
Block a user