Bug 1672390, remove message manager use from about debugging tests, r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D94666
This commit is contained in:
Neil Deakin 2020-10-27 00:26:33 +00:00
Родитель 851cf6f453
Коммит a1982d3e68
3 изменённых файлов: 16 добавлений и 35 удалений

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

@ -24,13 +24,10 @@ add_task(async function() {
// Open a tab that registers a push service worker.
const swTab = await addTab(TAB_URL);
info("Forward service worker messages to the test");
await forwardServiceWorkerMessage(swTab);
info(
"Wait for the service worker to claim the test window before proceeding."
);
await onTabMessage(swTab, "sw-claimed");
await onServiceWorkerMessage(swTab, "sw-claimed");
info("Wait until the service worker appears and is running");
const targetElement = await waitForServiceWorkerRunning(
@ -43,7 +40,7 @@ add_task(async function() {
ok(pushButton, "Found its push button");
info("Click on the Push button and wait for the push notification");
const onPushNotification = onTabMessage(swTab, "sw-pushed");
const onPushNotification = onServiceWorkerMessage(swTab, "sw-pushed");
pushButton.click();
await onPushNotification;

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

@ -30,13 +30,10 @@ add_task(async function() {
// Open a tab that registers a push service worker.
const swTab = await addTab(TAB_URL);
info("Forward service worker messages to the test");
await forwardServiceWorkerMessage(swTab);
info(
"Wait for the service worker to claim the test window before proceeding."
);
await onTabMessage(swTab, "sw-claimed");
await onServiceWorkerMessage(swTab, "sw-claimed");
info("Wait until the service worker appears and is running");
const targetElement = await waitForServiceWorkerRunning(

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

@ -29,16 +29,22 @@ async function enableServiceWorkerDebugging() {
* @param {String} message
* The name of the expected message.
*/
function onTabMessage(tab, message) {
const mm = tab.linkedBrowser.messageManager;
return new Promise(resolve => {
mm.addMessageListener(message, function listener() {
mm.removeMessageListener(message, listener);
resolve();
function onServiceWorkerMessage(tab, message) {
info("Make the test page notify us when the service worker sends a message.");
return SpecialPowers.spawn(tab.linkedBrowser, [message], function(
messageChild
) {
return new Promise(resolve => {
const win = content.wrappedJSObject;
win.navigator.serviceWorker.addEventListener("message", function(event) {
if (event.data == messageChild) {
resolve();
}
});
});
});
}
/* exported onTabMessage */
/* exported onServiceWorkerMessage */
async function _waitForServiceWorkerStatus(workerText, status, document) {
await waitUntil(() => {
@ -77,25 +83,6 @@ async function waitForRegistration(tab) {
}
/* exported waitForRegistration */
/**
* Helper to listen once on a message sent using postMessage from the provided tab.
*
* @param {Tab} tab
* The tab on which the message will be received.
* @param {String} message
* The name of the expected message.
*/
function forwardServiceWorkerMessage(tab) {
info("Make the test page notify us when the service worker sends a message.");
return ContentTask.spawn(tab.linkedBrowser, {}, function() {
const win = content.wrappedJSObject;
win.navigator.serviceWorker.addEventListener("message", function(event) {
sendAsyncMessage(event.data);
});
});
}
/* exported forwardServiceWorkerMessage */
/**
* Unregister the service worker from the content page. The content page should define
* `getRegistration` to allow this helper to retrieve the service worker registration that