| |
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/. */ |
| |
5 |
| |
6 // Tests that the input box expands as the user types long lines. |
| |
7 |
| |
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; |
| |
9 |
| |
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 } |
| |
17 |
| |
18 function testJSInputExpansion(hud) { |
| |
19 let jsterm = hud.jsterm; |
| |
20 let input = jsterm.inputNode; |
| |
21 input.focus(); |
| |
22 |
| |
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); |
| |
39 |
| |
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(); |
| |
47 |
| |
48 ok(newerHeight > newHeight, "height changed: " + newerHeight); |
| |
49 |
| |
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"); |
| |
58 |
| |
59 finishTest(); |
| |
60 } |