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
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(async function test_tab_options_modals() {
function backgroundScript() {
browser.runtime.openOptionsPage();
}
function optionsScript() {
try {
alert("WebExtensions OptionsUI Page Modal");
browser.test.notifyPass("options-ui-modals");
} catch (error) {
browser.test.log(`Error: ${error} :: ${error.stack}`);
browser.test.notifyFail("options-ui-modals");
}
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "temporary",
manifest: {
permissions: ["tabs"],
options_ui: {
page: "options.html",
},
},
files: {
"options.html": `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="options.js" type="text/javascript"></script>
</head>
</html>`,
"options.js": optionsScript,
},
background: backgroundScript,
});
await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:addons");
await extension.startup();
const onceModalOpened = new Promise(resolve => {
const aboutAddonsBrowser = gBrowser.selectedBrowser;
aboutAddonsBrowser.addEventListener(
"DOMWillOpenModalDialog",
function onModalDialog(event) {
// Wait for the next event tick to make sure the remaining part of the
// testcase runs after the dialog gets opened.
SimpleTest.executeSoon(resolve);
},
{ once: true, capture: true }
);
});
info("Wait the options_ui modal to be opened");
await onceModalOpened;
const optionsBrowser = getInlineOptionsBrowser(gBrowser.selectedBrowser);
// The stack that contains the tabmodalprompt elements is the parent of
// the extensions options_ui browser element.
let stack = optionsBrowser.parentNode;
let dialogs = stack.querySelectorAll("tabmodalprompt");
Assert.equal(
dialogs.length,
1,
"Expect a tab modal opened for the about addons tab"
);
// Verify that the expected stylesheets have been applied on the
// tabmodalprompt element (See Bug 1550529).
const tabmodalStyle = dialogs[0].ownerGlobal.getComputedStyle(dialogs[0]);
is(
tabmodalStyle["background-color"],
"rgba(26, 26, 26, 0.5)",
"Got the expected styles applied to the tabmodalprompt"
);
info("Close the tab modal prompt");
dialogs[0].querySelector(".tabmodalprompt-button0").click();
await extension.awaitFinish("options-ui-modals");
Assert.equal(
stack.querySelectorAll("tabmodalprompt").length,
0,
"Expect the tab modal to be closed"
);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await extension.unload();
});
|