browser_windowglobal_to_root.js (1369B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { RootMessageHandler } = ChromeUtils.importESModule( 7 "chrome://remote/content/shared/messagehandler/RootMessageHandler.sys.mjs" 8 ); 9 10 add_task(async function test_windowGlobal_to_root_command() { 11 // Navigate to a page to make sure that the windowglobal modules run in a 12 // different process than the root module. 13 const tab = BrowserTestUtils.addTab( 14 gBrowser, 15 "https://example.com/document-builder.sjs?html=tab" 16 ); 17 await BrowserTestUtils.browserLoaded(tab.linkedBrowser); 18 const browsingContextId = tab.linkedBrowser.browsingContext.id; 19 20 const rootMessageHandler = createRootMessageHandler( 21 "session-id-windowglobal-to-rootModule" 22 ); 23 24 for (const commandName of [ 25 "testHandleCommandToRoot", 26 "testSendRootCommand", 27 ]) { 28 const valueFromRoot = await rootMessageHandler.handleCommand({ 29 moduleName: "windowglobaltoroot", 30 commandName, 31 destination: { 32 type: WindowGlobalMessageHandler.type, 33 id: browsingContextId, 34 }, 35 }); 36 37 is( 38 valueFromRoot, 39 "root-value-called-from-windowglobal", 40 "Retrieved the expected value from windowglobaltoroot using " + 41 commandName 42 ); 43 } 44 45 rootMessageHandler.destroy(); 46 gBrowser.removeTab(tab); 47 });