|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that after selecting a different stack frame, resuming reselects |
|
6 * the topmost stackframe, loads the right source in the editor pane and |
|
7 * highlights the proper line. |
|
8 */ |
|
9 |
|
10 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
11 |
|
12 let gTab, gDebuggee, gPanel, gDebugger; |
|
13 let gEditor, gSources, gFrames, gClassicFrames, gToolbar; |
|
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 gFrames = gDebugger.DebuggerView.StackFrames; |
|
24 gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList; |
|
25 gToolbar = gDebugger.DebuggerView.Toolbar; |
|
26 |
|
27 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest); |
|
28 gDebuggee.firstCall(); |
|
29 }); |
|
30 } |
|
31 |
|
32 function performTest() { |
|
33 return Task.spawn(function() { |
|
34 yield selectBottomFrame(); |
|
35 testBottomFrame(0); |
|
36 |
|
37 yield performStep("StepOver"); |
|
38 testTopFrame(3); |
|
39 |
|
40 yield selectBottomFrame(); |
|
41 testBottomFrame(4); |
|
42 |
|
43 yield performStep("StepIn"); |
|
44 testTopFrame(2); |
|
45 |
|
46 yield selectBottomFrame(); |
|
47 testBottomFrame(4); |
|
48 |
|
49 yield performStep("StepOut"); |
|
50 testTopFrame(2); |
|
51 |
|
52 yield resumeDebuggerThenCloseAndFinish(gPanel); |
|
53 }); |
|
54 |
|
55 function selectBottomFrame() { |
|
56 let updated = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES); |
|
57 gClassicFrames.selectedIndex = gClassicFrames.itemCount - 1; |
|
58 return updated.then(waitForTick); |
|
59 } |
|
60 |
|
61 function testBottomFrame(debugLocation) { |
|
62 is(gFrames.selectedIndex, 0, |
|
63 "Oldest frame should be selected after click."); |
|
64 is(gClassicFrames.selectedIndex, gFrames.itemCount - 1, |
|
65 "Oldest frame should also be selected in the mirrored view."); |
|
66 is(gSources.selectedIndex, 0, |
|
67 "The first source is now selected in the widget."); |
|
68 is(gEditor.getText().search(/firstCall/), 118, |
|
69 "The first source is displayed."); |
|
70 is(gEditor.getText().search(/debugger/), -1, |
|
71 "The second source is not displayed."); |
|
72 |
|
73 is(gEditor.getDebugLocation(), debugLocation, |
|
74 "Editor debugger location is correct."); |
|
75 ok(gEditor.hasLineClass(debugLocation, "debug-line"), |
|
76 "The debugged line is highlighted appropriately."); |
|
77 } |
|
78 |
|
79 function performStep(type) { |
|
80 let updated = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES); |
|
81 gToolbar["_on" + type + "Pressed"](); |
|
82 return updated.then(waitForTick); |
|
83 } |
|
84 |
|
85 function testTopFrame(frameIndex) { |
|
86 is(gFrames.selectedIndex, frameIndex, |
|
87 "Topmost frame should be selected after click."); |
|
88 is(gClassicFrames.selectedIndex, gFrames.itemCount - frameIndex - 1, |
|
89 "Topmost frame should also be selected in the mirrored view."); |
|
90 is(gSources.selectedIndex, 1, |
|
91 "The second source is now selected in the widget."); |
|
92 is(gEditor.getText().search(/firstCall/), -1, |
|
93 "The second source is displayed."); |
|
94 is(gEditor.getText().search(/debugger/), 172, |
|
95 "The first source is not displayed."); |
|
96 } |
|
97 } |
|
98 |
|
99 registerCleanupFunction(function() { |
|
100 gTab = null; |
|
101 gDebuggee = null; |
|
102 gPanel = null; |
|
103 gDebugger = null; |
|
104 gEditor = null; |
|
105 gSources = null; |
|
106 gFrames = null; |
|
107 gClassicFrames = null; |
|
108 gToolbar = null; |
|
109 }); |