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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Bug 566194 - safe mode / security & compatibility check status are not exposed in new addon manager UI
async function loadDetail(win, id) {
let loaded = waitForViewLoad(win);
// Check the detail view.
let card = win.document.querySelector(`addon-card[addon-id="${id}"]`);
EventUtils.synthesizeMouseAtCenter(
card.querySelector(".addon-name-link"),
{},
win
);
await loaded;
}
function checkMessageShown(win, type, hasButton) {
let stack = win.document.querySelector("global-warnings");
is(stack.childElementCount, 1, "There is one message");
let messageBar = stack.firstElementChild;
ok(messageBar, "There is a message bar");
is(
messageBar.localName,
"moz-message-bar",
"The message bar is a moz-message-bar"
);
is_element_visible(messageBar, "Message bar is visible");
is(messageBar.getAttribute("warning-type"), type);
if (hasButton) {
let button = messageBar.querySelector("button");
is_element_visible(button, "Button is visible");
is(button.getAttribute("action"), type, "Button action is set");
}
}
function checkNoMessages(win) {
let stack = win.document.querySelector("global-warnings");
if (stack.childElementCount) {
// The safe mode message is hidden in CSS on the plugin list.
for (let child of stack.children) {
is_element_hidden(child, "The message is hidden");
}
} else {
is(stack.childElementCount, 0, "There are no message bars");
}
}
function clickMessageAction(win) {
let stack = win.document.querySelector("global-warnings");
let button = stack.firstElementChild.querySelector("button");
EventUtils.synthesizeMouseAtCenter(button, {}, win);
}
add_task(async function checkCompatibility() {
info("Testing compatibility checking warning");
info("Setting checkCompatibility to false");
AddonManager.checkCompatibility = false;
let id = "test@mochi.test";
let extension = ExtensionTestUtils.loadExtension({
manifest: { browser_specific_settings: { gecko: { id } } },
useAddonManager: "temporary",
});
await extension.startup();
let win = await loadInitialView("extension");
// Check the extension list view.
checkMessageShown(win, "check-compatibility", true);
// Check the detail view.
await loadDetail(win, id);
checkMessageShown(win, "check-compatibility", true);
// Check other views.
let views = ["plugin", "theme"];
for (let view of views) {
await switchView(win, view);
checkMessageShown(win, "check-compatibility", true);
}
// Check the button works.
info("Clicking 'Enable' button");
clickMessageAction(win);
is(
AddonManager.checkCompatibility,
true,
"Check Compatibility pref should be cleared"
);
checkNoMessages(win);
await closeView(win);
await extension.unload();
});
add_task(async function checkSecurity() {
info("Testing update security checking warning");
var pref = "extensions.checkUpdateSecurity";
info("Setting " + pref + " pref to false");
await SpecialPowers.pushPrefEnv({
set: [[pref, false]],
});
let id = "test-security@mochi.test";
let extension = ExtensionTestUtils.loadExtension({
manifest: { browser_specific_settings: { gecko: { id } } },
useAddonManager: "temporary",
});
await extension.startup();
let win = await loadInitialView("extension");
// Check extension list view.
checkMessageShown(win, "update-security", true);
// Check detail view.
await loadDetail(win, id);
checkMessageShown(win, "update-security", true);
// Check other views.
let views = ["plugin", "theme"];
for (let view of views) {
await switchView(win, view);
checkMessageShown(win, "update-security", true);
}
// Check the button works.
info("Clicking 'Enable' button");
clickMessageAction(win);
is(
Services.prefs.prefHasUserValue(pref),
false,
"Check Update Security pref should be cleared"
);
checkNoMessages(win);
await closeView(win);
await extension.unload();
});
add_task(async function checkSafeMode() {
info("Testing safe mode warning");
let id = "test-safemode@mochi.test";
let extension = ExtensionTestUtils.loadExtension({
manifest: { browser_specific_settings: { gecko: { id } } },
useAddonManager: "temporary",
});
await extension.startup();
let win = await loadInitialView("extension");
// Check extension list view hidden.
checkNoMessages(win);
let globalWarnings = win.document.querySelector("global-warnings");
globalWarnings.inSafeMode = true;
globalWarnings.refresh();
// Check detail view.
await loadDetail(win, id);
checkMessageShown(win, "safe-mode");
// Check other views.
await switchView(win, "theme");
checkMessageShown(win, "safe-mode");
await switchView(win, "plugin");
checkNoMessages(win);
await closeView(win);
await extension.unload();
});
|