Bug 1728326 - Rename internal WebExtensions events related to the background script (from background-page into background-script). r=zombie

Differential Revision: https://phabricator.services.mozilla.com/D124783
This commit is contained in:
Luca Greco 2021-11-05 20:27:03 +00:00
Родитель 3c700405f0
Коммит e1715d6268
9 изменённых файлов: 62 добавлений и 58 удалений

Просмотреть файл

@ -2293,7 +2293,7 @@ class EventManager {
return;
}
primed.pendingEvents.push({ args, resolve, reject });
extension.emit("background-page-event");
extension.emit("background-script-event");
});
let fire = {

Просмотреть файл

@ -83,7 +83,7 @@ class BackgroundPage extends HiddenExtensionPage {
if (extension.persistentListeners) {
EventManager.clearPrimedListeners(this.extension, false);
}
extension.emit("background-page-aborted");
extension.emit("background-script-aborted");
return;
}
@ -103,7 +103,7 @@ class BackgroundPage extends HiddenExtensionPage {
EventManager.clearPrimedListeners(extension, !!this.extension);
}
extension.emit("background-page-started");
extension.emit("background-script-started");
}
shutdown() {
@ -175,8 +175,7 @@ class BackgroundWorker {
EventManager.clearPrimedListeners(this.extension, false);
}
// TODO(bug 17228326): rename this to "background-script-aborted".
extension.emit("background-page-aborted");
extension.emit("background-script-aborted");
return;
}
@ -194,8 +193,7 @@ class BackgroundWorker {
EventManager.clearPrimedListeners(extension, !!this.extension);
}
// TODO(bug 17228326): rename this to "background-script-started".
extension.emit("background-page-started");
extension.emit("background-script-started");
}
shutdown(isAppShutdown) {
@ -286,18 +284,18 @@ this.backgroundPage = class extends ExtensionAPI {
// Used by runtime messaging to wait for background page listeners.
let bgStartupPromise = new Promise(resolve => {
let done = () => {
extension.off("background-page-started", done);
extension.off("background-page-aborted", done);
extension.off("background-script-started", done);
extension.off("background-script-aborted", done);
extension.off("shutdown", done);
resolve();
};
extension.on("background-page-started", done);
extension.on("background-page-aborted", done);
extension.on("background-script-started", done);
extension.on("background-script-aborted", done);
extension.on("shutdown", done);
});
extension.wakeupBackground = () => {
extension.emit("background-page-event");
extension.emit("background-script-event");
extension.wakeupBackground = () => bgStartupPromise;
return bgStartupPromise;
};
@ -308,7 +306,7 @@ this.backgroundPage = class extends ExtensionAPI {
EventManager.primeListeners(extension);
extension.once("start-background-page", async () => {
extension.once("start-background-script", async () => {
if (!this.extension) {
// Extension was shut down. Don't build the background page.
// Primed listeners have been cleared in onShutdown.
@ -324,13 +322,13 @@ this.backgroundPage = class extends ExtensionAPI {
// or else we can miss it if the event occurs after the first
// window is painted but before #2
// 2. After all windows have been restored.
extension.once("background-page-event", async () => {
extension.once("background-script-event", async () => {
await ExtensionParent.browserPaintedPromise;
extension.emit("start-background-page");
extension.emit("start-background-script");
});
ExtensionParent.browserStartupPromise.then(() => {
extension.emit("start-background-page");
extension.emit("start-background-script");
});
}

Просмотреть файл

@ -38,9 +38,9 @@ this.runtime = class extends ExtensionAPI {
return () => {};
}
let listener = () => fire.sync();
extension.on("background-page-started", listener);
extension.on("background-script-started", listener);
return () => {
extension.off("background-page-started", listener);
extension.off("background-script-started", listener);
};
},
}).api(),
@ -70,9 +70,9 @@ this.runtime = class extends ExtensionAPI {
break;
}
};
extension.on("background-page-started", listener);
extension.on("background-script-started", listener);
return () => {
extension.off("background-page-started", listener);
extension.off("background-script-started", listener);
};
},
}).api(),

Просмотреть файл

@ -125,19 +125,25 @@ add_task(async function test_unload_extension_during_background_page_startup() {
let bgStartupPromise = new Promise(resolve => {
function onBackgroundPageDone(eventName) {
extension.extension.off("background-page-started", onBackgroundPageDone);
extension.extension.off("background-page-aborted", onBackgroundPageDone);
extension.extension.off(
"background-script-started",
onBackgroundPageDone
);
extension.extension.off(
"background-script-aborted",
onBackgroundPageDone
);
if (eventName === "background-page-aborted") {
info("Background page startup was interrupted");
if (eventName === "background-script-aborted") {
info("Background script startup was interrupted");
resolve("bg_aborted");
} else {
info("Background page startup finished normally");
info("Background script startup finished normally");
resolve("bg_fully_loaded");
}
}
extension.extension.on("background-page-started", onBackgroundPageDone);
extension.extension.on("background-page-aborted", onBackgroundPageDone);
extension.extension.on("background-script-started", onBackgroundPageDone);
extension.extension.on("background-script-aborted", onBackgroundPageDone);
});
let bgStartingPromise = new Promise(resolve => {

Просмотреть файл

@ -418,7 +418,7 @@ add_task(async function test_serviceworker_lifecycle_events() {
info(
"trigger delayed call to nsIServiceWorkerManager.registerForAddonPrincipal"
);
extension.extension.emit("start-background-page");
extension.extension.emit("start-background-script");
info("Force activate the extension worker");
const newSwReg = swm.getRegistrationByPrincipal(

Просмотреть файл

@ -27,7 +27,7 @@ const PAGE_HTML = `<!DOCTYPE html><meta charset="utf-8"><script src="script.js">
function trackEvents(wrapper) {
let events = new Map();
for (let event of ["background-page-event", "start-background-page"]) {
for (let event of ["background-script-event", "start-background-script"]) {
events.set(event, false);
wrapper.extension.once(event, () => events.set(event, true));
}
@ -67,7 +67,7 @@ async function test(what, background, script) {
function awaitBgEvent() {
return new Promise(resolve =>
extension.extension.once("background-page-event", resolve)
extension.extension.once("background-script-event", resolve)
);
}
@ -81,12 +81,12 @@ async function test(what, background, script) {
]);
equal(
events.get("background-page-event"),
events.get("background-script-event"),
true,
"Should have gotten a background page event"
);
equal(
events.get("start-background-page"),
events.get("start-background-script"),
false,
"Background page should not be started"
);
@ -98,9 +98,9 @@ async function test(what, background, script) {
await promise;
equal(
events.get("start-background-page"),
events.get("start-background-script"),
true,
"Should have gotten start-background-page event"
"Should have gotten start-background-script event"
);
await extension.awaitFinish("messaging-test");
@ -123,14 +123,14 @@ async function test(what, background, script) {
]);
equal(
events.get("background-page-event"),
events.get("background-script-event"),
true,
"Should have gotten a background page event"
"Should have gotten a background script event"
);
equal(
events.get("start-background-page"),
events.get("start-background-script"),
false,
"Background page should not be started"
"Background script should not be started"
);
equal(extension.messageQueue.size, 0, "Have not yet received bg-ran message");
@ -140,9 +140,9 @@ async function test(what, background, script) {
await promise;
equal(
events.get("start-background-page"),
events.get("start-background-script"),
true,
"Should have gotten start-background-page event"
"Should have gotten start-background-script event"
);
await extension.awaitFinish("messaging-test");

Просмотреть файл

@ -451,7 +451,7 @@ add_task(async function test_shutdown_before_background_loaded() {
fireWakeupBeforeBgFail = fire.wakeup();
fireAsyncBeforeBgFail = fire.async();
extension.extension.once("background-page-aborted", resolve);
extension.extension.once("background-script-aborted", resolve);
info("Forcing the background load to fail");
browser.remove();
};

Просмотреть файл

@ -46,7 +46,7 @@ function promiseExtensionEvent(wrapper, event) {
function trackEvents(wrapper) {
let events = new Map();
for (let event of ["background-page-event", "start-background-page"]) {
for (let event of ["background-script-event", "start-background-script"]) {
events.set(event, false);
wrapper.extension.once(event, () => events.set(event, true));
}
@ -112,9 +112,9 @@ add_task(async function test_proxy_startup() {
equal(2, nonProxiedRequests, "non proxied request ok");
equal(
events.get("background-page-event"),
events.get("background-script-event"),
false,
"Should not have gotten a background page event"
"Should not have gotten a background script event"
);
// Make a request that the extension will proxy once it is started.
@ -123,27 +123,27 @@ add_task(async function test_proxy_startup() {
ExtensionTestUtils.fetch("http://proxied.example.com/?a=1"),
]);
await promiseExtensionEvent(extension, "background-page-event");
await promiseExtensionEvent(extension, "background-script-event");
equal(
events.get("background-page-event"),
events.get("background-script-event"),
true,
"Should have gotten a background page event"
"Should have gotten a background script event"
);
// Test the background page startup.
equal(
events.get("start-background-page"),
events.get("start-background-script"),
false,
"Should have gotten a background page event"
"Should have gotten a background script event"
);
Services.obs.notifyObservers(null, "browser-delayed-startup-finished");
await new Promise(executeSoon);
equal(
events.get("start-background-page"),
events.get("start-background-script"),
true,
"Should have gotten a background page event"
"Should have gotten a background script event"
);
// Verify our proxied request finishes properly and that the

Просмотреть файл

@ -38,7 +38,7 @@ Services.prefs.setBoolPref(
function trackEvents(wrapper) {
let events = new Map();
for (let event of ["background-page-event", "start-background-page"]) {
for (let event of ["background-script-event", "start-background-script"]) {
events.set(event, false);
wrapper.extension.once(event, () => events.set(event, true));
}
@ -47,23 +47,23 @@ function trackEvents(wrapper) {
async function testPersistentRequestStartup(extension, events, expect) {
equal(
events.get("background-page-event"),
events.get("background-script-event"),
expect.background,
"Should have gotten a background page event"
"Should have gotten a background script event"
);
equal(
events.get("start-background-page"),
events.get("start-background-script"),
false,
"Background page should not be started"
"Background script should not be started"
);
Services.obs.notifyObservers(null, "browser-delayed-startup-finished");
await ExtensionParent.browserPaintedPromise;
equal(
events.get("start-background-page"),
events.get("start-background-script"),
expect.delayedStart,
"Should have gotten start-background-page event"
"Should have gotten start-background-script event"
);
if (expect.request) {