browser_dbg-javascript-tracer-sidebar-panel.js (3806B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 // Tests the Javascript Tracing feature. 6 7 "use strict"; 8 9 add_task(async function () { 10 const dbg = await initDebugger("doc-scripts.html"); 11 12 info("Force the log method to be the debugger sidebar"); 13 await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-debugger-sidebar"); 14 15 info("Enable values recording"); 16 await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-log-values"); 17 18 info("Enable the tracing"); 19 await toggleJsTracer(dbg.toolbox); 20 21 const topLevelThreadActorID = 22 dbg.toolbox.commands.targetCommand.targetFront.threadFront.actorID; 23 info("Wait for tracing to be enabled"); 24 await waitForState(dbg, () => { 25 return dbg.selectors.getIsThreadCurrentlyTracing(topLevelThreadActorID); 26 }); 27 28 invokeInTab("main"); 29 invokeInTab("simple"); 30 31 info("Wait for the call tree to appear in the tracer panel"); 32 const tracerTree = await waitForElementWithSelector( 33 dbg, 34 "#tracer-tab-panel .tree" 35 ); 36 37 info("Wait for the expected traces to appear in the call tree"); 38 const traces = await waitFor(() => { 39 const elements = tracerTree.querySelectorAll(".trace-line"); 40 if (elements.length == 6) { 41 return elements; 42 } 43 return false; 44 }); 45 is(traces[0].textContent, "λ main simple1.js:1:17"); 46 is(traces[1].textContent, "λ foo simple2.js:1:13"); 47 is(traces[2].textContent, "λ bar simple2.js:3:5"); 48 is(traces[3].textContent, "λ simple simple3.js:1:19"); 49 is(traces[4].textContent, "λ foo simple2.js:1:13"); 50 is(traces[5].textContent, "λ bar simple2.js:3:5"); 51 52 info("Select the trace for the call to `foo`"); 53 EventUtils.synthesizeMouseAtCenter(traces[1], {}, dbg.win); 54 55 const focusedTrace = await waitFor( 56 () => tracerTree.querySelector(".tree-node.focused .trace-line"), 57 "Wait for the line to be focused in the tracer panel" 58 ); 59 is(focusedTrace, traces[1], "The clicked trace is now focused"); 60 await waitFor( 61 () => findElement(dbg, "tracedLine"), 62 "Wait for the traced line to be highlighted in CodeMirror" 63 ); 64 const tracePanel = await waitFor(() => findElement(dbg, "tracePanel")); 65 ok(tracePanel, "The trace panel is shown on trace selection"); 66 const tracePanelItems = tracePanel.querySelectorAll(".trace-item"); 67 is( 68 tracePanelItems.length, 69 2, 70 "There is two calls to foo() reported in the trace panel" 71 ); 72 ok( 73 tracePanelItems[0].classList.contains("selected"), 74 "The first item is selected, this is the first call to foo()" 75 ); 76 77 await assertInlinePreviews( 78 dbg, 79 [ 80 { 81 previews: [ 82 { identifier: "x:", value: "1" }, 83 { identifier: "y:", value: "2" }, 84 ], 85 line: 1, 86 }, 87 ], 88 "foo" 89 ); 90 91 info("Click on the second trace item"); 92 tracePanelItems[1].click(); 93 94 await waitFor( 95 () => 96 tracerTree.querySelector(".tree-node.focused .trace-line") == traces[4], 97 "Wait for the focused trace in the tree to become the second call to foo()" 98 ); 99 100 await assertInlinePreviews( 101 dbg, 102 [ 103 { 104 previews: [ 105 { identifier: "x:", value: "3" }, 106 { identifier: "y:", value: "4" }, 107 ], 108 line: 1, 109 }, 110 ], 111 "foo" 112 ); 113 114 // Test Disabling tracing 115 info("Disable the tracing"); 116 await toggleJsTracer(dbg.toolbox); 117 info("Wait for tracing to be disabled"); 118 await waitForState(dbg, () => { 119 return !dbg.selectors.getIsThreadCurrentlyTracing(topLevelThreadActorID); 120 }); 121 122 info("Reset back to the default value"); 123 await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-console"); 124 await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-log-values"); 125 });