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.

     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/. */
     6 // Tests that the cached autocomplete results are used when the new
     7 // user input is a subset of the existing completion results.
     9 const TEST_URI = "data:text/html;charset=utf8,<p>test cached autocompletion results";
    11 let testDriver;
    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 }
    25 function testNext() {
    26   executeSoon(function() {
    27     testDriver.next();
    28   });
    29 }
    31 function testCompletion(hud) {
    32   let jsterm = hud.jsterm;
    33   let input = jsterm.inputNode;
    34   let popup = jsterm.autocompletePopup;
    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;
    42   is(input.value, "doc", "'docu' completion (input.value)");
    43   is(jsterm.completeNode.value, "   ument", "'docu' completion (completeNode)");
    45   // Test typing 'window.'.
    46   input.value = "window.";
    47   input.setSelectionRange(7, 7);
    48   jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    49   yield undefined;
    51   ok(popup.getItems().length > 0, "'window.' gave a list of suggestions")
    53   content.wrappedJSObject.docfoobar = true;
    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;
    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");
    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;
    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");
    77   delete content.wrappedJSObject.docfoobar;
    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");
    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;
    99   ok(popup.getItems().length > 0, "'dump(d' gives non-zero results");
   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;
   107   content.wrappedJSObject.docfoobar = true;
   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;
   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");
   120   delete content.wrappedJSObject.docfoobar;
   122   testDriver = null;
   123   executeSoon(finishTest);
   124   yield undefined;
   125 }

mercurial