browser_keybindings_01.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 that the keybindings for opening and closing the inspector work as expected
  5. // Can probably make this a shared test that tests all of the tools global keybindings
  6. const TEST_URL = "data:text/html,<html><head><title>Test for the " +
  7. "highlighter keybindings</title></head><body>" +
  8. "<h1>Keybindings!</h1></body></html>"
  9. const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
  10. function test()
  11. {
  12. waitForExplicitFinish();
  13. let doc;
  14. let node;
  15. let inspector;
  16. let keysetMap = { };
  17. addTab(TEST_URL).then(function () {
  18. doc = content.document;
  19. node = doc.querySelector("h1");
  20. waitForFocus(setupKeyBindingsTest);
  21. });
  22. function buildDevtoolsKeysetMap(keyset) {
  23. [].forEach.call(keyset.querySelectorAll("key"), function (key) {
  24. if (!key.getAttribute("key")) {
  25. return;
  26. }
  27. let modifiers = key.getAttribute("modifiers");
  28. keysetMap[key.id.split("_")[1]] = {
  29. key: key.getAttribute("key"),
  30. modifiers: modifiers,
  31. modifierOpt: {
  32. shiftKey: modifiers.match("shift"),
  33. ctrlKey: modifiers.match("ctrl"),
  34. altKey: modifiers.match("alt"),
  35. metaKey: modifiers.match("meta"),
  36. accelKey: modifiers.match("accel")
  37. },
  38. synthesizeKey: function () {
  39. EventUtils.synthesizeKey(this.key, this.modifierOpt);
  40. }
  41. };
  42. });
  43. }
  44. function setupKeyBindingsTest()
  45. {
  46. for (let win of gDevToolsBrowser._trackedBrowserWindows) {
  47. buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset"));
  48. }
  49. gDevTools.once("toolbox-ready", (e, toolbox) => {
  50. inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox);
  51. });
  52. keysetMap.inspector.synthesizeKey();
  53. }
  54. function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox)
  55. {
  56. is(aToolbox.currentToolId, "inspector", "Correct tool has been loaded");
  57. aToolbox.once("picker-started", () => {
  58. ok(true, "picker-started event received, highlighter started");
  59. keysetMap.inspector.synthesizeKey();
  60. aToolbox.once("picker-stopped", () => {
  61. ok(true, "picker-stopped event received, highlighter stopped");
  62. gDevTools.once("select-tool-command", () => {
  63. webconsoleShouldBeSelected(aToolbox);
  64. });
  65. keysetMap.webconsole.synthesizeKey();
  66. });
  67. });
  68. }
  69. function webconsoleShouldBeSelected(aToolbox)
  70. {
  71. is(aToolbox.currentToolId, "webconsole", "webconsole should be selected.");
  72. gDevTools.once("select-tool-command", () => {
  73. jsdebuggerShouldBeSelected(aToolbox);
  74. });
  75. keysetMap.jsdebugger.synthesizeKey();
  76. }
  77. function jsdebuggerShouldBeSelected(aToolbox)
  78. {
  79. is(aToolbox.currentToolId, "jsdebugger", "jsdebugger should be selected.");
  80. gDevTools.once("select-tool-command", () => {
  81. netmonitorShouldBeSelected(aToolbox);
  82. });
  83. keysetMap.netmonitor.synthesizeKey();
  84. }
  85. function netmonitorShouldBeSelected(aToolbox, panel)
  86. {
  87. is(aToolbox.currentToolId, "netmonitor", "netmonitor should be selected.");
  88. finishUp();
  89. }
  90. function finishUp() {
  91. doc = node = inspector = keysetMap = null;
  92. gBrowser.removeCurrentTab();
  93. finish();
  94. }
  95. }