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; return;
} }
primed.pendingEvents.push({ args, resolve, reject }); primed.pendingEvents.push({ args, resolve, reject });
extension.emit("background-page-event"); extension.emit("background-script-event");
}); });
let fire = { let fire = {

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -46,7 +46,7 @@ function promiseExtensionEvent(wrapper, event) {
function trackEvents(wrapper) { function trackEvents(wrapper) {
let events = new Map(); 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); events.set(event, false);
wrapper.extension.once(event, () => events.set(event, true)); 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(2, nonProxiedRequests, "non proxied request ok");
equal( equal(
events.get("background-page-event"), events.get("background-script-event"),
false, 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. // 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"), ExtensionTestUtils.fetch("http://proxied.example.com/?a=1"),
]); ]);
await promiseExtensionEvent(extension, "background-page-event"); await promiseExtensionEvent(extension, "background-script-event");
equal( equal(
events.get("background-page-event"), events.get("background-script-event"),
true, true,
"Should have gotten a background page event" "Should have gotten a background script event"
); );
// Test the background page startup. // Test the background page startup.
equal( equal(
events.get("start-background-page"), events.get("start-background-script"),
false, false,
"Should have gotten a background page event" "Should have gotten a background script event"
); );
Services.obs.notifyObservers(null, "browser-delayed-startup-finished"); Services.obs.notifyObservers(null, "browser-delayed-startup-finished");
await new Promise(executeSoon); await new Promise(executeSoon);
equal( equal(
events.get("start-background-page"), events.get("start-background-script"),
true, true,
"Should have gotten a background page event" "Should have gotten a background script event"
); );
// Verify our proxied request finishes properly and that the // Verify our proxied request finishes properly and that the

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

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