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
|
"use strict";
// This test checks whether applied WebExtension themes that attempt to change
// the background color and the color of the navbar text fields are applied properly.
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
add_setup(async function () {
await gCUITestUtils.addSearchBar();
registerCleanupFunction(() => {
gCUITestUtils.removeSearchBar();
});
});
add_task(async function test_support_toolbar_field_properties() {
const TOOLBAR_FIELD_BACKGROUND = "#ff00ff";
const TOOLBAR_FIELD_COLOR = "#00ff00";
const TOOLBAR_FIELD_BORDER = "#aaaaff";
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
images: {
theme_frame: "image1.png",
},
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
toolbar_field: TOOLBAR_FIELD_BACKGROUND,
toolbar_field_text: TOOLBAR_FIELD_COLOR,
toolbar_field_border: TOOLBAR_FIELD_BORDER,
},
},
},
files: {
"image1.png": BACKGROUND,
},
});
await extension.startup();
let root = document.documentElement;
// Remove the `remotecontrol` attribute since it interferes with the urlbar styling.
root.removeAttribute("remotecontrol");
registerCleanupFunction(() => {
root.setAttribute("remotecontrol", "true");
});
let fields = [
document.querySelector("#urlbar-background"),
BrowserSearch.searchBar,
].filter(field => {
let bounds = field.getBoundingClientRect();
return bounds.width > 0 && bounds.height > 0;
});
Assert.equal(fields.length, 2, "Should be testing two elements");
info(
`Checking toolbar background colors and colors for ${fields.length} toolbar fields.`
);
for (let field of fields) {
info(`Testing ${field.id || field.className}`);
Assert.equal(
window.getComputedStyle(field).backgroundColor,
hexToCSS(TOOLBAR_FIELD_BACKGROUND),
"Field background should be set."
);
Assert.equal(
window.getComputedStyle(field).color,
hexToCSS(TOOLBAR_FIELD_COLOR),
"Field color should be set."
);
testBorderColor(field, TOOLBAR_FIELD_BORDER);
}
await extension.unload();
});
add_task(async function test_support_toolbar_field_brighttext() {
let root = document.documentElement;
// Remove the `remotecontrol` attribute since it interferes with the urlbar styling.
root.removeAttribute("remotecontrol");
registerCleanupFunction(() => {
root.setAttribute("remotecontrol", "true");
});
let urlbar = gURLBar.textbox;
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
toolbar_field: "#fff",
toolbar_field_text: "#000",
},
},
},
});
await extension.startup();
Assert.equal(
window.getComputedStyle(urlbar).color,
hexToCSS("#000000"),
"Color has been set"
);
Assert.ok(
!root.hasAttribute("lwt-toolbar-field-brighttext"),
"Brighttext attribute should not be set"
);
await extension.unload();
extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
toolbar_field: "#000",
toolbar_field_text: "#fff",
},
},
},
});
await extension.startup();
Assert.equal(
window.getComputedStyle(urlbar).color,
hexToCSS("#ffffff"),
"Color has been set"
);
Assert.ok(
root.hasAttribute("lwt-toolbar-field-brighttext"),
"Brighttext attribute should be set"
);
await extension.unload();
});
// Verifies that we apply the lwt-toolbar-field-brighttext attribute when
// toolbar fields are dark text on a dark background.
add_task(async function test_support_toolbar_field_brighttext_dark_on_dark() {
let root = document.documentElement;
// Remove the `remotecontrol` attribute since it interferes with the urlbar styling.
root.removeAttribute("remotecontrol");
registerCleanupFunction(() => {
root.setAttribute("remotecontrol", "true");
});
let urlbar = gURLBar.textbox;
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
toolbar_field: "#000",
toolbar_field_text: "#111111",
},
},
},
});
await extension.startup();
Assert.equal(
window.getComputedStyle(urlbar).color,
hexToCSS("#111111"),
"Color has been set"
);
Assert.ok(
root.hasAttribute("lwt-toolbar-field-brighttext"),
"Brighttext attribute should be set"
);
await extension.unload();
});
|