зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1620767 - Fix test_extension_storage_actor_upgrade intermittency by explicitly waiting the stores-update RDP event. r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D84215
This commit is contained in:
Родитель
1a2268d278
Коммит
b2f2e7f66d
|
@ -89,9 +89,11 @@ add_task(async function test_panel_live_reload() {
|
|||
extension.sendMessage("storage-local-set", { a: 123 });
|
||||
await extension.awaitMessage("storage-local-set:done");
|
||||
|
||||
const { target, extensionStorage } = await openAddonStoragePanel(
|
||||
extension.id
|
||||
);
|
||||
const {
|
||||
target,
|
||||
extensionStorage,
|
||||
storageFront,
|
||||
} = await openAddonStoragePanel(extension.id);
|
||||
|
||||
manifest = {
|
||||
...manifest,
|
||||
|
@ -99,6 +101,20 @@ add_task(async function test_panel_live_reload() {
|
|||
};
|
||||
// "Reload" is most similar to an upgrade, as e.g. storage data is preserved
|
||||
info("Update to version 2.0");
|
||||
|
||||
// Wait for the storage front to receive an event for the storage panel refresh
|
||||
// when the extension has been reloaded.
|
||||
const promiseStoragePanelUpdated = new Promise(resolve => {
|
||||
storageFront.on("stores-update", function updateListener(updates) {
|
||||
info(`Got stores-update event: ${JSON.stringify(updates)}`);
|
||||
const extStorageAdded = updates.added?.extensionStorage;
|
||||
if (host in extStorageAdded && extStorageAdded[host].length > 0) {
|
||||
storageFront.off("stores-update", updateListener);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await extension.upgrade(
|
||||
getExtensionConfig({
|
||||
manifest,
|
||||
|
@ -106,16 +122,10 @@ add_task(async function test_panel_live_reload() {
|
|||
})
|
||||
);
|
||||
|
||||
await extension.awaitMessage("extension-origin");
|
||||
|
||||
// When the webextension target is attached, we need to wait until the storage
|
||||
// is populated with the proper data again.
|
||||
// XXX: This seems to be a race which has a much higher frequency when the
|
||||
// target is attached, but the relationship between the two is unclear.
|
||||
await asyncWaitUntil(async () => {
|
||||
const { data } = await extensionStorage.getStoreObjects(host);
|
||||
return data?.length > 0;
|
||||
});
|
||||
await Promise.all([
|
||||
extension.awaitMessage("extension-origin"),
|
||||
promiseStoragePanelUpdated,
|
||||
]);
|
||||
|
||||
const { data } = await extensionStorage.getStoreObjects(host);
|
||||
Assert.deepEqual(
|
||||
|
@ -133,18 +143,3 @@ add_task(async function test_panel_live_reload() {
|
|||
|
||||
await shutdown(extension, target);
|
||||
});
|
||||
|
||||
/**
|
||||
* Duplicated from shared-head.js
|
||||
*/
|
||||
async function asyncWaitUntil(predicate, interval = 100) {
|
||||
let success = await predicate();
|
||||
const { setTimeout } = require("resource://gre/modules/Timer.jsm");
|
||||
while (!success) {
|
||||
// Wait for X milliseconds.
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
await new Promise(resolve => setTimeout(resolve, interval));
|
||||
// Test the predicate again.
|
||||
success = await predicate();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче