browser/devtools/webconsole/test/browser_webconsole_js_input_expansion.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 input box expands as the user types long lines.
     8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    10 function test() {
    11   addTab(TEST_URI);
    12   browser.addEventListener("load", function onLoad() {
    13     browser.removeEventListener("load", onLoad, true);
    14     openConsole(null, testJSInputExpansion);
    15   }, true);
    16 }
    18 function testJSInputExpansion(hud) {
    19   let jsterm = hud.jsterm;
    20   let input = jsterm.inputNode;
    21   input.focus();
    23   is(input.getAttribute("multiline"), "true", "multiline is enabled");
    24   // Tests if the inputNode expands.
    25   input.value = "hello\nworld\n";
    26   let length = input.value.length;
    27   input.selectionEnd = length;
    28   input.selectionStart = length;
    29   function getHeight()
    30   {
    31     return input.clientHeight;
    32   }
    33   let initialHeight = getHeight();
    34   // Performs an "d". This will trigger/test for the input event that should
    35   // change the "row" attribute of the inputNode.
    36   EventUtils.synthesizeKey("d", {});
    37   let newHeight = getHeight();
    38   ok(initialHeight < newHeight, "Height changed: " + newHeight);
    40   // Add some more rows. Tests for the 8 row limit.
    41   input.value = "row1\nrow2\nrow3\nrow4\nrow5\nrow6\nrow7\nrow8\nrow9\nrow10\n";
    42   length = input.value.length;
    43   input.selectionEnd = length;
    44   input.selectionStart = length;
    45   EventUtils.synthesizeKey("d", {});
    46   let newerHeight = getHeight();
    48   ok(newerHeight > newHeight, "height changed: " + newerHeight);
    50   // Test if the inputNode shrinks again.
    51   input.value = "";
    52   EventUtils.synthesizeKey("d", {});
    53   let height = getHeight();
    54   info("height: " + height);
    55   info("initialHeight: " + initialHeight);
    56   let finalHeightDifference = Math.abs(initialHeight - height);
    57   ok(finalHeightDifference <= 1, "height shrank to original size within 1px");
    59   finishTest();
    60 }

mercurial