|
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 the console history feature accessed via the up and down arrow keys. |
|
7 |
|
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; |
|
9 |
|
10 // Constants used for defining the direction of JSTerm input history navigation. |
|
11 const HISTORY_BACK = -1; |
|
12 const HISTORY_FORWARD = 1; |
|
13 |
|
14 function test() { |
|
15 addTab(TEST_URI); |
|
16 browser.addEventListener("load", function onLoad() { |
|
17 browser.removeEventListener("load", onLoad, true); |
|
18 openConsole(null, testHistory); |
|
19 }, true); |
|
20 } |
|
21 |
|
22 function testHistory(hud) { |
|
23 let jsterm = hud.jsterm; |
|
24 let input = jsterm.inputNode; |
|
25 |
|
26 let executeList = ["document", "window", "window.location"]; |
|
27 |
|
28 for each (var item in executeList) { |
|
29 input.value = item; |
|
30 jsterm.execute(); |
|
31 } |
|
32 |
|
33 for (var i = executeList.length - 1; i != -1; i--) { |
|
34 jsterm.historyPeruse(HISTORY_BACK); |
|
35 is (input.value, executeList[i], "check history previous idx:" + i); |
|
36 } |
|
37 |
|
38 jsterm.historyPeruse(HISTORY_BACK); |
|
39 is (input.value, executeList[0], "test that item is still index 0"); |
|
40 |
|
41 jsterm.historyPeruse(HISTORY_BACK); |
|
42 is (input.value, executeList[0], "test that item is still still index 0"); |
|
43 |
|
44 for (var i = 1; i < executeList.length; i++) { |
|
45 jsterm.historyPeruse(HISTORY_FORWARD); |
|
46 is (input.value, executeList[i], "check history next idx:" + i); |
|
47 } |
|
48 |
|
49 jsterm.historyPeruse(HISTORY_FORWARD); |
|
50 is (input.value, "", "check input is empty again"); |
|
51 |
|
52 // Simulate pressing Arrow_Down a few times and then if Arrow_Up shows |
|
53 // the previous item from history again. |
|
54 jsterm.historyPeruse(HISTORY_FORWARD); |
|
55 jsterm.historyPeruse(HISTORY_FORWARD); |
|
56 jsterm.historyPeruse(HISTORY_FORWARD); |
|
57 |
|
58 is (input.value, "", "check input is still empty"); |
|
59 |
|
60 let idxLast = executeList.length - 1; |
|
61 jsterm.historyPeruse(HISTORY_BACK); |
|
62 is (input.value, executeList[idxLast], "check history next idx:" + idxLast); |
|
63 |
|
64 executeSoon(finishTest); |
|
65 } |
|
66 |