browser/devtools/debugger/test/browser_dbg_scripts-switching-01.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:db5f4676be8c
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-01.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 ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel1),
23 "Title with first source is correct.");
24
25 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
26 .then(testSourcesDisplay)
27 .then(testSwitchPaused1)
28 .then(testSwitchPaused2)
29 .then(testSwitchRunning)
30 .then(() => resumeDebuggerThenCloseAndFinish(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 let gLabel1 = "code_script-switching-01.js";
40 let gLabel2 = "code_script-switching-02.js";
41
42 function testSourcesDisplay() {
43 let deferred = promise.defer();
44
45 is(gSources.itemCount, 2,
46 "Found the expected number of sources.");
47
48 is(gSources.items[0].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
49 EXAMPLE_URL + "code_script-switching-01.js",
50 "The correct tooltip text is displayed for the first source.");
51 is(gSources.items[1].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
52 EXAMPLE_URL + "code_script-switching-02.js",
53 "The correct tooltip text is displayed for the second source.");
54
55 ok(gSources.containsValue(EXAMPLE_URL + gLabel1),
56 "First source url is incorrect.");
57 ok(gSources.containsValue(EXAMPLE_URL + gLabel2),
58 "Second source url is incorrect.");
59
60 ok(gSources.getItemForAttachment(e => e.label == gLabel1),
61 "First source label is incorrect.");
62 ok(gSources.getItemForAttachment(e => e.label == gLabel2),
63 "Second source label is incorrect.");
64
65 ok(gSources.selectedItem,
66 "There should be a selected item in the sources pane.");
67 is(gSources.selectedValue, EXAMPLE_URL + gLabel2,
68 "The selected value is the sources pane is incorrect.");
69
70 is(gEditor.getText().search(/firstCall/), -1,
71 "The first source is not displayed.");
72 is(gEditor.getText().search(/debugger/), 172,
73 "The second source is displayed.");
74
75 ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel2),
76 "Title with second source is correct.");
77
78 ok(isCaretPos(gPanel, 1),
79 "Editor caret location is correct.");
80
81 // The editor's debug location takes a tick to update.
82 executeSoon(() => {
83 is(gEditor.getDebugLocation(), 0,
84 "Editor debugger location is correct.");
85 ok(gEditor.hasLineClass(0, "debug-line"),
86 "The debugged line is highlighted appropriately (1).");
87
88 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
89 gSources.selectedIndex = 0;
90 });
91
92 return deferred.promise;
93 }
94
95 function testSwitchPaused1() {
96 let deferred = promise.defer();
97
98 ok(gSources.selectedItem,
99 "There should be a selected item in the sources pane.");
100 is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
101 "The selected value is the sources pane is incorrect.");
102
103 is(gEditor.getText().search(/firstCall/), 118,
104 "The first source is displayed.");
105 is(gEditor.getText().search(/debugger/), -1,
106 "The second source is not displayed.");
107
108 // The editor's debug location takes a tick to update.
109 executeSoon(() => {
110 ok(isCaretPos(gPanel, 1),
111 "Editor caret location is correct.");
112 is(gEditor.getDebugLocation(), null,
113 "Editor debugger location is correct.");
114 ok(!gEditor.hasLineClass(5, "debug-line"),
115 "The debugged line highlight was removed.");
116
117 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
118 gSources.selectedIndex = 1;
119 });
120
121 return deferred.promise;
122 }
123
124 function testSwitchPaused2() {
125 let deferred = promise.defer();
126
127 ok(gSources.selectedItem,
128 "There should be a selected item in the sources pane.");
129 is(gSources.selectedValue, EXAMPLE_URL + gLabel2,
130 "The selected value is the sources pane is incorrect.");
131
132 is(gEditor.getText().search(/firstCall/), -1,
133 "The first source is not displayed.");
134 is(gEditor.getText().search(/debugger/), 172,
135 "The second source is displayed.");
136
137 // The editor's debug location takes a tick to update.
138 executeSoon(() => {
139 ok(isCaretPos(gPanel, 1),
140 "Editor caret location is correct.");
141 is(gEditor.getDebugLocation(), 0,
142 "Editor debugger location is correct.");
143 ok(gEditor.hasLineClass(0, "debug-line"),
144 "The debugged line is highlighted appropriately (2).");
145
146 // Step out three times.
147 waitForThreadEvents(gPanel, "paused").then(() => {
148 waitForThreadEvents(gPanel, "paused").then(() => {
149 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
150 gDebugger.gThreadClient.stepOut();
151 });
152 gDebugger.gThreadClient.stepOut();
153 });
154 gDebugger.gThreadClient.stepOut();
155 });
156
157 return deferred.promise;
158 }
159
160 function testSwitchRunning() {
161 let deferred = promise.defer();
162
163 ok(gSources.selectedItem,
164 "There should be a selected item in the sources pane.");
165 is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
166 "The selected value is the sources pane is incorrect.");
167
168 is(gEditor.getText().search(/firstCall/), 118,
169 "The first source is displayed.");
170 is(gEditor.getText().search(/debugger/), -1,
171 "The second source is not displayed.");
172
173 // The editor's debug location takes a tick to update.
174 executeSoon(() => {
175 ok(isCaretPos(gPanel, 1),
176 "Editor caret location is correct.");
177 is(gEditor.getDebugLocation(), 0,
178 "Editor debugger location is correct.");
179 ok(gEditor.hasLineClass(0, "debug-line"),
180 "The debugged line is highlighted appropriately (3).");
181
182 deferred.resolve();
183 });
184
185 return deferred.promise;
186 }
187
188 registerCleanupFunction(function() {
189 gTab = null;
190 gDebuggee = null;
191 gPanel = null;
192 gDebugger = null;
193 gEditor = null;
194 gSources = null;
195 gLabel1 = null;
196 gLabel2 = null;
197 });

mercurial