retry.sys.mjs (1525B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; 6 7 const lazy = {}; 8 9 ChromeUtils.defineESModuleGetters(lazy, { 10 WindowGlobalMessageHandler: 11 "chrome://remote/content/shared/messagehandler/WindowGlobalMessageHandler.sys.mjs", 12 }); 13 14 // The test is supposed to trigger the command and then destroy the 15 // JSWindowActor pair by any mean (eg a navigation) in order to trigger an 16 // AbortError and a retry. 17 class RetryModule extends Module { 18 destroy() {} 19 20 /** 21 * Commands 22 */ 23 24 async waitForDiscardedBrowsingContext(params = {}) { 25 const { browsingContext, retryOnAbort } = params; 26 27 // Wait for the browsing context to be discarded (replaced or destroyed) 28 // before calling the internal command. 29 await new Promise(resolve => { 30 const observe = (_subject, _topic, _data) => { 31 Services.obs.removeObserver(observe, "browsing-context-discarded"); 32 resolve(); 33 }; 34 Services.obs.addObserver(observe, "browsing-context-discarded"); 35 }); 36 37 return this.messageHandler.forwardCommand({ 38 moduleName: "retry", 39 commandName: "_internalForward", 40 destination: { 41 type: lazy.WindowGlobalMessageHandler.type, 42 id: browsingContext.id, 43 }, 44 retryOnAbort, 45 }); 46 } 47 } 48 49 export const retry = RetryModule;