browser_two_tabs.js (2026B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_PAGE = "https://example.com/document-builder.sjs?html=tab"; 7 8 add_task(async function test_broadcasting_two_tabs_command() { 9 info("Navigate the initial tab to the test URL"); 10 const tab1 = gBrowser.selectedTab; 11 await loadURL(tab1.linkedBrowser, TEST_PAGE); 12 const browsingContext1 = tab1.linkedBrowser.browsingContext; 13 14 info("Open a new tab on the same test URL"); 15 const tab2 = await addTab(TEST_PAGE); 16 const browsingContext2 = tab2.linkedBrowser.browsingContext; 17 18 const rootMessageHandler = createRootMessageHandler( 19 "session-id-broadcasting_two_tabs_command" 20 ); 21 22 const broadcastValue = await sendTestBroadcastCommand( 23 "commandwindowglobalonly", 24 "testBroadcast", 25 {}, 26 contextDescriptorAll, 27 rootMessageHandler 28 ); 29 30 ok( 31 Array.isArray(broadcastValue), 32 "The broadcast returned an array of values" 33 ); 34 35 is(broadcastValue.length, 2, "The broadcast returned 2 values as expected"); 36 37 ok( 38 broadcastValue.includes("broadcast-" + browsingContext1.id), 39 "The broadcast returned the expected value from tab1" 40 ); 41 ok( 42 broadcastValue.includes("broadcast-" + browsingContext2.id), 43 "The broadcast returned the expected value from tab2" 44 ); 45 46 info("Unload the first tab and broadcast again"); 47 await gBrowser.explicitUnloadTabs([tab1]); 48 49 const broadcastAfterUnload = await sendTestBroadcastCommand( 50 "commandwindowglobalonly", 51 "testBroadcast", 52 {}, 53 contextDescriptorAll, 54 rootMessageHandler 55 ); 56 57 ok( 58 Array.isArray(broadcastAfterUnload), 59 "The broadcast (after unload) returned an array of values" 60 ); 61 62 is( 63 broadcastAfterUnload.length, 64 1, 65 "The broadcast (after unload) only returned 1 value" 66 ); 67 68 is( 69 broadcastAfterUnload[0], 70 "broadcast-" + browsingContext2.id, 71 "The broadcast (after unload) returned the expected value from tab2" 72 ); 73 74 rootMessageHandler.destroy(); 75 });