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
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
async function testSidebarBrowserStyle(sidebarAction, assertMessage) {
function sidebarScript() {
browser.test.onMessage.addListener((msgName, info, assertMessage) => {
if (msgName !== "check-style") {
browser.test.notifyFail("sidebar-browser-style");
}
let style = window.getComputedStyle(document.getElementById("button"));
let buttonBackgroundColor = style.backgroundColor;
let browserStyleBackgroundColor = "rgb(9, 150, 248)";
if (!("browser_style" in info) || info.browser_style) {
browser.test.assertEq(
browserStyleBackgroundColor,
buttonBackgroundColor,
assertMessage
);
} else {
browser.test.assertTrue(
browserStyleBackgroundColor !== buttonBackgroundColor,
assertMessage
);
}
browser.test.notifyPass("sidebar-browser-style");
});
browser.test.sendMessage("sidebar-ready");
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
sidebar_action: sidebarAction,
},
useAddonManager: "temporary",
files: {
"panel.html": `
<!DOCTYPE html>
<html>
<button id="button" name="button" class="browser-style default">Default</button>
<script src="panel.js" type="text/javascript"></script>
</html>`,
"panel.js": sidebarScript,
},
});
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
await extension.startup();
await extension.awaitMessage("sidebar-ready");
extension.sendMessage("check-style", sidebarAction, assertMessage);
await extension.awaitFinish("sidebar-browser-style");
await extension.unload();
BrowserTestUtils.removeTab(tab);
}
add_task(async function test_sidebar_without_setting_browser_style() {
await testSidebarBrowserStyle(
{
default_panel: "panel.html",
},
"Expected correct style when browser_style is excluded"
);
});
add_task(async function test_sidebar_with_browser_style_set_to_true() {
await testSidebarBrowserStyle(
{
default_panel: "panel.html",
browser_style: true,
},
"Expected correct style when browser_style is set to `true`"
);
});
add_task(async function test_sidebar_with_browser_style_set_to_false() {
await testSidebarBrowserStyle(
{
default_panel: "panel.html",
browser_style: false,
},
"Expected no style when browser_style is set to `false`"
);
});
|