browser_webconsole_split.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. const TEST_URI = "data:text/html;charset=utf-8,Web Console test for splitting";
  6. function test() {
  7. waitForExplicitFinish();
  8. SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 1]]}, runTest);
  9. }
  10. function runTest() {
  11. // Test is slow on Linux EC2 instances - Bug 962931
  12. requestLongerTimeout(2);
  13. let {Toolbox} = require("devtools/client/framework/toolbox");
  14. let toolbox;
  15. loadTab(TEST_URI).then(testConsoleLoadOnDifferentPanel);
  16. function testConsoleLoadOnDifferentPanel() {
  17. info("About to check console loads even when non-webconsole panel is open");
  18. openPanel("inspector").then(() => {
  19. toolbox.on("webconsole-ready", () => {
  20. ok(true, "Webconsole has been triggered as loaded while another tool " +
  21. "is active");
  22. testKeyboardShortcuts();
  23. });
  24. // Opens split console.
  25. toolbox.toggleSplitConsole();
  26. });
  27. }
  28. function testKeyboardShortcuts() {
  29. info("About to check that panel responds to ESCAPE keyboard shortcut");
  30. toolbox.once("split-console", () => {
  31. ok(true, "Split console has been triggered via ESCAPE keypress");
  32. checkAllTools();
  33. });
  34. // Closes split console.
  35. EventUtils.sendKey("ESCAPE", toolbox.win);
  36. }
  37. function checkAllTools() {
  38. info("About to check split console with each panel individually.");
  39. Task.spawn(function* () {
  40. yield openAndCheckPanel("jsdebugger");
  41. yield openAndCheckPanel("inspector");
  42. yield openAndCheckPanel("styleeditor");
  43. yield openAndCheckPanel("performance");
  44. yield openAndCheckPanel("netmonitor");
  45. yield checkWebconsolePanelOpened();
  46. testBottomHost();
  47. });
  48. }
  49. function getCurrentUIState() {
  50. let win = toolbox.win;
  51. let deck = toolbox.doc.querySelector("#toolbox-deck");
  52. let webconsolePanel = toolbox.webconsolePanel;
  53. let splitter = toolbox.doc.querySelector("#toolbox-console-splitter");
  54. let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode)
  55. .getPropertyValue("height"));
  56. let deckHeight = parseFloat(win.getComputedStyle(deck)
  57. .getPropertyValue("height"));
  58. let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel)
  59. .getPropertyValue("height"));
  60. let splitterVisibility = !splitter.getAttribute("hidden");
  61. let openedConsolePanel = toolbox.currentToolId === "webconsole";
  62. let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole");
  63. return {
  64. deckHeight: deckHeight,
  65. containerHeight: containerHeight,
  66. webconsoleHeight: webconsoleHeight,
  67. splitterVisibility: splitterVisibility,
  68. openedConsolePanel: openedConsolePanel,
  69. buttonSelected: cmdButton.hasAttribute("checked")
  70. };
  71. }
  72. function checkWebconsolePanelOpened() {
  73. info("About to check special cases when webconsole panel is open.");
  74. let deferred = promise.defer();
  75. // Start with console split, so we can test for transition to main panel.
  76. toolbox.toggleSplitConsole();
  77. let currentUIState = getCurrentUIState();
  78. ok(currentUIState.splitterVisibility,
  79. "Splitter is visible when console is split");
  80. ok(currentUIState.deckHeight > 0,
  81. "Deck has a height > 0 when console is split");
  82. ok(currentUIState.webconsoleHeight > 0,
  83. "Web console has a height > 0 when console is split");
  84. ok(!currentUIState.openedConsolePanel,
  85. "The console panel is not the current tool");
  86. ok(currentUIState.buttonSelected, "The command button is selected");
  87. openPanel("webconsole").then(() => {
  88. currentUIState = getCurrentUIState();
  89. ok(!currentUIState.splitterVisibility,
  90. "Splitter is hidden when console is opened.");
  91. is(currentUIState.deckHeight, 0,
  92. "Deck has a height == 0 when console is opened.");
  93. is(currentUIState.webconsoleHeight, currentUIState.containerHeight,
  94. "Web console is full height.");
  95. ok(currentUIState.openedConsolePanel,
  96. "The console panel is the current tool");
  97. ok(currentUIState.buttonSelected,
  98. "The command button is still selected.");
  99. // Make sure splitting console does nothing while webconsole is opened
  100. toolbox.toggleSplitConsole();
  101. currentUIState = getCurrentUIState();
  102. ok(!currentUIState.splitterVisibility,
  103. "Splitter is hidden when console is opened.");
  104. is(currentUIState.deckHeight, 0,
  105. "Deck has a height == 0 when console is opened.");
  106. is(currentUIState.webconsoleHeight, currentUIState.containerHeight,
  107. "Web console is full height.");
  108. ok(currentUIState.openedConsolePanel,
  109. "The console panel is the current tool");
  110. ok(currentUIState.buttonSelected,
  111. "The command button is still selected.");
  112. // Make sure that split state is saved after opening another panel
  113. openPanel("inspector").then(() => {
  114. currentUIState = getCurrentUIState();
  115. ok(currentUIState.splitterVisibility,
  116. "Splitter is visible when console is split");
  117. ok(currentUIState.deckHeight > 0,
  118. "Deck has a height > 0 when console is split");
  119. ok(currentUIState.webconsoleHeight > 0,
  120. "Web console has a height > 0 when console is split");
  121. ok(!currentUIState.openedConsolePanel,
  122. "The console panel is not the current tool");
  123. ok(currentUIState.buttonSelected,
  124. "The command button is still selected.");
  125. toolbox.toggleSplitConsole();
  126. deferred.resolve();
  127. });
  128. });
  129. return deferred.promise;
  130. }
  131. function openPanel(toolId) {
  132. let deferred = promise.defer();
  133. let target = TargetFactory.forTab(gBrowser.selectedTab);
  134. gDevTools.showToolbox(target, toolId).then(function (box) {
  135. toolbox = box;
  136. deferred.resolve();
  137. }).then(null, console.error);
  138. return deferred.promise;
  139. }
  140. function openAndCheckPanel(toolId) {
  141. let deferred = promise.defer();
  142. openPanel(toolId).then(() => {
  143. info("Checking toolbox for " + toolId);
  144. checkToolboxUI(toolbox.getCurrentPanel());
  145. deferred.resolve();
  146. });
  147. return deferred.promise;
  148. }
  149. function checkToolboxUI() {
  150. let currentUIState = getCurrentUIState();
  151. ok(!currentUIState.splitterVisibility, "Splitter is hidden by default");
  152. is(currentUIState.deckHeight, currentUIState.containerHeight,
  153. "Deck has a height > 0 by default");
  154. is(currentUIState.webconsoleHeight, 0,
  155. "Web console is collapsed by default");
  156. ok(!currentUIState.openedConsolePanel,
  157. "The console panel is not the current tool");
  158. ok(!currentUIState.buttonSelected, "The command button is not selected.");
  159. toolbox.toggleSplitConsole();
  160. currentUIState = getCurrentUIState();
  161. ok(currentUIState.splitterVisibility,
  162. "Splitter is visible when console is split");
  163. ok(currentUIState.deckHeight > 0,
  164. "Deck has a height > 0 when console is split");
  165. ok(currentUIState.webconsoleHeight > 0,
  166. "Web console has a height > 0 when console is split");
  167. is(Math.round(currentUIState.deckHeight + currentUIState.webconsoleHeight),
  168. currentUIState.containerHeight,
  169. "Everything adds up to container height");
  170. ok(!currentUIState.openedConsolePanel,
  171. "The console panel is not the current tool");
  172. ok(currentUIState.buttonSelected, "The command button is selected.");
  173. toolbox.toggleSplitConsole();
  174. currentUIState = getCurrentUIState();
  175. ok(!currentUIState.splitterVisibility, "Splitter is hidden after toggling");
  176. is(currentUIState.deckHeight, currentUIState.containerHeight,
  177. "Deck has a height > 0 after toggling");
  178. is(currentUIState.webconsoleHeight, 0,
  179. "Web console is collapsed after toggling");
  180. ok(!currentUIState.openedConsolePanel,
  181. "The console panel is not the current tool");
  182. ok(!currentUIState.buttonSelected, "The command button is not selected.");
  183. }
  184. function testBottomHost() {
  185. checkHostType(Toolbox.HostType.BOTTOM);
  186. checkToolboxUI();
  187. toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost);
  188. }
  189. function testSidebarHost() {
  190. checkHostType(Toolbox.HostType.SIDE);
  191. checkToolboxUI();
  192. toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost);
  193. }
  194. function testWindowHost() {
  195. checkHostType(Toolbox.HostType.WINDOW);
  196. checkToolboxUI();
  197. toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy);
  198. }
  199. function checkHostType(hostType) {
  200. is(toolbox.hostType, hostType, "host type is " + hostType);
  201. let pref = Services.prefs.getCharPref("devtools.toolbox.host");
  202. is(pref, hostType, "host pref is " + hostType);
  203. }
  204. function testDestroy() {
  205. toolbox.destroy().then(function () {
  206. let target = TargetFactory.forTab(gBrowser.selectedTab);
  207. gDevTools.showToolbox(target).then(finish);
  208. });
  209. }
  210. function finish() {
  211. toolbox = null;
  212. finishTest();
  213. }
  214. }