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
|
"use strict";
// This test checks whether browser.theme.onUpdated works
// when a static theme is applied
add_task(async function test_on_updated() {
const theme = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
images: {
theme_frame: "image1.png",
},
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
},
},
},
files: {
"image1.png": BACKGROUND,
},
});
const extension = ExtensionTestUtils.loadExtension({
background() {
browser.theme.onUpdated.addListener(updateInfo => {
browser.test.sendMessage("theme-updated", updateInfo);
});
},
});
await extension.startup();
info("Testing update event on static theme startup");
let updatedPromise = extension.awaitMessage("theme-updated");
await theme.startup();
const { theme: receivedTheme, windowId } = await updatedPromise;
Assert.ok(!windowId, "No window id in static theme update event");
Assert.ok(
receivedTheme.images.theme_frame.includes("image1.png"),
"Theme theme_frame image should be applied"
);
Assert.equal(
receivedTheme.colors.frame,
ACCENT_COLOR,
"Theme frame color should be applied"
);
Assert.equal(
receivedTheme.colors.tab_background_text,
TEXT_COLOR,
"Theme tab_background_text color should be applied"
);
info("Testing update event on static theme unload");
updatedPromise = extension.awaitMessage("theme-updated");
await theme.unload();
const updateInfo = await updatedPromise;
Assert.ok(!windowId, "No window id in static theme update event on unload");
Assert.equal(
Object.keys(updateInfo.theme),
0,
"unloading theme sends empty theme in update event"
);
await extension.unload();
});
add_task(async function test_on_updated_eventpage() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.eventPages.enabled", true]],
});
const theme = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
images: {
theme_frame: "image1.png",
},
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
},
},
},
files: {
"image1.png": BACKGROUND,
},
});
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
browser_specific_settings: { gecko: { id: "watcher@mochitest" } },
background: { persistent: false },
},
background() {
browser.theme.onUpdated.addListener(updateInfo => {
browser.test.sendMessage("theme-updated", updateInfo);
});
},
});
await extension.startup();
assertPersistentListeners(extension, "theme", "onUpdated", {
primed: false,
});
await extension.terminateBackground();
assertPersistentListeners(extension, "theme", "onUpdated", {
primed: true,
});
info("Testing update event on static theme startup");
let updatedPromise = extension.awaitMessage("theme-updated");
await theme.startup();
const { theme: receivedTheme, windowId } = await updatedPromise;
Assert.ok(!windowId, "No window id in static theme update event");
Assert.ok(
receivedTheme.images.theme_frame.includes("image1.png"),
"Theme theme_frame image should be applied"
);
await theme.unload();
await extension.awaitMessage("theme-updated");
await extension.unload();
await SpecialPowers.popPrefEnv();
});
|