browser_jsterm_inspect_panels.js (2922B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Check that the inspect() jsterm helper function works. 5 6 "use strict"; 7 8 const TEST_URI = 9 "https://example.com/browser/devtools/client/webconsole/test/browser/" + 10 "test-simple-function.html"; 11 12 add_task(async function () { 13 const hud = await openNewTabAndConsole(TEST_URI); 14 15 await testInspectingElement(hud); 16 await testInspectingFunction(hud); 17 }); 18 19 async function testInspectingElement(hud) { 20 info("Test `inspect(el)`"); 21 execute(hud, "inspect(document.querySelector('p'))"); 22 await waitForSelectedElementInInspector(hud.toolbox, "p"); 23 ok(true, "inspected element is now selected in the inspector"); 24 25 info( 26 "Test that inspect selects the node in the inspector in the split console as well" 27 ); 28 const onSplitConsoleReady = hud.toolbox.once("split-console"); 29 EventUtils.sendKey("ESCAPE", hud.toolbox.win); 30 await onSplitConsoleReady; 31 32 execute(hud, "inspect(document.querySelector('body'))"); 33 await waitForSelectedElementInInspector(hud.toolbox, "body"); 34 ok(true, "the inspected element is selected in the inspector"); 35 } 36 37 async function testInspectingFunction(hud) { 38 info("Test `inspect(test)`"); 39 execute(hud, "inspect(test)"); 40 await waitFor(expectedSourceSelected("test-simple-function.js", 3)); 41 ok(true, "inspected function is now selected in the debugger"); 42 43 info("Test `inspect(test_mangled)`"); 44 execute(hud, "inspect(test_mangled)"); 45 await waitFor(expectedSourceSelected("test-mangled-function.js", 3, true)); 46 ok(true, "inspected source-mapped function is now selected in the debugger"); 47 48 info("Test `inspect(test_bound)`"); 49 execute(hud, "inspect(test_bound)"); 50 await waitFor(expectedSourceSelected("test-simple-function.js", 7)); 51 ok(true, "inspected bound target function is now selected in the debugger"); 52 53 function expectedSourceSelected( 54 sourceFilename, 55 sourceLine, 56 isOriginalSource 57 ) { 58 return () => { 59 const dbg = hud.toolbox.getPanel("jsdebugger"); 60 if (!dbg) { 61 return false; 62 } 63 64 const selectedLocation = dbg._selectors.getSelectedLocation( 65 dbg._getState() 66 ); 67 68 if (!selectedLocation) { 69 return false; 70 } 71 72 if ( 73 isOriginalSource && 74 !selectedLocation.source.id.includes("/originalSource-") 75 ) { 76 return false; 77 } 78 79 return ( 80 selectedLocation.source.id.includes(sourceFilename) && 81 selectedLocation.line == sourceLine 82 ); 83 }; 84 } 85 } 86 87 async function waitForSelectedElementInInspector(toolbox, displayName) { 88 return waitFor(() => { 89 const inspector = toolbox.getPanel("inspector"); 90 if (!inspector) { 91 return false; 92 } 93 94 const selection = inspector.selection; 95 return ( 96 selection && 97 selection.nodeFront && 98 selection.nodeFront.displayName == displayName 99 ); 100 }); 101 }