browser/devtools/webconsole/test/browser_webconsole_completion.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_completion.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     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 code completion works properly.
    1.10 +
    1.11 +const TEST_URI = "data:text/html;charset=utf8,<p>test code completion";
    1.12 +
    1.13 +let testDriver;
    1.14 +
    1.15 +function test() {
    1.16 +  addTab(TEST_URI);
    1.17 +  browser.addEventListener("load", function onLoad() {
    1.18 +    browser.removeEventListener("load", onLoad, true);
    1.19 +    openConsole(null, function(hud) {
    1.20 +      testDriver = testCompletion(hud);
    1.21 +      testDriver.next();
    1.22 +    });
    1.23 +  }, true);
    1.24 +}
    1.25 +
    1.26 +function testNext() {
    1.27 +  executeSoon(function() {
    1.28 +    testDriver.next();
    1.29 +  });
    1.30 +}
    1.31 +
    1.32 +function testCompletion(hud) {
    1.33 +  let jsterm = hud.jsterm;
    1.34 +  let input = jsterm.inputNode;
    1.35 +
    1.36 +  // Test typing 'docu'.
    1.37 +  input.value = "docu";
    1.38 +  input.setSelectionRange(4, 4);
    1.39 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.40 +  yield undefined;
    1.41 +
    1.42 +  is(input.value, "docu", "'docu' completion (input.value)");
    1.43 +  is(jsterm.completeNode.value, "    ment", "'docu' completion (completeNode)");
    1.44 +
    1.45 +  // Test typing 'docu' and press tab.
    1.46 +  input.value = "docu";
    1.47 +  input.setSelectionRange(4, 4);
    1.48 +  jsterm.complete(jsterm.COMPLETE_FORWARD, testNext);
    1.49 +  yield undefined;
    1.50 +
    1.51 +  is(input.value, "document", "'docu' tab completion");
    1.52 +  is(input.selectionStart, 8, "start selection is alright");
    1.53 +  is(input.selectionEnd, 8, "end selection is alright");
    1.54 +  is(jsterm.completeNode.value.replace(/ /g, ""), "", "'docu' completed");
    1.55 +
    1.56 +  // Test typing 'window.Ob' and press tab.  Just 'window.O' is
    1.57 +  // ambiguous: could be window.Object, window.Option, etc.
    1.58 +  input.value = "window.Ob";
    1.59 +  input.setSelectionRange(9, 9);
    1.60 +  jsterm.complete(jsterm.COMPLETE_FORWARD, testNext);
    1.61 +  yield undefined;
    1.62 +
    1.63 +  is(input.value, "window.Object", "'window.Ob' tab completion");
    1.64 +
    1.65 +  // Test typing 'document.getElem'.
    1.66 +  input.value = "document.getElem";
    1.67 +  input.setSelectionRange(16, 16);
    1.68 +  jsterm.complete(jsterm.COMPLETE_FORWARD, testNext);
    1.69 +  yield undefined;
    1.70 +
    1.71 +  is(input.value, "document.getElem", "'document.getElem' completion");
    1.72 +  is(jsterm.completeNode.value, "                entsByTagNameNS", "'document.getElem' completion");
    1.73 +
    1.74 +  // Test pressing tab another time.
    1.75 +  jsterm.complete(jsterm.COMPLETE_FORWARD, testNext);
    1.76 +  yield undefined;
    1.77 +
    1.78 +  is(input.value, "document.getElem", "'document.getElem' completion");
    1.79 +  is(jsterm.completeNode.value, "                entsByTagName", "'document.getElem' another tab completion");
    1.80 +
    1.81 +  // Test pressing shift_tab.
    1.82 +  jsterm.complete(jsterm.COMPLETE_BACKWARD, testNext);
    1.83 +  yield undefined;
    1.84 +
    1.85 +  is(input.value, "document.getElem", "'document.getElem' untab completion");
    1.86 +  is(jsterm.completeNode.value, "                entsByTagNameNS", "'document.getElem' completion");
    1.87 +
    1.88 +  jsterm.clearOutput();
    1.89 +
    1.90 +  input.value = "docu";
    1.91 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
    1.92 +  yield undefined;
    1.93 +
    1.94 +  is(jsterm.completeNode.value, "    ment", "'docu' completion");
    1.95 +  jsterm.execute();
    1.96 +  is(jsterm.completeNode.value, "", "clear completion on execute()");
    1.97 +
    1.98 +  // Test multi-line completion works
    1.99 +  input.value =                 "console.log('one');\nconsol";
   1.100 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
   1.101 +  yield undefined;
   1.102 +
   1.103 +  is(jsterm.completeNode.value, "                   \n      e", "multi-line completion");
   1.104 +
   1.105 +  // Test non-object autocompletion.
   1.106 +  input.value = "Object.name.sl";
   1.107 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
   1.108 +  yield undefined;
   1.109 +
   1.110 +  is(jsterm.completeNode.value, "              ice", "non-object completion");
   1.111 +
   1.112 +  // Test string literal autocompletion.
   1.113 +  input.value = "'Asimov'.sl";
   1.114 +  jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
   1.115 +  yield undefined;
   1.116 +
   1.117 +  is(jsterm.completeNode.value, "           ice", "string literal completion");
   1.118 +
   1.119 +  testDriver = jsterm = input = null;
   1.120 +  executeSoon(finishTest);
   1.121 +  yield undefined;
   1.122 +}
   1.123 +

mercurial