browser_browser_toolbox_navigate_tab.js (2993B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // There are shutdown issues for which multiple rejections are left uncaught. 5 // See bug 1018184 for resolving these issues. 6 const { PromiseTestUtils } = ChromeUtils.importESModule( 7 "resource://testing-common/PromiseTestUtils.sys.mjs" 8 ); 9 PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/); 10 11 Services.scriptloader.loadSubScript( 12 "chrome://mochitests/content/browser/devtools/client/inspector/test/shared-head.js", 13 this 14 ); 15 16 // On debug test machine, it takes about 50s to run the test. 17 requestLongerTimeout(4); 18 19 // Test that the Browser Toolbox still works after navigating a content tab 20 add_task(async function () { 21 // Forces the Browser Toolbox to open on the inspector by default 22 await pushPref("devtools.browsertoolbox.panel", "inspector"); 23 24 await testNavigate("everything"); 25 await testNavigate("parent-process"); 26 }); 27 28 async function testNavigate(browserToolboxScope) { 29 await pushPref("devtools.browsertoolbox.scope", browserToolboxScope); 30 31 const tab = await addTab( 32 `data:text/html,<div>NAVIGATE TEST - BEFORE: ${browserToolboxScope}</div>` 33 ); 34 // Set the scope on the browser element to assert it easily in the Toolbox 35 // task. 36 tab.linkedBrowser.setAttribute("data-test-scope", browserToolboxScope); 37 38 const ToolboxTask = await initBrowserToolboxTask(); 39 await ToolboxTask.importFunctions({ 40 getNodeFront, 41 selectNode, 42 }); 43 44 const hasBrowserContainerTask = async ({ scope, hasNavigated }) => { 45 /* global gToolbox */ 46 const inspector = await gToolbox.selectTool("inspector"); 47 info("Select the test browser element in the inspector"); 48 let selector = `browser[data-test-scope="${scope}"]`; 49 if (hasNavigated) { 50 selector += `[navigated="true"]`; 51 } 52 const nodeFront = await getNodeFront(selector, inspector); 53 await selectNode(nodeFront, inspector); 54 const browserContainer = inspector.markup.getContainer(nodeFront); 55 return !!browserContainer; 56 }; 57 58 info("Select the test browser in the Browser Toolbox (before navigation)"); 59 const hasContainerBeforeNavigation = await ToolboxTask.spawn( 60 { scope: browserToolboxScope, hasNavigated: false }, 61 hasBrowserContainerTask 62 ); 63 ok( 64 hasContainerBeforeNavigation, 65 "Found a valid container for the browser element before navigation" 66 ); 67 68 info("Navigate the test tab to another data-uri"); 69 await navigateTo( 70 `data:text/html,<div>NAVIGATE TEST - AFTER: ${browserToolboxScope}</div>` 71 ); 72 tab.linkedBrowser.setAttribute("navigated", "true"); 73 74 info("Select the test browser in the Browser Toolbox (after navigation)"); 75 const hasContainerAfterNavigation = await ToolboxTask.spawn( 76 { scope: browserToolboxScope, hasNavigated: true }, 77 hasBrowserContainerTask 78 ); 79 ok( 80 hasContainerAfterNavigation, 81 "Found a valid container for the browser element after navigation" 82 ); 83 84 await ToolboxTask.destroy(); 85 }