summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_minimize.js
blob: 9b512632038b03955e70d63b1d71f427a8651808 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that when the toolbox is displayed in a bottom host, that host can be
// minimized to just the tabbar height, and maximized again.
// Also test that while minimized, switching to a tool, clicking on the
// settings, or clicking on the selected tool's tab maximizes the toolbox again.
// Finally test that the minimize button doesn't exist in other host types.

const URL = "data:text/html;charset=utf8,test page";
const {Toolbox} = require("devtools/client/framework/toolbox");

add_task(function* () {
  info("Create a test tab and open the toolbox");
  let tab = yield addTab(URL);
  let target = TargetFactory.forTab(tab);
  let toolbox = yield gDevTools.showToolbox(target, "webconsole");

  let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  ok(button, "The minimize button exists in the default bottom host");

  info("Try to minimize the toolbox");
  yield minimize(toolbox);
  ok(parseInt(toolbox._host.frame.style.marginBottom, 10) < 0,
     "The toolbox host has been hidden away with a negative-margin");

  info("Try to maximize again the toolbox");
  yield maximize(toolbox);
  ok(parseInt(toolbox._host.frame.style.marginBottom, 10) == 0,
     "The toolbox host is shown again");

  info("Try to minimize again using the keyboard shortcut");
  yield minimizeWithShortcut(toolbox);
  ok(parseInt(toolbox._host.frame.style.marginBottom, 10) < 0,
     "The toolbox host has been hidden away with a negative-margin");

  info("Try to maximize again using the keyboard shortcut");
  yield maximizeWithShortcut(toolbox);
  ok(parseInt(toolbox._host.frame.style.marginBottom, 10) == 0,
     "The toolbox host is shown again");

  info("Minimize again and switch to another tool");
  yield minimize(toolbox);
  let onMaximized = toolbox._host.once("maximized");
  yield toolbox.selectTool("inspector");
  yield onMaximized;

  info("Minimize again and click on the tab of the current tool");
  yield minimize(toolbox);
  onMaximized = toolbox._host.once("maximized");
  let tabButton = toolbox.doc.querySelector("#toolbox-tab-inspector");
  EventUtils.synthesizeMouseAtCenter(tabButton, {}, toolbox.win);
  yield onMaximized;

  info("Minimize again and click on the settings tab");
  yield minimize(toolbox);
  onMaximized = toolbox._host.once("maximized");
  let settingsButton = toolbox.doc.querySelector("#toolbox-tab-options");
  EventUtils.synthesizeMouseAtCenter(settingsButton, {}, toolbox.win);
  yield onMaximized;

  info("Switch to a different host");
  yield toolbox.switchHost(Toolbox.HostType.SIDE);
  button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  ok(!button, "The minimize button doesn't exist in the side host");

  Services.prefs.clearUserPref("devtools.toolbox.host");
  yield toolbox.destroy();
  gBrowser.removeCurrentTab();
});

function* minimize(toolbox) {
  let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  let onMinimized = toolbox._host.once("minimized");
  EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win);
  yield onMinimized;
}

function* minimizeWithShortcut(toolbox) {
  let key = toolbox.doc.getElementById("toolbox-minimize-key")
                       .getAttribute("key");
  let onMinimized = toolbox._host.once("minimized");
  EventUtils.synthesizeKey(key, {accelKey: true, shiftKey: true},
                           toolbox.win);
  yield onMinimized;
}

function* maximize(toolbox) {
  let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
  let onMaximized = toolbox._host.once("maximized");
  EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win);
  yield onMaximized;
}

function* maximizeWithShortcut(toolbox) {
  let key = toolbox.doc.getElementById("toolbox-minimize-key")
                       .getAttribute("key");
  let onMaximized = toolbox._host.once("maximized");
  EventUtils.synthesizeKey(key, {accelKey: true, shiftKey: true},
                           toolbox.win);
  yield onMaximized;
}