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 the console history feature accessed via the up and down arrow keys. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; michael@0: michael@0: // Constants used for defining the direction of JSTerm input history navigation. michael@0: const HISTORY_BACK = -1; michael@0: const HISTORY_FORWARD = 1; 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, testHistory); michael@0: }, true); michael@0: } michael@0: michael@0: function testHistory(hud) { michael@0: let jsterm = hud.jsterm; michael@0: let input = jsterm.inputNode; michael@0: michael@0: let executeList = ["document", "window", "window.location"]; michael@0: michael@0: for each (var item in executeList) { michael@0: input.value = item; michael@0: jsterm.execute(); michael@0: } michael@0: michael@0: for (var i = executeList.length - 1; i != -1; i--) { michael@0: jsterm.historyPeruse(HISTORY_BACK); michael@0: is (input.value, executeList[i], "check history previous idx:" + i); michael@0: } michael@0: michael@0: jsterm.historyPeruse(HISTORY_BACK); michael@0: is (input.value, executeList[0], "test that item is still index 0"); michael@0: michael@0: jsterm.historyPeruse(HISTORY_BACK); michael@0: is (input.value, executeList[0], "test that item is still still index 0"); michael@0: michael@0: for (var i = 1; i < executeList.length; i++) { michael@0: jsterm.historyPeruse(HISTORY_FORWARD); michael@0: is (input.value, executeList[i], "check history next idx:" + i); michael@0: } michael@0: michael@0: jsterm.historyPeruse(HISTORY_FORWARD); michael@0: is (input.value, "", "check input is empty again"); michael@0: michael@0: // Simulate pressing Arrow_Down a few times and then if Arrow_Up shows michael@0: // the previous item from history again. michael@0: jsterm.historyPeruse(HISTORY_FORWARD); michael@0: jsterm.historyPeruse(HISTORY_FORWARD); michael@0: jsterm.historyPeruse(HISTORY_FORWARD); michael@0: michael@0: is (input.value, "", "check input is still empty"); michael@0: michael@0: let idxLast = executeList.length - 1; michael@0: jsterm.historyPeruse(HISTORY_BACK); michael@0: is (input.value, executeList[idxLast], "check history next idx:" + idxLast); michael@0: michael@0: executeSoon(finishTest); michael@0: } michael@0: