summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_split.js
blob: 7253e3f7a56a9f8f2e1337735607a8812ea1d98e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_URI =
  "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for splitting";

// Test is slow on Linux EC2 instances - Bug 962931
requestLongerTimeout(4);

add_task(async function () {
  let toolbox;
  const getFluentString = await getFluentStringHelper([
    "devtools/client/toolbox.ftl",
  ]);
  const hideSplitConsoleLabel = getFluentString(
    "toolbox-meatball-menu-hideconsole-label"
  );

  await addTab(TEST_URI);
  await testConsoleLoadOnDifferentPanel();
  await testKeyboardShortcuts();
  await checkAllTools();

  info("Testing host types");
  checkHostType(Toolbox.HostType.BOTTOM);
  await checkToolboxUI();
  await toolbox.switchHost(Toolbox.HostType.RIGHT);
  checkHostType(Toolbox.HostType.RIGHT);
  await checkToolboxUI();
  await toolbox.switchHost(Toolbox.HostType.WINDOW);

  // checkHostType, below,  will open the meatball menu to read the "Split
  // console" menu item label. However, if we've just opened a new window then
  // on some platforms when we switch focus to the new window we might end up
  // triggering the auto-close behavior on the menu popup. To avoid that, wait
  // a moment before querying the menu.
  await new Promise(resolve => requestIdleCallback(resolve));

  checkHostType(Toolbox.HostType.WINDOW);
  await checkToolboxUI();
  await toolbox.switchHost(Toolbox.HostType.BOTTOM);

  async function testConsoleLoadOnDifferentPanel() {
    info("About to check console loads even when non-webconsole panel is open");

    await openPanel("inspector");
    const webconsoleReady = toolbox.once("webconsole-ready");
    await toolbox.toggleSplitConsole();
    await webconsoleReady;
    ok(
      true,
      "Webconsole has been triggered as loaded while another tool is active"
    );
  }

  async function testKeyboardShortcuts() {
    info("About to check that panel responds to ESCAPE keyboard shortcut");

    const splitConsoleReady = toolbox.once("split-console");
    EventUtils.sendKey("ESCAPE", toolbox.win);
    await splitConsoleReady;
    ok(true, "Split console has been triggered via ESCAPE keypress");
  }

  async function checkAllTools() {
    info("About to check split console with each panel individually.");
    await openAndCheckPanel("jsdebugger");
    await openAndCheckPanel("inspector");
    await openAndCheckPanel("styleeditor");
    await openAndCheckPanel("performance");
    await openAndCheckPanel("netmonitor");

    await checkWebconsolePanelOpened();
  }

  async function getCurrentUIState() {
    const deck = toolbox.doc.querySelector("#toolbox-deck");
    const webconsolePanel = toolbox.webconsolePanel;
    const splitter = toolbox.doc.querySelector("#toolbox-console-splitter");

    const containerHeight = deck.parentNode.getBoundingClientRect().height;
    const deckHeight = deck.getBoundingClientRect().height;
    const webconsoleHeight = webconsolePanel.getBoundingClientRect().height;
    const splitterVisibility = !splitter.hidden;
    // Splitter height will be 1px since the margin is negative.
    const splitterHeight = splitterVisibility ? 1 : 0;
    const openedConsolePanel = toolbox.currentToolId === "webconsole";
    const menuLabel = await getMenuLabel(toolbox);

    return {
      deckHeight,
      containerHeight,
      webconsoleHeight,
      splitterVisibility,
      splitterHeight,
      openedConsolePanel,
      menuLabel,
    };
  }

  async function getMenuLabel() {
    const button = toolbox.doc.getElementById("toolbox-meatball-menu-button");
    const onPopupShown = new Promise(
      resolve => {
        toolbox.doc.addEventListener("popupshown", () => resolve());
      },
      { once: true }
    );
    info("Click on menu and wait for the popup to be visible");
    AccessibilityUtils.setEnv({
      // Toobox toolbar buttons are handled with arrow keys.
      nonNegativeTabIndexRule: false,
    });
    EventUtils.sendMouseEvent({ type: "click" }, button);
    AccessibilityUtils.resetEnv();
    await onPopupShown;

    const menuItem = toolbox.doc.getElementById(
      "toolbox-meatball-menu-splitconsole"
    );

    // Return undefined if the menu item is not available
    let label;
    if (menuItem && menuItem.querySelector(".label")) {
      label =
        menuItem.querySelector(".label").textContent === hideSplitConsoleLabel
          ? "hide"
          : "split";
    }

    // Wait for menu to close
    const onPopupHide = new Promise(resolve => {
      toolbox.doc.addEventListener(
        "popuphidden",
        () => {
          resolve(label);
        },
        { once: true }
      );
    });
    info("Hit escape and wait for the popup to be closed");
    EventUtils.sendKey("ESCAPE", toolbox.win);
    await onPopupHide;

    return label;
  }

  async function checkWebconsolePanelOpened() {
    info("About to check special cases when webconsole panel is open.");

    // Start with console split, so we can test for transition to main panel.
    await toolbox.toggleSplitConsole();

    let currentUIState = await getCurrentUIState();

    ok(
      currentUIState.splitterVisibility,
      "Splitter is visible when console is split"
    );
    Assert.greater(
      currentUIState.deckHeight,
      0,
      "Deck has a height > 0 when console is split"
    );
    Assert.greater(
      currentUIState.webconsoleHeight,
      0,
      "Web console has a height > 0 when console is split"
    );
    ok(
      !currentUIState.openedConsolePanel,
      "The console panel is not the current tool"
    );
    is(
      currentUIState.menuLabel,
      "hide",
      "The menu item indicates the console is split"
    );

    await openPanel("webconsole");
    currentUIState = await getCurrentUIState();

    ok(
      !currentUIState.splitterVisibility,
      "Splitter is hidden when console is opened."
    );
    is(
      currentUIState.deckHeight,
      0,
      "Deck has a height == 0 when console is opened."
    );
    is(
      currentUIState.webconsoleHeight,
      currentUIState.containerHeight,
      "Web console is full height."
    );
    ok(
      currentUIState.openedConsolePanel,
      "The console panel is the current tool"
    );
    is(
      currentUIState.menuLabel,
      undefined,
      "The menu item is hidden when console is opened"
    );

    // Make sure splitting console does nothing while webconsole is opened
    await toolbox.toggleSplitConsole();

    currentUIState = await getCurrentUIState();

    ok(
      !currentUIState.splitterVisibility,
      "Splitter is hidden when console is opened."
    );
    is(
      currentUIState.deckHeight,
      0,
      "Deck has a height == 0 when console is opened."
    );
    is(
      currentUIState.webconsoleHeight,
      currentUIState.containerHeight,
      "Web console is full height."
    );
    ok(
      currentUIState.openedConsolePanel,
      "The console panel is the current tool"
    );
    is(
      currentUIState.menuLabel,
      undefined,
      "The menu item is hidden when console is opened"
    );

    // Make sure that split state is saved after opening another panel
    await openPanel("inspector");
    currentUIState = await getCurrentUIState();
    ok(
      currentUIState.splitterVisibility,
      "Splitter is visible when console is split"
    );
    Assert.greater(
      currentUIState.deckHeight,
      0,
      "Deck has a height > 0 when console is split"
    );
    Assert.greater(
      currentUIState.webconsoleHeight,
      0,
      "Web console has a height > 0 when console is split"
    );
    ok(
      !currentUIState.openedConsolePanel,
      "The console panel is not the current tool"
    );
    is(
      currentUIState.menuLabel,
      "hide",
      "The menu item still indicates the console is split"
    );

    await toolbox.toggleSplitConsole();
  }

  async function checkToolboxUI() {
    let currentUIState = await getCurrentUIState();

    ok(!currentUIState.splitterVisibility, "Splitter is hidden by default");
    is(
      currentUIState.deckHeight,
      currentUIState.containerHeight,
      "Deck has a height > 0 by default"
    );
    is(
      currentUIState.webconsoleHeight,
      0,
      "Web console is collapsed by default"
    );
    ok(
      !currentUIState.openedConsolePanel,
      "The console panel is not the current tool"
    );
    is(
      currentUIState.menuLabel,
      "split",
      "The menu item indicates the console is not split"
    );

    await toolbox.toggleSplitConsole();

    currentUIState = await getCurrentUIState();

    ok(
      currentUIState.splitterVisibility,
      "Splitter is visible when console is split"
    );
    Assert.greater(
      currentUIState.deckHeight,
      0,
      "Deck has a height > 0 when console is split"
    );
    Assert.greater(
      currentUIState.webconsoleHeight,
      0,
      "Web console has a height > 0 when console is split"
    );
    is(
      Math.round(
        currentUIState.deckHeight +
          currentUIState.webconsoleHeight +
          currentUIState.splitterHeight
      ),
      Math.round(currentUIState.containerHeight),
      "Everything adds up to container height"
    );
    ok(
      !currentUIState.openedConsolePanel,
      "The console panel is not the current tool"
    );
    is(
      currentUIState.menuLabel,
      "hide",
      "The menu item indicates the console is split"
    );

    await toolbox.toggleSplitConsole();

    currentUIState = await getCurrentUIState();

    ok(!currentUIState.splitterVisibility, "Splitter is hidden after toggling");
    is(
      currentUIState.deckHeight,
      currentUIState.containerHeight,
      "Deck has a height > 0 after toggling"
    );
    is(
      currentUIState.webconsoleHeight,
      0,
      "Web console is collapsed after toggling"
    );
    ok(
      !currentUIState.openedConsolePanel,
      "The console panel is not the current tool"
    );
    is(
      currentUIState.menuLabel,
      "split",
      "The menu item indicates the console is not split"
    );
  }

  async function openPanel(toolId) {
    const tab = gBrowser.selectedTab;
    toolbox = await gDevTools.showToolboxForTab(tab, { toolId });
  }

  async function openAndCheckPanel(toolId) {
    await openPanel(toolId);
    await checkToolboxUI(toolbox.getCurrentPanel());
  }

  function checkHostType(hostType) {
    is(toolbox.hostType, hostType, "host type is " + hostType);

    const pref = Services.prefs.getCharPref("devtools.toolbox.host");
    is(pref, hostType, "host pref is " + hostType);
  }
});