browser_console_devtools_loader_exception.js (3022B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Check that exceptions from scripts loaded with the DevTools loader are 5 // opened correctly in View Source from the Browser Console. 6 7 "use strict"; 8 9 const TEST_URI = 10 "data:text/html;charset=utf8,<!DOCTYPE html><p>browser_console_devtools_loader_exception.js</p>"; 11 12 add_task(async function () { 13 // Disable the preloaded process as it creates processes intermittently 14 // which forces the emission of RDP requests we aren't correctly waiting for. 15 await pushPref("dom.ipc.processPrelaunch.enabled", false); 16 await pushPref("devtools.browsertoolbox.scope", "everything"); 17 18 const wcHud = await openNewTabAndConsole(TEST_URI); 19 ok(wcHud, "web console opened"); 20 21 const bcHud = await BrowserConsoleManager.toggleBrowserConsole(); 22 ok(bcHud, "browser console opened"); 23 24 // Cause an exception in a script loaded with the DevTools loader. 25 const toolbox = wcHud.toolbox; 26 const oldPanels = toolbox._toolPanels; 27 // non-iterable 28 toolbox._toolPanels = {}; 29 30 function fixToolbox() { 31 toolbox._toolPanels = oldPanels; 32 } 33 34 info("generate exception and wait for message"); 35 36 executeSoon(() => { 37 expectUncaughtException(); 38 executeSoon(fixToolbox); 39 toolbox.getToolPanels(); 40 }); 41 42 const msg = await waitFor(() => 43 findErrorMessage(bcHud, "TypeError: this._toolPanels is not iterable") 44 ); 45 46 fixToolbox(); 47 48 ok(msg, `Message found: "TypeError: this._toolPanels is not iterable"`); 49 50 const locationNode = msg.querySelector( 51 ".message-location .frame-link-source" 52 ); 53 ok(locationNode, "Message location link element found"); 54 55 const url = locationNode.href; 56 info("view-source url: " + url); 57 ok(url, "we have some source URL after the click"); 58 ok(url.includes("toolbox.js"), "we have the expected view source URL"); 59 ok(!url.includes("->"), "no -> in the URL given to view-source"); 60 61 const { targetCommand } = bcHud.commands; 62 // If Fission is not enabled for the Browser Console (e.g. in Beta at this moment), 63 // the target list won't watch for Frame targets, and as a result we won't have issues 64 // with pending connections to the server that we're observing when attaching the target. 65 const onViewSourceTargetAvailable = new Promise(resolve => { 66 const onAvailable = ({ targetFront }) => { 67 if (targetFront.url.includes("view-source:")) { 68 targetCommand.unwatchTargets({ 69 types: [targetCommand.TYPES.FRAME], 70 onAvailable, 71 }); 72 resolve(); 73 } 74 }; 75 targetCommand.watchTargets({ 76 types: [targetCommand.TYPES.FRAME], 77 onAvailable, 78 }); 79 }); 80 81 const onTabOpen = BrowserTestUtils.waitForNewTab( 82 gBrowser, 83 tabUrl => tabUrl.startsWith("view-source:"), 84 true 85 ); 86 locationNode.click(); 87 88 await onTabOpen; 89 ok(true, "The view source tab was opened in response to clicking the link"); 90 91 info("Wait for the frame target to be available"); 92 await onViewSourceTargetAvailable; 93 });