browser/devtools/webconsole/test/browser_webconsole_cached_autocomplete.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2f4ec9a13817
1 /* vim:set ts=2 sw=2 sts=2 et: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 // Tests that the cached autocomplete results are used when the new
7 // user input is a subset of the existing completion results.
8
9 const TEST_URI = "data:text/html;charset=utf8,<p>test cached autocompletion results";
10
11 let testDriver;
12
13 function test() {
14 requestLongerTimeout(2);
15 addTab(TEST_URI);
16 browser.addEventListener("load", function onLoad() {
17 browser.removeEventListener("load", onLoad, true);
18 openConsole(null, function(hud) {
19 testDriver = testCompletion(hud);
20 testDriver.next();
21 });
22 }, true);
23 }
24
25 function testNext() {
26 executeSoon(function() {
27 testDriver.next();
28 });
29 }
30
31 function testCompletion(hud) {
32 let jsterm = hud.jsterm;
33 let input = jsterm.inputNode;
34 let popup = jsterm.autocompletePopup;
35
36 // Test if 'doc' gives 'document'
37 input.value = "doc";
38 input.setSelectionRange(3, 3);
39 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
40 yield undefined;
41
42 is(input.value, "doc", "'docu' completion (input.value)");
43 is(jsterm.completeNode.value, " ument", "'docu' completion (completeNode)");
44
45 // Test typing 'window.'.
46 input.value = "window.";
47 input.setSelectionRange(7, 7);
48 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
49 yield undefined;
50
51 ok(popup.getItems().length > 0, "'window.' gave a list of suggestions")
52
53 content.wrappedJSObject.docfoobar = true;
54
55 // Test typing 'window.doc'.
56 input.value = "window.doc";
57 input.setSelectionRange(10, 10);
58 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
59 yield undefined;
60
61 let newItems = popup.getItems();
62 ok(newItems.every(function(item) {
63 return item.label != "docfoobar";
64 }), "autocomplete cached results do not contain docfoobar. list has not been updated");
65
66 // Test that backspace does not cause a request to the server
67 input.value = "window.do";
68 input.setSelectionRange(9, 9);
69 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
70 yield undefined;
71
72 newItems = popup.getItems();
73 ok(newItems.every(function(item) {
74 return item.label != "docfoobar";
75 }), "autocomplete cached results do not contain docfoobar. list has not been updated");
76
77 delete content.wrappedJSObject.docfoobar;
78
79 // Test if 'window.getC' gives 'getComputedStyle'
80 input.value = "window."
81 input.setSelectionRange(7, 7);
82 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
83 yield undefined;
84 input.value = "window.getC";
85 input.setSelectionRange(11, 11);
86 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
87 yield undefined;
88 newItems = popup.getItems();
89 ok(!newItems.every(function(item) {
90 return item.label != "getComputedStyle";
91 }), "autocomplete results do contain getComputedStyle");
92
93 // Test if 'dump(d' gives non-zero results
94 input.value = "dump(d";
95 input.setSelectionRange(6, 6);
96 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
97 yield undefined;
98
99 ok(popup.getItems().length > 0, "'dump(d' gives non-zero results");
100
101 // Test that 'dump(window.)' works.
102 input.value = "dump(window.)";
103 input.setSelectionRange(12, 12);
104 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
105 yield undefined;
106
107 content.wrappedJSObject.docfoobar = true;
108
109 // Make sure 'dump(window.doc)' does not contain 'docfoobar'.
110 input.value = "dump(window.doc)";
111 input.setSelectionRange(15, 15);
112 jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
113 yield undefined;
114
115 newItems = popup.getItems();
116 ok(newItems.every(function(item) {
117 return item.label != "docfoobar";
118 }), "autocomplete cached results do not contain docfoobar. list has not been updated");
119
120 delete content.wrappedJSObject.docfoobar;
121
122 testDriver = null;
123 executeSoon(finishTest);
124 yield undefined;
125 }

mercurial