browser/devtools/webconsole/test/browser_webconsole_split.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c92161d3f14f
1 /* vim:set ts=2 sw=2 sts=2 et: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 function test()
7 {
8 // Test is slow on Linux EC2 instances - Bug 962931
9 requestLongerTimeout(2);
10
11 let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
12 let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
13 let Toolbox = devtools.Toolbox;
14 let toolbox;
15
16 addTab("data:text/html;charset=utf-8,Web Console test for splitting");
17 browser.addEventListener("load", function onLoad() {
18 browser.removeEventListener("load", onLoad, true);
19 testConsoleLoadOnDifferentPanel()
20 }, true);
21
22 function testConsoleLoadOnDifferentPanel()
23 {
24 info("About to check console loads even when non-webconsole panel is open");
25
26 openPanel("inspector").then(() => {
27 toolbox.on("webconsole-ready", () => {
28 ok(true, "Webconsole has been triggered as loaded while another tool is active");
29 testKeyboardShortcuts();
30 });
31
32 // Opens split console.
33 toolbox.toggleSplitConsole();
34 });
35 }
36
37 function testKeyboardShortcuts()
38 {
39 info("About to check that panel responds to ESCAPE keyboard shortcut");
40
41 toolbox.once("split-console", () => {
42 ok(true, "Split console has been triggered via ESCAPE keypress");
43 checkAllTools();
44 });
45
46 // Closes split console.
47 EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
48 }
49
50 function checkAllTools()
51 {
52 info("About to check split console with each panel individually.");
53
54 Task.spawn(function() {
55 yield openAndCheckPanel("jsdebugger");
56 yield openAndCheckPanel("inspector");
57 yield openAndCheckPanel("styleeditor");
58 yield openAndCheckPanel("jsprofiler");
59 yield openAndCheckPanel("netmonitor");
60
61 yield checkWebconsolePanelOpened();
62 testBottomHost();
63 });
64 }
65
66 function getCurrentUIState()
67 {
68 let win = toolbox.doc.defaultView;
69 let deck = toolbox.doc.querySelector("#toolbox-deck");
70 let webconsolePanel = toolbox.doc.querySelector("#toolbox-panel-webconsole");
71 let splitter = toolbox.doc.querySelector("#toolbox-console-splitter");
72
73 let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode).getPropertyValue("height"));
74 let deckHeight = parseFloat(win.getComputedStyle(deck).getPropertyValue("height"));
75 let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel).getPropertyValue("height"));
76 let splitterVisibility = !splitter.getAttribute("hidden");
77 let openedConsolePanel = toolbox.currentToolId === "webconsole";
78 let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole");
79
80 return {
81 deckHeight: deckHeight,
82 containerHeight: containerHeight,
83 webconsoleHeight: webconsoleHeight,
84 splitterVisibility: splitterVisibility,
85 openedConsolePanel: openedConsolePanel,
86 buttonSelected: cmdButton.hasAttribute("checked")
87 };
88 }
89
90 function checkWebconsolePanelOpened()
91 {
92 info("About to check special cases when webconsole panel is open.");
93
94 let deferred = promise.defer();
95
96 // Start with console split, so we can test for transition to main panel.
97 toolbox.toggleSplitConsole();
98
99 let currentUIState = getCurrentUIState();
100
101 ok (currentUIState.splitterVisibility, "Splitter is visible when console is split");
102 ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split");
103 ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split");
104 ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
105 ok (currentUIState.buttonSelected, "The command button is selected");
106
107 openPanel("webconsole").then(() => {
108
109 let currentUIState = getCurrentUIState();
110
111 ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened.");
112 is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened.");
113 is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height.");
114 ok (currentUIState.openedConsolePanel, "The console panel is the current tool");
115 ok (currentUIState.buttonSelected, "The command button is still selected.");
116
117 // Make sure splitting console does nothing while webconsole is opened
118 toolbox.toggleSplitConsole();
119
120 let currentUIState = getCurrentUIState();
121
122 ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened.");
123 is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened.");
124 is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height.");
125 ok (currentUIState.openedConsolePanel, "The console panel is the current tool");
126 ok (currentUIState.buttonSelected, "The command button is still selected.");
127
128 // Make sure that split state is saved after opening another panel
129 openPanel("inspector").then(() => {
130 let currentUIState = getCurrentUIState();
131 ok (currentUIState.splitterVisibility, "Splitter is visible when console is split");
132 ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split");
133 ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split");
134 ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
135 ok (currentUIState.buttonSelected, "The command button is still selected.");
136
137 toolbox.toggleSplitConsole();
138 deferred.resolve();
139
140 });
141 });
142 return deferred.promise;
143 }
144
145 function openPanel(toolId, callback)
146 {
147 let deferred = promise.defer();
148 let target = TargetFactory.forTab(gBrowser.selectedTab);
149 gDevTools.showToolbox(target, toolId).then(function(box) {
150 toolbox = box;
151 deferred.resolve();
152 }).then(null, console.error);
153 return deferred.promise;
154 }
155
156 function openAndCheckPanel(toolId)
157 {
158 let deferred = promise.defer();
159 openPanel(toolId).then(() => {
160 info ("Checking toolbox for " + toolId);
161 checkToolboxUI(toolbox.getCurrentPanel());
162 deferred.resolve();
163 });
164 return deferred.promise;
165 }
166
167 function checkToolboxUI()
168 {
169 let currentUIState = getCurrentUIState();
170
171 ok (!currentUIState.splitterVisibility, "Splitter is hidden by default");
172 is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 by default");
173 is (currentUIState.webconsoleHeight, 0, "Web console is collapsed by default");
174 ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
175 ok (!currentUIState.buttonSelected, "The command button is not selected.");
176
177 toolbox.toggleSplitConsole();
178
179 let currentUIState = getCurrentUIState();
180
181 ok (currentUIState.splitterVisibility, "Splitter is visible when console is split");
182 ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split");
183 ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split");
184 is (currentUIState.deckHeight + currentUIState.webconsoleHeight,
185 currentUIState.containerHeight,
186 "Everything adds up to container height");
187 ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
188 ok (currentUIState.buttonSelected, "The command button is selected.");
189
190 toolbox.toggleSplitConsole();
191
192 let currentUIState = getCurrentUIState();
193
194 ok (!currentUIState.splitterVisibility, "Splitter is hidden after toggling");
195 is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 after toggling");
196 is (currentUIState.webconsoleHeight, 0, "Web console is collapsed after toggling");
197 ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
198 ok (!currentUIState.buttonSelected, "The command button is not selected.");
199 }
200
201 function testBottomHost()
202 {
203 checkHostType(Toolbox.HostType.BOTTOM);
204
205 checkToolboxUI();
206
207 toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost);
208 }
209
210 function testSidebarHost()
211 {
212 checkHostType(Toolbox.HostType.SIDE);
213
214 checkToolboxUI();
215
216 toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost);
217 }
218
219 function testWindowHost()
220 {
221 checkHostType(Toolbox.HostType.WINDOW);
222
223 checkToolboxUI();
224
225 toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy);
226 }
227
228 function checkHostType(hostType)
229 {
230 is(toolbox.hostType, hostType, "host type is " + hostType);
231
232 let pref = Services.prefs.getCharPref("devtools.toolbox.host");
233 is(pref, hostType, "host pref is " + hostType);
234 }
235
236 function testDestroy()
237 {
238 toolbox.destroy().then(function() {
239 let target = TargetFactory.forTab(gBrowser.selectedTab);
240 gDevTools.showToolbox(target).then(finish);
241 });
242 }
243
244 function finish()
245 {
246 toolbox = null;
247 finishTest();
248 }
249 }

mercurial