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
|
"use strict";
add_task(async function theme_reset_global_static_theme() {
let global_theme_extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: "#123456",
tab_background_text: "#fedcba",
},
},
},
});
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["theme"],
},
async background() {
await browser.theme.reset();
let theme_after_reset = await browser.theme.getCurrent();
browser.test.assertEq(
"#123456",
theme_after_reset.colors.frame,
"Theme from other extension should not be cleared upon reset()"
);
let theme = {
colors: {
frame: "#CF723F",
},
};
await browser.theme.update(theme);
await browser.theme.reset();
let final_reset_theme = await browser.theme.getCurrent();
browser.test.assertEq(
JSON.stringify({ colors: null, images: null, properties: null }),
JSON.stringify(final_reset_theme),
"Should reset when extension had replaced the global theme"
);
browser.test.sendMessage("done");
},
});
await global_theme_extension.startup();
await extension.startup();
await extension.awaitMessage("done");
await global_theme_extension.unload();
await extension.unload();
});
add_task(async function theme_reset_by_windowId() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["theme"],
},
async background() {
let theme = {
colors: {
frame: "#CF723F",
},
};
let { id: winId } = await browser.windows.getCurrent();
await browser.theme.update(winId, theme);
let update_theme = await browser.theme.getCurrent(winId);
browser.test.onMessage.addListener(async () => {
let current_theme = await browser.theme.getCurrent(winId);
browser.test.assertEq(
update_theme.colors.frame,
current_theme.colors.frame,
"Should not be reset by a reset(windowId) call from another extension"
);
browser.test.sendMessage("done");
});
browser.test.sendMessage("ready", winId);
},
});
let anotherExtension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["theme"],
},
background() {
browser.test.onMessage.addListener(async winId => {
await browser.theme.reset(winId);
browser.test.sendMessage("done");
});
},
});
await extension.startup();
let winId = await extension.awaitMessage("ready");
await anotherExtension.startup();
// theme.reset should be ignored if the theme was set by another extension.
anotherExtension.sendMessage(winId);
await anotherExtension.awaitMessage("done");
extension.sendMessage();
await extension.awaitMessage("done");
await anotherExtension.unload();
await extension.unload();
});
|