browser/devtools/webconsole/test/browser_webconsole_history.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_history.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// Tests the console history feature accessed via the up and down arrow keys.
    1.10 +
    1.11 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    1.12 +
    1.13 +// Constants used for defining the direction of JSTerm input history navigation.
    1.14 +const HISTORY_BACK = -1;
    1.15 +const HISTORY_FORWARD = 1;
    1.16 +
    1.17 +function test() {
    1.18 +  addTab(TEST_URI);
    1.19 +  browser.addEventListener("load", function onLoad() {
    1.20 +    browser.removeEventListener("load", onLoad, true);
    1.21 +    openConsole(null, testHistory);
    1.22 +  }, true);
    1.23 +}
    1.24 +
    1.25 +function testHistory(hud) {
    1.26 +  let jsterm = hud.jsterm;
    1.27 +  let input = jsterm.inputNode;
    1.28 +
    1.29 +  let executeList = ["document", "window", "window.location"];
    1.30 +
    1.31 +  for each (var item in executeList) {
    1.32 +    input.value = item;
    1.33 +    jsterm.execute();
    1.34 +  }
    1.35 +
    1.36 +  for (var i = executeList.length - 1; i != -1; i--) {
    1.37 +    jsterm.historyPeruse(HISTORY_BACK);
    1.38 +    is (input.value, executeList[i], "check history previous idx:" + i);
    1.39 +  }
    1.40 +
    1.41 +  jsterm.historyPeruse(HISTORY_BACK);
    1.42 +  is (input.value, executeList[0], "test that item is still index 0");
    1.43 +
    1.44 +  jsterm.historyPeruse(HISTORY_BACK);
    1.45 +  is (input.value, executeList[0], "test that item is still still index 0");
    1.46 +
    1.47 +  for (var i = 1; i < executeList.length; i++) {
    1.48 +    jsterm.historyPeruse(HISTORY_FORWARD);
    1.49 +    is (input.value, executeList[i], "check history next idx:" + i);
    1.50 +  }
    1.51 +
    1.52 +  jsterm.historyPeruse(HISTORY_FORWARD);
    1.53 +  is (input.value, "", "check input is empty again");
    1.54 +
    1.55 +  // Simulate pressing Arrow_Down a few times and then if Arrow_Up shows
    1.56 +  // the previous item from history again.
    1.57 +  jsterm.historyPeruse(HISTORY_FORWARD);
    1.58 +  jsterm.historyPeruse(HISTORY_FORWARD);
    1.59 +  jsterm.historyPeruse(HISTORY_FORWARD);
    1.60 +
    1.61 +  is (input.value, "", "check input is still empty");
    1.62 +
    1.63 +  let idxLast = executeList.length - 1;
    1.64 +  jsterm.historyPeruse(HISTORY_BACK);
    1.65 +  is (input.value, executeList[idxLast], "check history next idx:" + idxLast);
    1.66 +
    1.67 +  executeSoon(finishTest);
    1.68 +}
    1.69 +

mercurial