browser/devtools/webconsole/test/browser_webconsole_js_input_expansion.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_js_input_expansion.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     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 input box expands as the user types long lines.
    1.10 +
    1.11 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    1.12 +
    1.13 +function test() {
    1.14 +  addTab(TEST_URI);
    1.15 +  browser.addEventListener("load", function onLoad() {
    1.16 +    browser.removeEventListener("load", onLoad, true);
    1.17 +    openConsole(null, testJSInputExpansion);
    1.18 +  }, true);
    1.19 +}
    1.20 +
    1.21 +function testJSInputExpansion(hud) {
    1.22 +  let jsterm = hud.jsterm;
    1.23 +  let input = jsterm.inputNode;
    1.24 +  input.focus();
    1.25 +
    1.26 +  is(input.getAttribute("multiline"), "true", "multiline is enabled");
    1.27 +  // Tests if the inputNode expands.
    1.28 +  input.value = "hello\nworld\n";
    1.29 +  let length = input.value.length;
    1.30 +  input.selectionEnd = length;
    1.31 +  input.selectionStart = length;
    1.32 +  function getHeight()
    1.33 +  {
    1.34 +    return input.clientHeight;
    1.35 +  }
    1.36 +  let initialHeight = getHeight();
    1.37 +  // Performs an "d". This will trigger/test for the input event that should
    1.38 +  // change the "row" attribute of the inputNode.
    1.39 +  EventUtils.synthesizeKey("d", {});
    1.40 +  let newHeight = getHeight();
    1.41 +  ok(initialHeight < newHeight, "Height changed: " + newHeight);
    1.42 +
    1.43 +  // Add some more rows. Tests for the 8 row limit.
    1.44 +  input.value = "row1\nrow2\nrow3\nrow4\nrow5\nrow6\nrow7\nrow8\nrow9\nrow10\n";
    1.45 +  length = input.value.length;
    1.46 +  input.selectionEnd = length;
    1.47 +  input.selectionStart = length;
    1.48 +  EventUtils.synthesizeKey("d", {});
    1.49 +  let newerHeight = getHeight();
    1.50 +
    1.51 +  ok(newerHeight > newHeight, "height changed: " + newerHeight);
    1.52 +
    1.53 +  // Test if the inputNode shrinks again.
    1.54 +  input.value = "";
    1.55 +  EventUtils.synthesizeKey("d", {});
    1.56 +  let height = getHeight();
    1.57 +  info("height: " + height);
    1.58 +  info("initialHeight: " + initialHeight);
    1.59 +  let finalHeightDifference = Math.abs(initialHeight - height);
    1.60 +  ok(finalHeightDifference <= 1, "height shrank to original size within 1px");
    1.61 +
    1.62 +  finishTest();
    1.63 +}

mercurial