browser_webconsole_history.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Tests the console history feature accessed via the up and down arrow keys.
  5. "use strict";
  6. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  7. "test/test-console.html";
  8. // Constants used for defining the direction of JSTerm input history navigation.
  9. const HISTORY_BACK = -1;
  10. const HISTORY_FORWARD = 1;
  11. add_task(function* () {
  12. yield loadTab(TEST_URI);
  13. let hud = yield openConsole();
  14. hud.jsterm.clearOutput();
  15. let jsterm = hud.jsterm;
  16. let input = jsterm.inputNode;
  17. let executeList = ["document", "window", "window.location"];
  18. for (let item of executeList) {
  19. input.value = item;
  20. yield jsterm.execute();
  21. }
  22. for (let x = executeList.length - 1; x != -1; x--) {
  23. jsterm.historyPeruse(HISTORY_BACK);
  24. is(input.value, executeList[x], "check history previous idx:" + x);
  25. }
  26. jsterm.historyPeruse(HISTORY_BACK);
  27. is(input.value, executeList[0], "test that item is still index 0");
  28. jsterm.historyPeruse(HISTORY_BACK);
  29. is(input.value, executeList[0], "test that item is still still index 0");
  30. for (let i = 1; i < executeList.length; i++) {
  31. jsterm.historyPeruse(HISTORY_FORWARD);
  32. is(input.value, executeList[i], "check history next idx:" + i);
  33. }
  34. jsterm.historyPeruse(HISTORY_FORWARD);
  35. is(input.value, "", "check input is empty again");
  36. // Simulate pressing Arrow_Down a few times and then if Arrow_Up shows
  37. // the previous item from history again.
  38. jsterm.historyPeruse(HISTORY_FORWARD);
  39. jsterm.historyPeruse(HISTORY_FORWARD);
  40. jsterm.historyPeruse(HISTORY_FORWARD);
  41. is(input.value, "", "check input is still empty");
  42. let idxLast = executeList.length - 1;
  43. jsterm.historyPeruse(HISTORY_BACK);
  44. is(input.value, executeList[idxLast], "check history next idx:" + idxLast);
  45. });