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
177
178
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/*
* Test Permission Popup for Sideloaded Extensions.
*/
const { AddonTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/AddonTestUtils.sys.mjs"
);
const ADDON_ID = "addon1@test.mozilla.org";
const CUSTOM_THEME_ID = "theme1@test.mozilla.org";
const DEFAULT_THEME_ID = "default-theme@mozilla.org";
AddonTestUtils.initMochitest(this);
function assertDisabledSideloadedExtensionElement(managerWindow, addonElement) {
const doc = addonElement.ownerDocument;
const toggleDisabled = addonElement.querySelector(
'[action="toggle-disabled"]'
);
is(
doc.l10n.getAttributes(toggleDisabled).id,
"extension-enable-addon-button-label",
"Addon toggle-disabled action has the enable label"
);
ok(!toggleDisabled.checked, "toggle-disable isn't checked");
}
function assertEnabledSideloadedExtensionElement(managerWindow, addonElement) {
const doc = addonElement.ownerDocument;
const toggleDisabled = addonElement.querySelector(
'[action="toggle-disabled"]'
);
is(
doc.l10n.getAttributes(toggleDisabled).id,
"extension-enable-addon-button-label",
"Addon toggle-disabled action has the enable label"
);
ok(!toggleDisabled.checked, "toggle-disable isn't checked");
}
function clickEnableExtension(addonElement) {
addonElement.querySelector('[action="toggle-disabled"]').click();
}
// Test for bug 1647931
// Install a theme, enable it and then enable the default theme again
add_task(async function test_theme_enable() {
await SpecialPowers.pushPrefEnv({
set: [
["xpinstall.signatures.required", false],
["extensions.autoDisableScopes", 15],
["extensions.ui.ignoreUnsigned", true],
],
});
let theme = {
manifest: {
browser_specific_settings: { gecko: { id: CUSTOM_THEME_ID } },
name: "Theme 1",
theme: {
colors: {
frame: "#000000",
tab_background_text: "#ffffff",
},
},
},
};
let xpi = AddonTestUtils.createTempWebExtensionFile(theme);
await AddonTestUtils.manuallyInstall(xpi);
let changePromise = new Promise(resolve =>
ExtensionsUI.once("change", resolve)
);
ExtensionsUI._checkForSideloaded();
await changePromise;
// enable fresh installed theme
let manager = await open_manager("addons://list/theme");
let customTheme = getAddonCard(manager, CUSTOM_THEME_ID);
clickEnableExtension(customTheme);
// enable default theme again
let defaultTheme = getAddonCard(manager, DEFAULT_THEME_ID);
clickEnableExtension(defaultTheme);
let addon = await AddonManager.getAddonByID(CUSTOM_THEME_ID);
await close_manager(manager);
await addon.uninstall();
});
// Loading extension by sideloading method
add_task(async function test_sideloaded_extension_permissions_prompt() {
await SpecialPowers.pushPrefEnv({
set: [
["xpinstall.signatures.required", false],
["extensions.autoDisableScopes", 15],
["extensions.ui.ignoreUnsigned", true],
],
});
let options = {
manifest: {
browser_specific_settings: { gecko: { id: ADDON_ID } },
name: "Test 1",
permissions: ["history", "https://*/*"],
icons: { 64: "foo-icon.png" },
},
};
let xpi = AddonTestUtils.createTempWebExtensionFile(options);
await AddonTestUtils.manuallyInstall(xpi);
let changePromise = new Promise(resolve =>
ExtensionsUI.once("change", resolve)
);
ExtensionsUI._checkForSideloaded();
await changePromise;
// Test click event on permission cancel option.
let manager = await open_manager("addons://list/extension");
let addon = getAddonCard(manager, ADDON_ID);
Assert.notEqual(addon, null, "Found sideloaded addon in about:addons");
assertDisabledSideloadedExtensionElement(manager, addon);
let popupPromise = promisePopupNotificationShown("addon-webext-permissions");
clickEnableExtension(addon);
let panel = await popupPromise;
ok(PopupNotifications.isPanelOpen, "Permission popup should be visible");
panel.secondaryButton.click();
ok(
!PopupNotifications.isPanelOpen,
"Permission popup should be closed / closing"
);
addon = await AddonManager.getAddonByID(ADDON_ID);
ok(
!addon.seen,
"Seen flag should remain false after permissions are refused"
);
// Test click event on permission accept option.
addon = getAddonCard(manager, ADDON_ID);
Assert.notEqual(addon, null, "Found sideloaded addon in about:addons");
assertEnabledSideloadedExtensionElement(manager, addon);
popupPromise = promisePopupNotificationShown("addon-webext-permissions");
clickEnableExtension(addon);
panel = await popupPromise;
ok(PopupNotifications.isPanelOpen, "Permission popup should be visible");
let notificationPromise = acceptAppMenuNotificationWhenShown(
"addon-installed",
ADDON_ID
);
panel.button.click();
ok(
!PopupNotifications.isPanelOpen,
"Permission popup should be closed / closing"
);
await notificationPromise;
addon = await AddonManager.getAddonByID(ADDON_ID);
ok(addon.seen, "Seen flag should be true after permissions are accepted");
ok(!PopupNotifications.isPanelOpen, "Permission popup should not be visible");
await close_manager(manager);
await addon.uninstall();
});
|