browser_toolbox_minimize.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 that when the toolbox is displayed in a bottom host, that host can be
  6. // minimized to just the tabbar height, and maximized again.
  7. // Also test that while minimized, switching to a tool, clicking on the
  8. // settings, or clicking on the selected tool's tab maximizes the toolbox again.
  9. // Finally test that the minimize button doesn't exist in other host types.
  10. const URL = "data:text/html;charset=utf8,test page";
  11. const {Toolbox} = require("devtools/client/framework/toolbox");
  12. add_task(function* () {
  13. info("Create a test tab and open the toolbox");
  14. let tab = yield addTab(URL);
  15. let target = TargetFactory.forTab(tab);
  16. let toolbox = yield gDevTools.showToolbox(target, "webconsole");
  17. let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  18. ok(button, "The minimize button exists in the default bottom host");
  19. info("Try to minimize the toolbox");
  20. yield minimize(toolbox);
  21. ok(parseInt(toolbox._host.frame.style.marginBottom, 10) < 0,
  22. "The toolbox host has been hidden away with a negative-margin");
  23. info("Try to maximize again the toolbox");
  24. yield maximize(toolbox);
  25. ok(parseInt(toolbox._host.frame.style.marginBottom, 10) == 0,
  26. "The toolbox host is shown again");
  27. info("Try to minimize again using the keyboard shortcut");
  28. yield minimizeWithShortcut(toolbox);
  29. ok(parseInt(toolbox._host.frame.style.marginBottom, 10) < 0,
  30. "The toolbox host has been hidden away with a negative-margin");
  31. info("Try to maximize again using the keyboard shortcut");
  32. yield maximizeWithShortcut(toolbox);
  33. ok(parseInt(toolbox._host.frame.style.marginBottom, 10) == 0,
  34. "The toolbox host is shown again");
  35. info("Minimize again and switch to another tool");
  36. yield minimize(toolbox);
  37. let onMaximized = toolbox._host.once("maximized");
  38. yield toolbox.selectTool("inspector");
  39. yield onMaximized;
  40. info("Minimize again and click on the tab of the current tool");
  41. yield minimize(toolbox);
  42. onMaximized = toolbox._host.once("maximized");
  43. let tabButton = toolbox.doc.querySelector("#toolbox-tab-inspector");
  44. EventUtils.synthesizeMouseAtCenter(tabButton, {}, toolbox.win);
  45. yield onMaximized;
  46. info("Minimize again and click on the settings tab");
  47. yield minimize(toolbox);
  48. onMaximized = toolbox._host.once("maximized");
  49. let settingsButton = toolbox.doc.querySelector("#toolbox-tab-options");
  50. EventUtils.synthesizeMouseAtCenter(settingsButton, {}, toolbox.win);
  51. yield onMaximized;
  52. info("Switch to a different host");
  53. yield toolbox.switchHost(Toolbox.HostType.SIDE);
  54. button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  55. ok(!button, "The minimize button doesn't exist in the side host");
  56. Services.prefs.clearUserPref("devtools.toolbox.host");
  57. yield toolbox.destroy();
  58. gBrowser.removeCurrentTab();
  59. });
  60. function* minimize(toolbox) {
  61. let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  62. let onMinimized = toolbox._host.once("minimized");
  63. EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win);
  64. yield onMinimized;
  65. }
  66. function* minimizeWithShortcut(toolbox) {
  67. let key = toolbox.doc.getElementById("toolbox-minimize-key")
  68. .getAttribute("key");
  69. let onMinimized = toolbox._host.once("minimized");
  70. EventUtils.synthesizeKey(key, {accelKey: true, shiftKey: true},
  71. toolbox.win);
  72. yield onMinimized;
  73. }
  74. function* maximize(toolbox) {
  75. let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  76. let onMaximized = toolbox._host.once("maximized");
  77. EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win);
  78. yield onMaximized;
  79. }
  80. function* maximizeWithShortcut(toolbox) {
  81. let key = toolbox.doc.getElementById("toolbox-minimize-key")
  82. .getAttribute("key");
  83. let onMaximized = toolbox._host.once("maximized");
  84. EventUtils.synthesizeKey(key, {accelKey: true, shiftKey: true},
  85. toolbox.win);
  86. yield onMaximized;
  87. }