summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_938980_navbar_collapsed.js
blob: 28b75c0a37cff28d56bb5f2afeff48d7aa01a873 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

requestLongerTimeout(2);

var bookmarksToolbar = document.getElementById("PersonalToolbar");
var navbar = document.getElementById("nav-bar");
var tabsToolbar = document.getElementById("TabsToolbar");

// Customization reset should restore visibility to default-visible toolbars.
add_task(async function () {
  is(navbar.collapsed, false, "Test should start with navbar visible");
  setToolbarVisibility(navbar, false);
  is(navbar.collapsed, true, "navbar should be hidden now");

  await resetCustomization();

  is(
    navbar.collapsed,
    false,
    "Customization reset should restore visibility to the navbar"
  );
});

// Customization reset should restore collapsed-state to default-collapsed toolbars.
add_task(async function () {
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be in its default state"
  );

  is(
    bookmarksToolbar.collapsed,
    true,
    "Test should start with bookmarks toolbar collapsed"
  );
  ok(bookmarksToolbar.collapsed, "bookmarksToolbar should be collapsed");
  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
  is(navbar.collapsed, false, "The nav-bar should be shown by default");

  setToolbarVisibility(bookmarksToolbar, true);
  setToolbarVisibility(navbar, false);
  ok(!bookmarksToolbar.collapsed, "bookmarksToolbar should be visible now");
  ok(navbar.collapsed, "navbar should be collapsed");
  is(
    CustomizableUI.inDefaultState,
    false,
    "Should no longer be in default state"
  );

  await startCustomizing();
  await gCustomizeMode.reset();
  await endCustomizing();

  is(
    bookmarksToolbar.collapsed,
    true,
    "Customization reset should restore collapsed-state to the bookmarks toolbar"
  );
  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
  ok(
    bookmarksToolbar.collapsed,
    "The bookmarksToolbar should be collapsed after reset"
  );
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be back to default state"
  );
});

// Check that the menubar will be collapsed by resetting, if the platform supports it.
add_task(async function () {
  let menubar = document.getElementById("toolbar-menubar");
  const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(
    menubar.id
  );
  if (!canMenubarCollapse) {
    return;
  }
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be in its default state"
  );

  is(
    menubar.getBoundingClientRect().height,
    0,
    "menubar should be hidden by default"
  );
  setToolbarVisibility(menubar, true);
  isnot(
    menubar.getBoundingClientRect().height,
    0,
    "menubar should be visible now"
  );

  await startCustomizing();
  await gCustomizeMode.reset();

  is(
    menubar.getAttribute("autohide"),
    "true",
    "The menubar should have autohide=true after reset in customization mode"
  );
  is(
    menubar.getBoundingClientRect().height,
    0,
    "The menubar should have height=0 after reset in customization mode"
  );

  await endCustomizing();

  is(
    menubar.getAttribute("autohide"),
    "true",
    "The menubar should have autohide=true after reset"
  );
  is(
    menubar.getBoundingClientRect().height,
    0,
    "The menubar should have height=0 after reset"
  );
});

// Customization reset should restore collapsed-state to default-collapsed toolbars.
add_task(async function () {
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be in its default state"
  );
  ok(bookmarksToolbar.collapsed, "bookmarksToolbar should be collapsed");
  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");

  setToolbarVisibility(bookmarksToolbar, true);
  ok(!bookmarksToolbar.collapsed, "bookmarksToolbar should be visible now");
  is(
    CustomizableUI.inDefaultState,
    false,
    "Should no longer be in default state"
  );

  await startCustomizing();

  ok(
    !bookmarksToolbar.collapsed,
    "The bookmarksToolbar should be visible before reset"
  );
  ok(!navbar.collapsed, "The navbar should be visible before reset");
  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");

  await gCustomizeMode.reset();

  ok(
    bookmarksToolbar.collapsed,
    "The bookmarksToolbar should be collapsed after reset"
  );
  ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
  ok(!navbar.collapsed, "The navbar should still be visible after reset");
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be back to default state"
  );
  await endCustomizing();
});

// Check that the menubar will be collapsed by resetting, if the platform supports it.
add_task(async function () {
  let menubar = document.getElementById("toolbar-menubar");
  const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(
    menubar.id
  );
  if (!canMenubarCollapse) {
    return;
  }
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be in its default state"
  );
  await startCustomizing();
  let resetButton = document.getElementById("customization-reset-button");
  is(
    resetButton.disabled,
    true,
    "The reset button should be disabled when in default state"
  );

  setToolbarVisibility(menubar, true);
  is(
    resetButton.disabled,
    false,
    "The reset button should be enabled when not in default state"
  );
  ok(
    !CustomizableUI.inDefaultState,
    "No longer in default state when the menubar is shown"
  );

  await gCustomizeMode.reset();

  is(
    resetButton.disabled,
    true,
    "The reset button should be disabled when in default state"
  );
  ok(
    CustomizableUI.inDefaultState,
    "Everything should be in its default state"
  );

  await endCustomizing();
});