michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests that the input box expands as the user types long lines. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, testJSInputExpansion); michael@0: }, true); michael@0: } michael@0: michael@0: function testJSInputExpansion(hud) { michael@0: let jsterm = hud.jsterm; michael@0: let input = jsterm.inputNode; michael@0: input.focus(); michael@0: michael@0: is(input.getAttribute("multiline"), "true", "multiline is enabled"); michael@0: // Tests if the inputNode expands. michael@0: input.value = "hello\nworld\n"; michael@0: let length = input.value.length; michael@0: input.selectionEnd = length; michael@0: input.selectionStart = length; michael@0: function getHeight() michael@0: { michael@0: return input.clientHeight; michael@0: } michael@0: let initialHeight = getHeight(); michael@0: // Performs an "d". This will trigger/test for the input event that should michael@0: // change the "row" attribute of the inputNode. michael@0: EventUtils.synthesizeKey("d", {}); michael@0: let newHeight = getHeight(); michael@0: ok(initialHeight < newHeight, "Height changed: " + newHeight); michael@0: michael@0: // Add some more rows. Tests for the 8 row limit. michael@0: input.value = "row1\nrow2\nrow3\nrow4\nrow5\nrow6\nrow7\nrow8\nrow9\nrow10\n"; michael@0: length = input.value.length; michael@0: input.selectionEnd = length; michael@0: input.selectionStart = length; michael@0: EventUtils.synthesizeKey("d", {}); michael@0: let newerHeight = getHeight(); michael@0: michael@0: ok(newerHeight > newHeight, "height changed: " + newerHeight); michael@0: michael@0: // Test if the inputNode shrinks again. michael@0: input.value = ""; michael@0: EventUtils.synthesizeKey("d", {}); michael@0: let height = getHeight(); michael@0: info("height: " + height); michael@0: info("initialHeight: " + initialHeight); michael@0: let finalHeightDifference = Math.abs(initialHeight - height); michael@0: ok(finalHeightDifference <= 1, "height shrank to original size within 1px"); michael@0: michael@0: finishTest(); michael@0: }