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
|
/* 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";
const DEFAULT_THEME_ID = "default-theme@mozilla.org";
const LIGHT_THEME_ID = "firefox-compact-light@mozilla.org";
const DARK_THEME_ID = "firefox-compact-dark@mozilla.org";
const ALPENGLOW_THEME_ID = "firefox-alpenglow@mozilla.org";
const MAX_THEME_COUNT = 6; // Not exposed from CustomizeMode.jsm
const { _defaultImportantThemes } = ChromeUtils.import(
"resource:///modules/CustomizeMode.jsm"
);
async function installTheme(id) {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
applications: { gecko: { id } },
manifest_version: 2,
name: "Theme " + id,
description: "wow. such theme.",
author: "Pixel Pusher",
version: "1",
theme: {},
},
useAddonManager: "temporary",
});
await extension.startup();
return extension;
}
add_task(async function() {
await startCustomizing();
// Check restore defaults button is disabled.
ok(
document.getElementById("customization-reset-button").disabled,
"Reset button should start out disabled"
);
let themesButton = document.getElementById("customization-lwtheme-button");
let themesButtonIcon = themesButton.icon;
let iconURL = themesButtonIcon.style.backgroundImage;
// If we've run other tests before, we might have set the image to the
// default theme's icon explicitly, otherwise it might be empty, in which
// case the icon is determined by CSS (which will be the default
// theme's icon).
if (iconURL) {
ok(
/default/i.test(themesButtonIcon.style.backgroundImage),
`Button should show default theme thumbnail - was: "${iconURL}"`
);
} else {
is(
iconURL,
"",
`Button should show default theme thumbnail (empty string) - was: "${iconURL}"`
);
}
let popup = document.getElementById("customization-lwtheme-menu");
let popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button");
await popupShownPromise;
// close current tab and re-open Customize menu to confirm correct number of Themes
await endCustomizing();
info("Exited customize mode");
await startCustomizing();
info("Started customizing a second time");
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a second time");
await popupShownPromise;
let header = document.getElementById("customization-lwtheme-menu-header");
let footer = document.getElementById("customization-lwtheme-menu-footer");
let menu = document.getElementById("customization-lwtheme-menu");
let themeMenuItems = menu.querySelectorAll(
"toolbarbutton.customization-lwtheme-menu-theme"
);
is(
themeMenuItems.length,
_defaultImportantThemes.length,
"There should only be four themes (default, light, dark, alpenglow) in the 'My Themes' section by default"
);
// Note that we use our own theme ID constants in the
// following tests because we want to test things are
// displayed in the proper order, not just in the order
// that constants in the code happens to be in.
is(
themeMenuItems[0].theme.id,
DEFAULT_THEME_ID,
"The first theme should be the default theme"
);
is(
themeMenuItems[1].theme.id,
LIGHT_THEME_ID,
"The second theme should be the light theme"
);
is(
themeMenuItems[2].theme.id,
DARK_THEME_ID,
"The third theme should be the dark theme"
);
is(
themeMenuItems[3].theme.id,
ALPENGLOW_THEME_ID,
"The fourth theme should be the alpenglow theme"
);
let themeChangedPromise = promiseObserverNotified(
"lightweight-theme-styling-update"
);
header.nextElementSibling.nextElementSibling.doCommand(); // Select light theme
info("Clicked on light theme");
await themeChangedPromise;
let button = document.getElementById("customization-reset-button");
await TestUtils.waitForCondition(() => !button.disabled);
// Check restore defaults button is enabled.
ok(!button.disabled, "Reset button should not be disabled anymore");
ok(
/light/i.test(themesButtonIcon.style.backgroundImage),
`Button should show light theme thumbnail - was: "${themesButtonIcon.style.backgroundImage}"`
);
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a third time");
await popupShownPromise;
let activeThemes = popup.querySelectorAll(
"toolbarbutton.customization-lwtheme-menu-theme[active]"
);
is(activeThemes.length, 1, "Exactly 1 theme should be selected");
if (activeThemes.length) {
is(
activeThemes[0].theme.id,
LIGHT_THEME_ID,
"Light theme should be selected"
);
}
popup.hidePopup();
// Install 5 themes:
let addons = [];
for (let n = 1; n <= 5; n++) {
addons.push(await installTheme("my-theme-" + n + "@example.com"));
}
addons = await Promise.all(addons);
ok(
!themesButtonIcon.style.backgroundImage,
`Button should show fallback theme thumbnail - was: "${themesButtonIcon.style.backgroundImage}"`
);
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a fourth time");
await popupShownPromise;
activeThemes = popup.querySelectorAll(
"toolbarbutton.customization-lwtheme-menu-theme[active]"
);
is(activeThemes.length, 1, "Exactly 1 theme should be selected");
if (activeThemes.length) {
is(
activeThemes[0].theme.id,
"my-theme-5@example.com",
"Last installed theme should be selected"
);
}
let firstLWTheme = footer.previousElementSibling;
let firstLWThemeId = firstLWTheme.theme.id;
themeChangedPromise = promiseObserverNotified(
"lightweight-theme-styling-update"
);
firstLWTheme.doCommand();
info("Clicked on first theme");
await themeChangedPromise;
await new Promise(executeSoon);
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button");
await popupShownPromise;
activeThemes = popup.querySelectorAll(
"toolbarbutton.customization-lwtheme-menu-theme[active]"
);
is(activeThemes.length, 1, "Exactly 1 theme should be selected");
if (activeThemes.length) {
is(
activeThemes[0].theme.id,
firstLWThemeId,
"First theme should be selected"
);
}
is(
header.nextElementSibling.theme.id,
DEFAULT_THEME_ID,
"The first theme should be the Default theme"
);
let themeCount = 0;
let iterNode = header;
while (iterNode.nextElementSibling && iterNode.nextElementSibling.theme) {
themeCount++;
iterNode = iterNode.nextElementSibling;
}
is(
themeCount,
MAX_THEME_COUNT,
"There should be the max number of themes in the 'My Themes' section"
);
let defaultTheme = header.nextElementSibling;
defaultTheme.doCommand();
await new Promise(SimpleTest.executeSoon);
// ensure current theme isn't set to "Default"
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a sixth time");
await popupShownPromise;
// check that "Restore Defaults" button resets theme
await gCustomizeMode.reset();
defaultTheme = await AddonManager.getAddonByID(DEFAULT_THEME_ID);
is(defaultTheme.isActive, true, "Current theme reset to default");
await endCustomizing();
await startCustomizing();
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a seventh time");
await popupShownPromise;
header = document.getElementById("customization-lwtheme-menu-header");
is(header.hidden, false, "Header should never be hidden");
let themeNode = header.nextElementSibling;
is(
themeNode.theme.id,
DEFAULT_THEME_ID,
"The first theme should be the Default theme"
);
is(themeNode.hidden, false, "The default theme should never be hidden");
themeNode = themeNode.nextElementSibling;
is(
themeNode.theme.id,
LIGHT_THEME_ID,
"The second theme should be the Light theme"
);
is(themeNode.hidden, false, "The light theme should never be hidden");
themeNode = themeNode.nextElementSibling;
is(
themeNode.theme.id,
DARK_THEME_ID,
"The third theme should be the Dark theme"
);
is(themeNode.hidden, false, "The dark theme should never be hidden");
await Promise.all(addons.map(a => a.unload()));
});
add_task(async function asyncCleanup() {
await endCustomizing();
});
|