browser/devtools/webconsole/test/browser_webconsole_cached_autocomplete.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial