browser_dbg-sourcemaps3.js (4079B)
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 "use strict"; 6 7 // Tests loading sourcemapped sources, setting breakpoints, and 8 // inspecting restored scopes. 9 requestLongerTimeout(2); 10 11 // This source map does not have source contents, so it's fetched separately 12 add_task(async function () { 13 await pushPref("devtools.debugger.map-scopes-enabled", true); 14 // NOTE: the CORS call makes the test run times inconsistent 15 const dbg = await initDebugger( 16 "doc-sourcemaps3.html", 17 "bundle.js", 18 "sorted.js", 19 "test.js" 20 ); 21 22 ok(true, "Original sources exist"); 23 const sortedSrc = findSource(dbg, "sorted.js"); 24 25 await selectSource(dbg, sortedSrc); 26 27 // Test that breakpoint is not off by a line. 28 await addBreakpoint(dbg, sortedSrc, 9, 5); 29 is(dbg.selectors.getBreakpointCount(), 1, "One breakpoint exists"); 30 ok( 31 dbg.selectors.getBreakpoint( 32 createLocation({ source: sortedSrc, line: 9, column: 4 }) 33 ), 34 "Breakpoint has correct line" 35 ); 36 37 invokeInTab("test"); 38 39 await waitForPaused(dbg); 40 await assertPausedAtSourceAndLine(dbg, sortedSrc.id, 9, 5); 41 42 is(getScopeNodeLabel(dbg, 1), "Block"); 43 is(getScopeNodeLabel(dbg, 2), "na"); 44 is(getScopeNodeLabel(dbg, 3), "nb"); 45 46 is(getScopeNodeLabel(dbg, 4), "Function Body"); 47 48 await toggleScopeNode(dbg, 4); 49 50 is(getScopeNodeLabel(dbg, 5), "ma"); 51 is(getScopeNodeLabel(dbg, 6), "mb"); 52 53 await toggleScopeNode(dbg, 7); 54 55 is(getScopeNodeLabel(dbg, 8), "a"); 56 is(getScopeNodeLabel(dbg, 9), "b"); 57 58 is(getScopeNodeLabel(dbg, 10), "Module"); 59 60 await toggleScopeNode(dbg, 10); 61 62 is(getScopeNodeLabel(dbg, 11), "binaryLookup:r(n, o, t)"); 63 is(getScopeNodeLabel(dbg, 12), "comparer:e(n, o)"); 64 is(getScopeNodeLabel(dbg, 13), "fancySort"); 65 66 info("Assert the mapped original frame display names"); 67 68 let frameLabels = getFrameLabels(dbg); 69 // The frame display named are mapped to the original source. 70 // For example "fancySort" method is named "u" in the generated source. 71 Assert.deepEqual(frameLabels, [ 72 "comparer", 73 "binaryLookup", 74 "fancySort", 75 "fancySort", 76 "originalTestName", 77 ]); 78 79 info( 80 "Verify that original function names are displayed in frames on source selection" 81 ); 82 await selectSource(dbg, "test.js"); 83 84 frameLabels = getFrameLabels(dbg); 85 Assert.deepEqual(frameLabels, [ 86 "comparer", 87 "binaryLookup", 88 "fancySort", 89 "fancySort", 90 "originalTestName", // <== this frame was updated 91 ]); 92 await resume(dbg); 93 94 const testSrc = findSource(dbg, "test.js"); 95 96 info("Add breakpoints"); 97 await addBreakpoint(dbg, testSrc, 11); 98 await addBreakpoint(dbg, testSrc, 15); 99 await addBreakpoint(dbg, testSrc, 20); 100 await addBreakpoint(dbg, testSrc, 29); 101 102 invokeInTab("test2"); 103 104 await waitForPaused(dbg); 105 await assertPausedAtSourceAndLine(dbg, testSrc.id, 11); 106 frameLabels = getFrameLabels(dbg); 107 // Note: There seems to be an issue with the frames on the stack, 108 // The expected labels should be ["originalTestName2", "test2"] 109 Assert.deepEqual(frameLabels, ["originalTestName2", "originalTestName2"]); 110 111 await resume(dbg); 112 113 await waitForPaused(dbg); 114 await assertPausedAtSourceAndLine(dbg, testSrc.id, 15); 115 frameLabels = getFrameLabels(dbg); 116 Assert.deepEqual(frameLabels, ["originalTestName3", "originalTestName3"]); 117 118 await resume(dbg); 119 120 await waitForPaused(dbg); 121 await assertPausedAtSourceAndLine(dbg, testSrc.id, 20); 122 frameLabels = getFrameLabels(dbg); 123 Assert.deepEqual(frameLabels, [ 124 "originalTestName4", 125 "run", 126 "run", 127 "originalTestName4", 128 ]); 129 130 await resume(dbg); 131 132 await waitForPaused(dbg); 133 await assertPausedAtSourceAndLine(dbg, testSrc.id, 29); 134 frameLabels = getFrameLabels(dbg); 135 Assert.deepEqual(frameLabels, ["constructor", "test2"]); 136 137 await resume(dbg); 138 }); 139 140 function getFrameLabels(dbg) { 141 return [ 142 ...findAllElementsWithSelector(dbg, ".pane.frames .frame .title"), 143 ].map(el => el.textContent); 144 }