|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test that switching between stack frames properly sets the current debugger |
|
6 * location in the source editor. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
10 |
|
11 let gTab, gDebuggee, gPanel, gDebugger; |
|
12 let gEditor, gSources, gFrames, gClassicFrames; |
|
13 |
|
14 function test() { |
|
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
16 gTab = aTab; |
|
17 gDebuggee = aDebuggee; |
|
18 gPanel = aPanel; |
|
19 gDebugger = gPanel.panelWin; |
|
20 gEditor = gDebugger.DebuggerView.editor; |
|
21 gSources = gDebugger.DebuggerView.Sources; |
|
22 gFrames = gDebugger.DebuggerView.StackFrames; |
|
23 gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList; |
|
24 |
|
25 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
|
26 .then(initialChecks) |
|
27 .then(testNewestTwoFrames) |
|
28 .then(testOldestTwoFrames) |
|
29 .then(testAfterResume) |
|
30 .then(() => closeDebuggerAndFinish(gPanel)) |
|
31 .then(null, aError => { |
|
32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
33 }); |
|
34 |
|
35 gDebuggee.firstCall(); |
|
36 }); |
|
37 } |
|
38 |
|
39 function initialChecks() { |
|
40 is(gDebugger.gThreadClient.state, "paused", |
|
41 "Should only be getting stack frames while paused."); |
|
42 is(gFrames.itemCount, 4, |
|
43 "Should have four frames."); |
|
44 is(gClassicFrames.itemCount, 4, |
|
45 "Should also have four frames in the mirrored view."); |
|
46 } |
|
47 |
|
48 function testNewestTwoFrames() { |
|
49 let deferred = promise.defer(); |
|
50 |
|
51 is(gFrames.selectedIndex, 3, |
|
52 "Newest frame should be selected by default."); |
|
53 is(gClassicFrames.selectedIndex, 0, |
|
54 "Newest frame should be selected in the mirrored view as well."); |
|
55 is(gSources.selectedIndex, 1, |
|
56 "The second source is selected in the widget."); |
|
57 ok(isCaretPos(gPanel, 1), |
|
58 "Editor caret location is correct (1)."); |
|
59 |
|
60 // The editor's debug location takes a tick to update. |
|
61 executeSoon(() => { |
|
62 is(gEditor.getDebugLocation(), 0, |
|
63 "Editor debug location is correct."); |
|
64 |
|
65 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
66 gFrames.getItemAtIndex(2).target, |
|
67 gDebugger); |
|
68 |
|
69 is(gFrames.selectedIndex, 2, |
|
70 "Third frame should be selected after click."); |
|
71 is(gClassicFrames.selectedIndex, 1, |
|
72 "Third frame should be selected in the mirrored view as well."); |
|
73 is(gSources.selectedIndex, 1, |
|
74 "The second source is still selected in the widget."); |
|
75 ok(isCaretPos(gPanel, 6), |
|
76 "Editor caret location is correct (2)."); |
|
77 |
|
78 // The editor's debug location takes a tick to update. |
|
79 executeSoon(() => { |
|
80 is(gEditor.getDebugLocation(), 5, |
|
81 "Editor debug location is correct."); |
|
82 |
|
83 deferred.resolve(); |
|
84 }); |
|
85 }); |
|
86 |
|
87 return deferred.promise; |
|
88 } |
|
89 |
|
90 function testOldestTwoFrames() { |
|
91 let deferred = promise.defer(); |
|
92 |
|
93 waitForSourceAndCaret(gPanel, "-01.js", 1).then(waitForTick).then(() => { |
|
94 is(gFrames.selectedIndex, 1, |
|
95 "Second frame should be selected after click."); |
|
96 is(gClassicFrames.selectedIndex, 2, |
|
97 "Second frame should be selected in the mirrored view as well."); |
|
98 is(gSources.selectedIndex, 0, |
|
99 "The first source is now selected in the widget."); |
|
100 ok(isCaretPos(gPanel, 1), |
|
101 "Editor caret location is correct (3)."); |
|
102 |
|
103 // The editor's debug location takes a tick to update. |
|
104 executeSoon(() => { |
|
105 is(gEditor.getDebugLocation(), 0, |
|
106 "Editor debug location is correct."); |
|
107 |
|
108 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
109 gFrames.getItemAtIndex(0).target, |
|
110 gDebugger); |
|
111 |
|
112 is(gFrames.selectedIndex, 0, |
|
113 "Oldest frame should be selected after click."); |
|
114 is(gClassicFrames.selectedIndex, 3, |
|
115 "Oldest frame should be selected in the mirrored view as well."); |
|
116 is(gSources.selectedIndex, 0, |
|
117 "The first source is still selected in the widget."); |
|
118 ok(isCaretPos(gPanel, 5), |
|
119 "Editor caret location is correct (4)."); |
|
120 |
|
121 // The editor's debug location takes a tick to update. |
|
122 executeSoon(() => { |
|
123 is(gEditor.getDebugLocation(), 4, |
|
124 "Editor debug location is correct."); |
|
125 |
|
126 deferred.resolve(); |
|
127 }); |
|
128 }); |
|
129 }); |
|
130 |
|
131 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
132 gDebugger.document.querySelector("#stackframe-2"), |
|
133 gDebugger); |
|
134 |
|
135 return deferred.promise; |
|
136 } |
|
137 |
|
138 function testAfterResume() { |
|
139 let deferred = promise.defer(); |
|
140 |
|
141 gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => { |
|
142 is(gFrames.itemCount, 0, |
|
143 "Should have no frames after resume."); |
|
144 is(gClassicFrames.itemCount, 0, |
|
145 "Should have no frames in the mirrored view as well."); |
|
146 ok(isCaretPos(gPanel, 5), |
|
147 "Editor caret location is correct after resume."); |
|
148 is(gEditor.getDebugLocation(), null, |
|
149 "Editor debug location is correct after resume."); |
|
150 |
|
151 deferred.resolve(); |
|
152 }, true); |
|
153 |
|
154 gDebugger.gThreadClient.resume(); |
|
155 |
|
156 return deferred.promise; |
|
157 } |
|
158 |
|
159 registerCleanupFunction(function() { |
|
160 gTab = null; |
|
161 gDebuggee = null; |
|
162 gPanel = null; |
|
163 gDebugger = null; |
|
164 gEditor = null; |
|
165 gSources = null; |
|
166 gFrames = null; |
|
167 gClassicFrames = null; |
|
168 }); |
|
169 |