1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that makes sure web console autocomplete happens in the user-selected
// stackframe from the js debugger.
"use strict";
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"test/test-autocomplete-in-stackframe.html";
// Force the old debugger UI since it's directly used (see Bug 1301705)
Services.prefs.setBoolPref("devtools.debugger.new-debugger-frontend", false);
registerCleanupFunction(function* () {
Services.prefs.clearUserPref("devtools.debugger.new-debugger-frontend");
});
var gStackframes;
registerCleanupFunction(function () {
gStackframes = null;
});
requestLongerTimeout(2);
add_task(function* () {
yield loadTab(TEST_URI);
let hud = yield openConsole();
yield testCompletion(hud);
});
function* testCompletion(hud) {
let jsterm = hud.jsterm;
let input = jsterm.inputNode;
let popup = jsterm.autocompletePopup;
// Test that document.title gives string methods. Native getters must execute.
input.value = "document.title.";
input.setSelectionRange(input.value.length, input.value.length);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
let newItems = popup.getItems();
ok(newItems.length > 0, "'document.title.' gave a list of suggestions");
ok(newItems.some(function (item) {
return item.label == "substr";
}), "autocomplete results do contain substr");
ok(newItems.some(function (item) {
return item.label == "toLowerCase";
}), "autocomplete results do contain toLowerCase");
ok(newItems.some(function (item) {
return item.label == "strike";
}), "autocomplete results do contain strike");
// Test if 'f' gives 'foo1' but not 'foo2' or 'foo3'
input.value = "f";
input.setSelectionRange(1, 1);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(newItems.length > 0, "'f' gave a list of suggestions");
ok(!newItems.every(function (item) {
return item.label != "foo1";
}), "autocomplete results do contain foo1");
ok(!newItems.every(function (item) {
return item.label != "foo1Obj";
}), "autocomplete results do contain foo1Obj");
ok(newItems.every(function (item) {
return item.label != "foo2";
}), "autocomplete results do not contain foo2");
ok(newItems.every(function (item) {
return item.label != "foo2Obj";
}), "autocomplete results do not contain foo2Obj");
ok(newItems.every(function (item) {
return item.label != "foo3";
}), "autocomplete results do not contain foo3");
ok(newItems.every(function (item) {
return item.label != "foo3Obj";
}), "autocomplete results do not contain foo3Obj");
// Test if 'foo1Obj.' gives 'prop1' and 'prop2'
input.value = "foo1Obj.";
input.setSelectionRange(8, 8);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(!newItems.every(function (item) {
return item.label != "prop1";
}), "autocomplete results do contain prop1");
ok(!newItems.every(function (item) {
return item.label != "prop2";
}), "autocomplete results do contain prop2");
// Test if 'foo1Obj.prop2.' gives 'prop21'
input.value = "foo1Obj.prop2.";
input.setSelectionRange(14, 14);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(!newItems.every(function (item) {
return item.label != "prop21";
}), "autocomplete results do contain prop21");
info("Opening Debugger");
let dbg = yield openDebugger();
info("Waiting for pause");
yield pauseDebugger(dbg);
info("Opening Console again");
yield openConsole();
// From this point on the
// Test if 'f' gives 'foo3' and 'foo1' but not 'foo2'
input.value = "f";
input.setSelectionRange(1, 1);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(newItems.length > 0, "'f' gave a list of suggestions");
ok(!newItems.every(function (item) {
return item.label != "foo3";
}), "autocomplete results do contain foo3");
ok(!newItems.every(function (item) {
return item.label != "foo3Obj";
}), "autocomplete results do contain foo3Obj");
ok(!newItems.every(function (item) {
return item.label != "foo1";
}), "autocomplete results do contain foo1");
ok(!newItems.every(function (item) {
return item.label != "foo1Obj";
}), "autocomplete results do contain foo1Obj");
ok(newItems.every(function (item) {
return item.label != "foo2";
}), "autocomplete results do not contain foo2");
ok(newItems.every(function (item) {
return item.label != "foo2Obj";
}), "autocomplete results do not contain foo2Obj");
yield openDebugger();
gStackframes.selectFrame(1);
info("openConsole");
yield openConsole();
// Test if 'f' gives 'foo2' and 'foo1' but not 'foo3'
input.value = "f";
input.setSelectionRange(1, 1);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(newItems.length > 0, "'f' gave a list of suggestions");
ok(!newItems.every(function (item) {
return item.label != "foo2";
}), "autocomplete results do contain foo2");
ok(!newItems.every(function (item) {
return item.label != "foo2Obj";
}), "autocomplete results do contain foo2Obj");
ok(!newItems.every(function (item) {
return item.label != "foo1";
}), "autocomplete results do contain foo1");
ok(!newItems.every(function (item) {
return item.label != "foo1Obj";
}), "autocomplete results do contain foo1Obj");
ok(newItems.every(function (item) {
return item.label != "foo3";
}), "autocomplete results do not contain foo3");
ok(newItems.every(function (item) {
return item.label != "foo3Obj";
}), "autocomplete results do not contain foo3Obj");
// Test if 'foo2Obj.' gives 'prop1'
input.value = "foo2Obj.";
input.setSelectionRange(8, 8);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(!newItems.every(function (item) {
return item.label != "prop1";
}), "autocomplete results do contain prop1");
// Test if 'foo2Obj.prop1.' gives 'prop11'
input.value = "foo2Obj.prop1.";
input.setSelectionRange(14, 14);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(!newItems.every(function (item) {
return item.label != "prop11";
}), "autocomplete results do contain prop11");
// Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string
// i.e. 'length'
input.value = "foo2Obj.prop1.prop11.";
input.setSelectionRange(21, 21);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
ok(!newItems.every(function (item) {
return item.label != "length";
}), "autocomplete results do contain length");
// Test if 'foo1Obj[0].' throws no errors.
input.value = "foo2Obj[0].";
input.setSelectionRange(11, 11);
yield new Promise(resolve => {
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
});
newItems = popup.getItems();
is(newItems.length, 0, "no items for foo2Obj[0]");
}
function pauseDebugger(aResult) {
let debuggerWin = aResult.panelWin;
let debuggerController = debuggerWin.DebuggerController;
let thread = debuggerController.activeThread;
gStackframes = debuggerController.StackFrames;
return new Promise(resolve => {
thread.addOneTimeListener("framesadded", resolve);
info("firstCall()");
ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
content.wrappedJSObject.firstCall();
});
});
}
|