browser_toolbox_toggle.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. "use strict";
  5. // Test toggling the toolbox with ACCEL+SHIFT+I / ACCEL+ALT+I and F12 in docked
  6. // and detached (window) modes.
  7. const URL = "data:text/html;charset=utf-8,Toggling devtools using shortcuts";
  8. var {Toolbox} = require("devtools/client/framework/toolbox");
  9. add_task(function* () {
  10. // Make sure this test starts with the selectedTool pref cleared. Previous
  11. // tests select various tools, and that sets this pref.
  12. Services.prefs.clearUserPref("devtools.toolbox.selectedTool");
  13. // Test with ACCEL+SHIFT+I / ACCEL+ALT+I (MacOSX) ; modifiers should match :
  14. // - toolbox-key-toggle in devtools/client/framework/toolbox-window.xul
  15. // - key_devToolboxMenuItem in browser/base/content/browser.xul
  16. info("Test toggle using CTRL+SHIFT+I/CMD+ALT+I");
  17. yield testToggle("I", {
  18. accelKey: true,
  19. shiftKey: !navigator.userAgent.match(/Mac/),
  20. altKey: navigator.userAgent.match(/Mac/)
  21. });
  22. // Test with F12 ; no modifiers
  23. info("Test toggle using F12");
  24. yield testToggle("VK_F12", {});
  25. });
  26. function* testToggle(key, modifiers) {
  27. let tab = yield addTab(URL + " ; key : '" + key + "'");
  28. yield gDevTools.showToolbox(TargetFactory.forTab(tab));
  29. yield testToggleDockedToolbox(tab, key, modifiers);
  30. yield testToggleDetachedToolbox(tab, key, modifiers);
  31. yield cleanup();
  32. }
  33. function* testToggleDockedToolbox(tab, key, modifiers) {
  34. let toolbox = getToolboxForTab(tab);
  35. isnot(toolbox.hostType, Toolbox.HostType.WINDOW,
  36. "Toolbox is docked in the main window");
  37. info("verify docked toolbox is destroyed when using toggle key");
  38. let onToolboxDestroyed = once(gDevTools, "toolbox-destroyed");
  39. EventUtils.synthesizeKey(key, modifiers);
  40. yield onToolboxDestroyed;
  41. ok(true, "Docked toolbox is destroyed when using a toggle key");
  42. info("verify new toolbox is created when using toggle key");
  43. let onToolboxReady = once(gDevTools, "toolbox-ready");
  44. EventUtils.synthesizeKey(key, modifiers);
  45. yield onToolboxReady;
  46. ok(true, "Toolbox is created by using when toggle key");
  47. }
  48. function* testToggleDetachedToolbox(tab, key, modifiers) {
  49. let toolbox = getToolboxForTab(tab);
  50. info("change the toolbox hostType to WINDOW");
  51. yield toolbox.switchHost(Toolbox.HostType.WINDOW);
  52. is(toolbox.hostType, Toolbox.HostType.WINDOW,
  53. "Toolbox opened on separate window");
  54. info("Wait for focus on the toolbox window");
  55. yield new Promise(res => waitForFocus(res, toolbox.win));
  56. info("Focus main window to put the toolbox window in the background");
  57. let onMainWindowFocus = once(window, "focus");
  58. window.focus();
  59. yield onMainWindowFocus;
  60. ok(true, "Main window focused");
  61. info("Verify windowed toolbox is focused instead of closed when using " +
  62. "toggle key from the main window");
  63. let toolboxWindow = toolbox.win.top;
  64. let onToolboxWindowFocus = once(toolboxWindow, "focus", true);
  65. EventUtils.synthesizeKey(key, modifiers);
  66. yield onToolboxWindowFocus;
  67. ok(true, "Toolbox focused and not destroyed");
  68. info("Verify windowed toolbox is destroyed when using toggle key from its " +
  69. "own window");
  70. let onToolboxDestroyed = once(gDevTools, "toolbox-destroyed");
  71. EventUtils.synthesizeKey(key, modifiers, toolboxWindow);
  72. yield onToolboxDestroyed;
  73. ok(true, "Toolbox destroyed");
  74. }
  75. function getToolboxForTab(tab) {
  76. return gDevTools.getToolbox(TargetFactory.forTab(tab));
  77. }
  78. function* cleanup() {
  79. Services.prefs.setCharPref("devtools.toolbox.host",
  80. Toolbox.HostType.BOTTOM);
  81. gBrowser.removeCurrentTab();
  82. }