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