browser_events_handler.js (1836B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Test that the window-global-handler-created event gets emitted for each 8 * individual frame's browsing context. 9 */ 10 add_task(async function test_windowGlobalHandlerCreated() { 11 const events = []; 12 13 const rootMessageHandler = createRootMessageHandler( 14 "session-id-event_with_frames" 15 ); 16 17 info("Add a new session data item to get window global handlers created"); 18 await rootMessageHandler.addSessionDataItem({ 19 moduleName: "command", 20 category: "browser_session_data_browser_element", 21 contextDescriptor: { 22 type: ContextDescriptorType.All, 23 }, 24 values: [true], 25 }); 26 27 const onEvent = (evtName, wrappedEvt) => { 28 if (wrappedEvt.name === "window-global-handler-created") { 29 console.info(`Received event for context ${wrappedEvt.data.contextId}`); 30 events.push(wrappedEvt.data); 31 } 32 }; 33 rootMessageHandler.on("message-handler-event", onEvent); 34 35 info("Navigate the initial tab to the test URL"); 36 const browser = gBrowser.selectedTab.linkedBrowser; 37 await loadURL(browser, createTestMarkupWithFrames()); 38 39 const contexts = browser.browsingContext.getAllBrowsingContextsInSubtree(); 40 is(contexts.length, 4, "Test tab has 3 children contexts (4 in total)"); 41 42 // Wait for all the events 43 await TestUtils.waitForCondition(() => events.length >= 4); 44 45 for (const context of contexts) { 46 const contextEvents = events.filter(evt => { 47 return ( 48 evt.contextId === context.id && 49 evt.innerWindowId === context.currentWindowGlobal.innerWindowId 50 ); 51 }); 52 is(contextEvents.length, 1, `Found event for context ${context.id}`); 53 } 54 55 rootMessageHandler.off("message-handler-event", onEvent); 56 rootMessageHandler.destroy(); 57 });