|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that switching the displayed source in the UI works as advertised. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-02.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gEditor, gSources; |
|
12 |
|
13 function test() { |
|
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
15 gTab = aTab; |
|
16 gDebuggee = aDebuggee; |
|
17 gPanel = aPanel; |
|
18 gDebugger = gPanel.panelWin; |
|
19 gEditor = gDebugger.DebuggerView.editor; |
|
20 gSources = gDebugger.DebuggerView.Sources; |
|
21 |
|
22 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
|
23 .then(testSourcesDisplay) |
|
24 .then(testSwitchPaused1) |
|
25 .then(testSwitchPaused2) |
|
26 .then(testSwitchRunning) |
|
27 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
28 .then(null, aError => { |
|
29 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
30 }); |
|
31 |
|
32 gDebuggee.firstCall(); |
|
33 }); |
|
34 } |
|
35 |
|
36 let gLabel1 = "code_script-switching-01.js"; |
|
37 let gLabel2 = "code_script-switching-02.js"; |
|
38 let gParams = "?foo=bar,baz|lol"; |
|
39 |
|
40 function testSourcesDisplay() { |
|
41 let deferred = promise.defer(); |
|
42 |
|
43 is(gSources.itemCount, 2, |
|
44 "Found the expected number of sources."); |
|
45 |
|
46 ok(gSources.containsValue(EXAMPLE_URL + gLabel1), |
|
47 "First source url is incorrect."); |
|
48 ok(gSources.containsValue(EXAMPLE_URL + gLabel2 + gParams), |
|
49 "Second source url is incorrect."); |
|
50 |
|
51 ok(gSources.getItemForAttachment(e => e.label == gLabel1), |
|
52 "First source label is incorrect."); |
|
53 ok(gSources.getItemForAttachment(e => e.label == gLabel2), |
|
54 "Second source label is incorrect."); |
|
55 |
|
56 ok(gSources.selectedItem, |
|
57 "There should be a selected item in the sources pane."); |
|
58 is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams, |
|
59 "The selected value is the sources pane is incorrect."); |
|
60 |
|
61 is(gEditor.getText().search(/firstCall/), -1, |
|
62 "The first source is not displayed."); |
|
63 is(gEditor.getText().search(/debugger/), 172, |
|
64 "The second source is displayed."); |
|
65 |
|
66 ok(isCaretPos(gPanel, 1), |
|
67 "Editor caret location is correct."); |
|
68 |
|
69 // The editor's debug location takes a tick to update. |
|
70 executeSoon(() => { |
|
71 is(gEditor.getDebugLocation(), 0, |
|
72 "Editor debugger location is correct."); |
|
73 ok(gEditor.hasLineClass(0, "debug-line"), |
|
74 "The debugged line is highlighted appropriately."); |
|
75 |
|
76 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); |
|
77 gSources.selectedItem = e => e.attachment.label == gLabel1; |
|
78 }); |
|
79 |
|
80 return deferred.promise; |
|
81 } |
|
82 |
|
83 function testSwitchPaused1() { |
|
84 let deferred = promise.defer(); |
|
85 |
|
86 ok(gSources.selectedItem, |
|
87 "There should be a selected item in the sources pane."); |
|
88 is(gSources.selectedValue, EXAMPLE_URL + gLabel1, |
|
89 "The selected value is the sources pane is incorrect."); |
|
90 |
|
91 is(gEditor.getText().search(/firstCall/), 118, |
|
92 "The first source is displayed."); |
|
93 is(gEditor.getText().search(/debugger/), -1, |
|
94 "The second source is not displayed."); |
|
95 |
|
96 // The editor's debug location takes a tick to update. |
|
97 executeSoon(() => { |
|
98 ok(isCaretPos(gPanel, 1), |
|
99 "Editor caret location is correct."); |
|
100 |
|
101 is(gEditor.getDebugLocation(), null, |
|
102 "Editor debugger location is correct."); |
|
103 ok(!gEditor.hasLineClass(5, "debug-line"), |
|
104 "The debugged line highlight was removed."); |
|
105 |
|
106 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); |
|
107 gSources.selectedItem = e => e.attachment.label == gLabel2; |
|
108 }); |
|
109 |
|
110 return deferred.promise; |
|
111 } |
|
112 |
|
113 function testSwitchPaused2() { |
|
114 let deferred = promise.defer(); |
|
115 |
|
116 ok(gSources.selectedItem, |
|
117 "There should be a selected item in the sources pane."); |
|
118 is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams, |
|
119 "The selected value is the sources pane is incorrect."); |
|
120 |
|
121 is(gEditor.getText().search(/firstCall/), -1, |
|
122 "The first source is not displayed."); |
|
123 is(gEditor.getText().search(/debugger/), 172, |
|
124 "The second source is displayed."); |
|
125 |
|
126 // The editor's debug location takes a tick to update. |
|
127 executeSoon(() => { |
|
128 ok(isCaretPos(gPanel, 1), |
|
129 "Editor caret location is correct."); |
|
130 is(gEditor.getDebugLocation(), 0, |
|
131 "Editor debugger location is correct."); |
|
132 ok(gEditor.hasLineClass(0, "debug-line"), |
|
133 "The debugged line is highlighted appropriately."); |
|
134 |
|
135 // Step out three times. |
|
136 waitForThreadEvents(gPanel, "paused").then(() => { |
|
137 waitForThreadEvents(gPanel, "paused").then(() => { |
|
138 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve); |
|
139 gDebugger.gThreadClient.stepOut(); |
|
140 }); |
|
141 gDebugger.gThreadClient.stepOut(); |
|
142 }); |
|
143 gDebugger.gThreadClient.stepOut(); |
|
144 }); |
|
145 |
|
146 return deferred.promise; |
|
147 } |
|
148 |
|
149 function testSwitchRunning() { |
|
150 let deferred = promise.defer(); |
|
151 |
|
152 ok(gSources.selectedItem, |
|
153 "There should be a selected item in the sources pane."); |
|
154 is(gSources.selectedValue, EXAMPLE_URL + gLabel1, |
|
155 "The selected value is the sources pane is incorrect."); |
|
156 |
|
157 is(gEditor.getText().search(/firstCall/), 118, |
|
158 "The first source is displayed."); |
|
159 is(gEditor.getText().search(/debugger/), -1, |
|
160 "The second source is not displayed."); |
|
161 |
|
162 // The editor's debug location takes a tick to update. |
|
163 executeSoon(() => { |
|
164 ok(isCaretPos(gPanel, 1), |
|
165 "Editor caret location is correct."); |
|
166 is(gEditor.getDebugLocation(), 0, |
|
167 "Editor debugger location is correct."); |
|
168 ok(gEditor.hasLineClass(0, "debug-line"), |
|
169 "The debugged line is highlighted appropriately."); |
|
170 |
|
171 deferred.resolve(); |
|
172 }); |
|
173 |
|
174 return deferred.promise; |
|
175 } |
|
176 |
|
177 registerCleanupFunction(function() { |
|
178 gTab = null; |
|
179 gDebuggee = null; |
|
180 gPanel = null; |
|
181 gDebugger = null; |
|
182 gEditor = null; |
|
183 gSources = null; |
|
184 gLabel1 = null; |
|
185 gLabel2 = null; |
|
186 gParams = null; |
|
187 }); |