browser_console_keyboard_accessibility.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // Check that basic keyboard shortcuts work in the web console.
  5. "use strict";
  6. add_task(function* () {
  7. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  8. "test/test-console.html";
  9. yield loadTab(TEST_URI);
  10. let hud = yield openConsole();
  11. ok(hud, "Web Console opened");
  12. info("dump some spew into the console for scrolling");
  13. hud.jsterm.execute("(function() { for (var i = 0; i < 100; i++) { " +
  14. "console.log('foobarz' + i);" +
  15. "}})();");
  16. yield waitForMessages({
  17. webconsole: hud,
  18. messages: [{
  19. text: "foobarz99",
  20. category: CATEGORY_WEBDEV,
  21. severity: SEVERITY_LOG,
  22. }],
  23. });
  24. let currentPosition = hud.ui.outputWrapper.scrollTop;
  25. let bottom = currentPosition;
  26. EventUtils.synthesizeKey("VK_PAGE_UP", {});
  27. isnot(hud.ui.outputWrapper.scrollTop, currentPosition,
  28. "scroll position changed after page up");
  29. currentPosition = hud.ui.outputWrapper.scrollTop;
  30. EventUtils.synthesizeKey("VK_PAGE_DOWN", {});
  31. ok(hud.ui.outputWrapper.scrollTop > currentPosition,
  32. "scroll position now at bottom");
  33. EventUtils.synthesizeKey("VK_HOME", {});
  34. is(hud.ui.outputWrapper.scrollTop, 0, "scroll position now at top");
  35. EventUtils.synthesizeKey("VK_END", {});
  36. let scrollTop = hud.ui.outputWrapper.scrollTop;
  37. ok(scrollTop > 0 && Math.abs(scrollTop - bottom) <= 5,
  38. "scroll position now at bottom");
  39. info("try ctrl-l to clear output");
  40. executeSoon(() => {
  41. let clearShortcut;
  42. if (Services.appinfo.OS === "Darwin") {
  43. clearShortcut = WCUL10n.getStr("webconsole.clear.keyOSX");
  44. } else {
  45. clearShortcut = WCUL10n.getStr("webconsole.clear.key");
  46. }
  47. synthesizeKeyShortcut(clearShortcut);
  48. });
  49. yield hud.jsterm.once("messages-cleared");
  50. is(hud.outputNode.textContent.indexOf("foobarz1"), -1, "output cleared");
  51. is(hud.jsterm.inputNode.getAttribute("focused"), "true",
  52. "jsterm input is focused");
  53. info("try ctrl-f to focus filter");
  54. synthesizeKeyShortcut(WCUL10n.getStr("webconsole.find.key"));
  55. ok(!hud.jsterm.inputNode.getAttribute("focused"),
  56. "jsterm input is not focused");
  57. is(hud.ui.filterBox.getAttribute("focused"), "true",
  58. "filter input is focused");
  59. if (Services.appinfo.OS == "Darwin") {
  60. ok(hud.ui.getFilterState("network"), "network category is enabled");
  61. EventUtils.synthesizeKey("t", { ctrlKey: true });
  62. ok(!hud.ui.getFilterState("network"), "accesskey for Network works");
  63. EventUtils.synthesizeKey("t", { ctrlKey: true });
  64. ok(hud.ui.getFilterState("network"), "accesskey for Network works (again)");
  65. } else {
  66. EventUtils.synthesizeKey("N", { altKey: true });
  67. let net = hud.ui.document.querySelector("toolbarbutton[category=net]");
  68. is(hud.ui.document.activeElement, net,
  69. "accesskey for Network category focuses the Net button");
  70. }
  71. });