Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Test that we can set breakpoints and step through source mapped |
michael@0 | 6 | * coffee script. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_binary_search.html"; |
michael@0 | 10 | const COFFEE_URL = EXAMPLE_URL + "code_binary_search.coffee"; |
michael@0 | 11 | |
michael@0 | 12 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 13 | let gEditor, gSources; |
michael@0 | 14 | |
michael@0 | 15 | function test() { |
michael@0 | 16 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 17 | gTab = aTab; |
michael@0 | 18 | gDebuggee = aDebuggee; |
michael@0 | 19 | gPanel = aPanel; |
michael@0 | 20 | gDebugger = gPanel.panelWin; |
michael@0 | 21 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 22 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 23 | |
michael@0 | 24 | checkSourceMapsEnabled(); |
michael@0 | 25 | |
michael@0 | 26 | waitForSourceShown(gPanel, ".coffee") |
michael@0 | 27 | .then(checkInitialSource) |
michael@0 | 28 | .then(testSetBreakpoint) |
michael@0 | 29 | .then(testSetBreakpointBlankLine) |
michael@0 | 30 | .then(testHitBreakpoint) |
michael@0 | 31 | .then(testStepping) |
michael@0 | 32 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 33 | .then(null, aError => { |
michael@0 | 34 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 35 | }); |
michael@0 | 36 | }); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function checkSourceMapsEnabled() { |
michael@0 | 40 | is(Services.prefs.getBoolPref("devtools.debugger.source-maps-enabled"), true, |
michael@0 | 41 | "The source maps functionality should be enabled by default."); |
michael@0 | 42 | is(gDebugger.Prefs.sourceMapsEnabled, true, |
michael@0 | 43 | "The source maps pref should be true from startup."); |
michael@0 | 44 | is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"), "true", |
michael@0 | 45 | "Source maps should be enabled from startup.") |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function checkInitialSource() { |
michael@0 | 49 | isnot(gSources.selectedValue.indexOf(".coffee"), -1, |
michael@0 | 50 | "The debugger should show the source mapped coffee source file."); |
michael@0 | 51 | is(gSources.selectedValue.indexOf(".js"), -1, |
michael@0 | 52 | "The debugger should not show the generated js source file."); |
michael@0 | 53 | is(gEditor.getText().indexOf("isnt"), 218, |
michael@0 | 54 | "The debugger's editor should have the coffee source source displayed."); |
michael@0 | 55 | is(gEditor.getText().indexOf("function"), -1, |
michael@0 | 56 | "The debugger's editor should not have the JS source displayed."); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function testSetBreakpoint() { |
michael@0 | 60 | let deferred = promise.defer(); |
michael@0 | 61 | |
michael@0 | 62 | gDebugger.gThreadClient.interrupt(aResponse => { |
michael@0 | 63 | gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 5 }, aResponse => { |
michael@0 | 64 | ok(!aResponse.error, |
michael@0 | 65 | "Should be able to set a breakpoint in a coffee source file."); |
michael@0 | 66 | ok(!aResponse.actualLocation, |
michael@0 | 67 | "Should be able to set a breakpoint on line 5."); |
michael@0 | 68 | |
michael@0 | 69 | deferred.resolve(); |
michael@0 | 70 | }); |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | return deferred.promise; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function testSetBreakpointBlankLine() { |
michael@0 | 77 | let deferred = promise.defer(); |
michael@0 | 78 | |
michael@0 | 79 | gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 3 }, aResponse => { |
michael@0 | 80 | ok(!aResponse.error, |
michael@0 | 81 | "Should be able to set a breakpoint in a coffee source file on a blank line."); |
michael@0 | 82 | ok(aResponse.actualLocation, |
michael@0 | 83 | "Because 3 is empty, we should have an actualLocation."); |
michael@0 | 84 | is(aResponse.actualLocation.url, COFFEE_URL, |
michael@0 | 85 | "actualLocation.url should be source mapped to the coffee file."); |
michael@0 | 86 | is(aResponse.actualLocation.line, 2, |
michael@0 | 87 | "actualLocation.line should be source mapped back to 2."); |
michael@0 | 88 | |
michael@0 | 89 | deferred.resolve(); |
michael@0 | 90 | }); |
michael@0 | 91 | |
michael@0 | 92 | return deferred.promise; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function testHitBreakpoint() { |
michael@0 | 96 | let deferred = promise.defer(); |
michael@0 | 97 | |
michael@0 | 98 | gDebugger.gThreadClient.resume(aResponse => { |
michael@0 | 99 | ok(!aResponse.error, "Shouldn't get an error resuming."); |
michael@0 | 100 | is(aResponse.type, "resumed", "Type should be 'resumed'."); |
michael@0 | 101 | |
michael@0 | 102 | gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
michael@0 | 103 | is(aPacket.type, "paused", |
michael@0 | 104 | "We should now be paused again."); |
michael@0 | 105 | is(aPacket.why.type, "breakpoint", |
michael@0 | 106 | "and the reason we should be paused is because we hit a breakpoint."); |
michael@0 | 107 | |
michael@0 | 108 | // Check that we stopped at the right place, by making sure that the |
michael@0 | 109 | // environment is in the state that we expect. |
michael@0 | 110 | is(aPacket.frame.environment.bindings.variables.start.value, 0, |
michael@0 | 111 | "'start' is 0."); |
michael@0 | 112 | is(aPacket.frame.environment.bindings.variables.stop.value.type, "undefined", |
michael@0 | 113 | "'stop' hasn't been assigned to yet."); |
michael@0 | 114 | is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined", |
michael@0 | 115 | "'pivot' hasn't been assigned to yet."); |
michael@0 | 116 | |
michael@0 | 117 | waitForCaretUpdated(gPanel, 5).then(deferred.resolve); |
michael@0 | 118 | }); |
michael@0 | 119 | |
michael@0 | 120 | // This will cause the breakpoint to be hit, and put us back in the |
michael@0 | 121 | // paused state. |
michael@0 | 122 | gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5); |
michael@0 | 123 | }); |
michael@0 | 124 | |
michael@0 | 125 | return deferred.promise; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function testStepping() { |
michael@0 | 129 | let deferred = promise.defer(); |
michael@0 | 130 | |
michael@0 | 131 | gDebugger.gThreadClient.stepIn(aResponse => { |
michael@0 | 132 | ok(!aResponse.error, "Shouldn't get an error resuming."); |
michael@0 | 133 | is(aResponse.type, "resumed", "Type should be 'resumed'."); |
michael@0 | 134 | |
michael@0 | 135 | // After stepping, we will pause again, so listen for that. |
michael@0 | 136 | gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
michael@0 | 137 | is(aPacket.type, "paused", |
michael@0 | 138 | "We should now be paused again."); |
michael@0 | 139 | is(aPacket.why.type, "resumeLimit", |
michael@0 | 140 | "and the reason we should be paused is because we hit the resume limit."); |
michael@0 | 141 | |
michael@0 | 142 | // Check that we stopped at the right place, by making sure that the |
michael@0 | 143 | // environment is in the state that we expect. |
michael@0 | 144 | is(aPacket.frame.environment.bindings.variables.start.value, 0, |
michael@0 | 145 | "'start' is 0."); |
michael@0 | 146 | is(aPacket.frame.environment.bindings.variables.stop.value, 5, |
michael@0 | 147 | "'stop' hasn't been assigned to yet."); |
michael@0 | 148 | is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined", |
michael@0 | 149 | "'pivot' hasn't been assigned to yet."); |
michael@0 | 150 | |
michael@0 | 151 | waitForCaretUpdated(gPanel, 6).then(deferred.resolve); |
michael@0 | 152 | }); |
michael@0 | 153 | }); |
michael@0 | 154 | |
michael@0 | 155 | return deferred.promise; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | registerCleanupFunction(function() { |
michael@0 | 159 | gTab = null; |
michael@0 | 160 | gDebuggee = null; |
michael@0 | 161 | gPanel = null; |
michael@0 | 162 | gDebugger = null; |
michael@0 | 163 | gEditor = null; |
michael@0 | 164 | gSources = null; |
michael@0 | 165 | }); |