browser/devtools/webconsole/test/browser_webconsole_cached_autocomplete.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_cached_autocomplete.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// Tests that the cached autocomplete results are used when the new
    1.10 +// user input is a subset of the existing completion results.
    1.11 +
    1.12 +const TEST_URI = "data:text/html;charset=utf8,<p>test cached autocompletion results";
    1.13 +
    1.14 +let testDriver;
    1.15 +
    1.16 +function test() {
    1.17 +  requestLongerTimeout(2);
    1.18 +  addTab(TEST_URI);
    1.19 +  browser.addEventListener("load", function onLoad() {
    1.20 +    browser.removeEventListener("load", onLoad, true);
    1.21 +    openConsole(null, function(hud) {
    1.22 +      testDriver = testCompletion(hud);
    1.23 +      testDriver.next();
    1.24 +    });
    1.25 +  }, true);
    1.26 +}
    1.27 +
    1.28 +function testNext() {
    1.29 +  executeSoon(function() {
    1.30 +    testDriver.next();
    1.31 +  });
    1.32 +}
    1.33 +
    1.34 +function testCompletion(hud) {
    1.35 +  let jsterm = hud.jsterm;
    1.36 +  let input = jsterm.inputNode;
    1.37 +  let popup = jsterm.autocompletePopup;
    1.38 +
    1.39 +  // Test if 'doc' gives 'document'
    1.40 +  input.value = "doc";
    1.41 +  input.setSelectionRange(3, 3);
    1.42 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.43 +  yield undefined;
    1.44 +
    1.45 +  is(input.value, "doc", "'docu' completion (input.value)");
    1.46 +  is(jsterm.completeNode.value, "   ument", "'docu' completion (completeNode)");
    1.47 +
    1.48 +  // Test typing 'window.'.
    1.49 +  input.value = "window.";
    1.50 +  input.setSelectionRange(7, 7);
    1.51 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.52 +  yield undefined;
    1.53 +
    1.54 +  ok(popup.getItems().length > 0, "'window.' gave a list of suggestions")
    1.55 +
    1.56 +  content.wrappedJSObject.docfoobar = true;
    1.57 +
    1.58 +  // Test typing 'window.doc'.
    1.59 +  input.value = "window.doc";
    1.60 +  input.setSelectionRange(10, 10);
    1.61 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.62 +  yield undefined;
    1.63 +
    1.64 +  let newItems = popup.getItems();
    1.65 +  ok(newItems.every(function(item) {
    1.66 +       return item.label != "docfoobar";
    1.67 +     }), "autocomplete cached results do not contain docfoobar. list has not been updated");
    1.68 +
    1.69 +  // Test that backspace does not cause a request to the server
    1.70 +  input.value = "window.do";
    1.71 +  input.setSelectionRange(9, 9);
    1.72 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.73 +  yield undefined;
    1.74 +
    1.75 +  newItems = popup.getItems();
    1.76 +  ok(newItems.every(function(item) {
    1.77 +       return item.label != "docfoobar";
    1.78 +     }), "autocomplete cached results do not contain docfoobar. list has not been updated");
    1.79 +
    1.80 +  delete content.wrappedJSObject.docfoobar;
    1.81 +
    1.82 +  // Test if 'window.getC' gives 'getComputedStyle'
    1.83 +  input.value = "window."
    1.84 +  input.setSelectionRange(7, 7);
    1.85 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.86 +  yield undefined;
    1.87 +  input.value = "window.getC";
    1.88 +  input.setSelectionRange(11, 11);
    1.89 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.90 +  yield undefined;
    1.91 +  newItems = popup.getItems();
    1.92 +  ok(!newItems.every(function(item) {
    1.93 +       return item.label != "getComputedStyle";
    1.94 +     }), "autocomplete results do contain getComputedStyle");
    1.95 +
    1.96 +  // Test if 'dump(d' gives non-zero results
    1.97 +  input.value = "dump(d";
    1.98 +  input.setSelectionRange(6, 6);
    1.99 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
   1.100 +  yield undefined;
   1.101 +
   1.102 +  ok(popup.getItems().length > 0, "'dump(d' gives non-zero results");
   1.103 +
   1.104 +  // Test that 'dump(window.)' works.
   1.105 +  input.value = "dump(window.)";
   1.106 +  input.setSelectionRange(12, 12);
   1.107 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
   1.108 +  yield undefined;
   1.109 +
   1.110 +  content.wrappedJSObject.docfoobar = true;
   1.111 +
   1.112 +  // Make sure 'dump(window.doc)' does not contain 'docfoobar'.
   1.113 +  input.value = "dump(window.doc)";
   1.114 +  input.setSelectionRange(15, 15);
   1.115 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
   1.116 +  yield undefined;
   1.117 +
   1.118 +  newItems = popup.getItems();
   1.119 +  ok(newItems.every(function(item) {
   1.120 +       return item.label != "docfoobar";
   1.121 +     }), "autocomplete cached results do not contain docfoobar. list has not been updated");
   1.122 +
   1.123 +  delete content.wrappedJSObject.docfoobar;
   1.124 +
   1.125 +  testDriver = null;
   1.126 +  executeSoon(finishTest);
   1.127 +  yield undefined;
   1.128 +}

mercurial