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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests that upgrading bootstrapped add-ons behaves correctly while the
// manager is open
const { AddonTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/AddonTestUtils.sys.mjs"
);
const ID = "reinstall@tests.mozilla.org";
const testIdSuffix = "@tests.mozilla.org";
let gManagerWindow, xpi1, xpi2;
function htmlDoc() {
return gManagerWindow.document;
}
function get_list_item_count() {
return htmlDoc().querySelectorAll(`addon-card[addon-id$="${testIdSuffix}"]`)
.length;
}
function removeItem(item) {
let button = item.querySelector('[action="remove"]');
button.click();
}
function hasPendingMessage(item, msg) {
let messageBar = htmlDoc().querySelector(
`moz-message-bar[addon-id="${item.addon.id}"`
);
is_element_visible(messageBar, msg);
}
async function install_addon(xpi) {
let install = await AddonManager.getInstallForFile(
xpi,
"application/x-xpinstall"
);
return install.install();
}
async function check_addon(aAddon, aVersion) {
is(get_list_item_count(), 1, "Should be one item in the list");
is(aAddon.version, aVersion, "Add-on should have the right version");
let item = getAddonCard(gManagerWindow, ID);
ok(!!item, "Should see the add-on in the list");
// Force XBL to apply
item.clientTop;
let { version } = await get_tooltip_info(item, gManagerWindow);
is(version, aVersion, "Version should be correct");
const l10nAttrs = item.ownerDocument.l10n.getAttributes(item.addonNameEl);
if (aAddon.userDisabled) {
Assert.deepEqual(
l10nAttrs,
{ id: "addon-name-disabled", args: { name: aAddon.name } },
"localized addon name is marked as disabled"
);
} else {
Assert.deepEqual(
l10nAttrs,
{ id: null, args: null },
"localized addon name is not marked as disabled"
);
}
}
async function wait_for_addon_item_added(addonId) {
await BrowserTestUtils.waitForEvent(
htmlDoc().querySelector("addon-list"),
"add"
);
const item = getAddonCard(gManagerWindow, addonId);
ok(item, `Found addon card for ${addonId}`);
}
async function wait_for_addon_item_removed(addonId) {
await BrowserTestUtils.waitForEvent(
htmlDoc().querySelector("addon-list"),
"remove"
);
const item = getAddonCard(gManagerWindow, addonId);
ok(!item, `There shouldn't be an addon card for ${addonId}`);
}
function wait_for_addon_item_updated(addonId) {
return BrowserTestUtils.waitForEvent(
getAddonCard(gManagerWindow, addonId),
"update"
);
}
// Install version 1 then upgrade to version 2 with the manager open
async function test_upgrade_v1_to_v2() {
let promiseItemAdded = wait_for_addon_item_added(ID);
await install_addon(xpi1);
await promiseItemAdded;
let addon = await promiseAddonByID(ID);
await check_addon(addon, "1.0");
ok(!addon.userDisabled, "Add-on should not be disabled");
let promiseItemUpdated = wait_for_addon_item_updated(ID);
await install_addon(xpi2);
await promiseItemUpdated;
addon = await promiseAddonByID(ID);
await check_addon(addon, "2.0");
ok(!addon.userDisabled, "Add-on should not be disabled");
let promiseItemRemoved = wait_for_addon_item_removed(ID);
await addon.uninstall();
await promiseItemRemoved;
is(get_list_item_count(), 0, "Should be no items in the list");
}
// Install version 1 mark it as disabled then upgrade to version 2 with the
// manager open
async function test_upgrade_disabled_v1_to_v2() {
let promiseItemAdded = wait_for_addon_item_added(ID);
await install_addon(xpi1);
await promiseItemAdded;
let promiseItemUpdated = wait_for_addon_item_updated(ID);
let addon = await promiseAddonByID(ID);
await addon.disable();
await promiseItemUpdated;
await check_addon(addon, "1.0");
ok(addon.userDisabled, "Add-on should be disabled");
promiseItemUpdated = wait_for_addon_item_updated(ID);
await install_addon(xpi2);
await promiseItemUpdated;
addon = await promiseAddonByID(ID);
await check_addon(addon, "2.0");
ok(addon.userDisabled, "Add-on should be disabled");
let promiseItemRemoved = wait_for_addon_item_removed(ID);
await addon.uninstall();
await promiseItemRemoved;
is(get_list_item_count(), 0, "Should be no items in the list");
}
// Install version 1 click the remove button and then upgrade to version 2 with
// the manager open
async function test_upgrade_pending_uninstall_v1_to_v2() {
let promiseItemAdded = wait_for_addon_item_added(ID);
await install_addon(xpi1);
await promiseItemAdded;
let addon = await promiseAddonByID(ID);
await check_addon(addon, "1.0");
ok(!addon.userDisabled, "Add-on should not be disabled");
let item = getAddonCard(gManagerWindow, ID);
let promiseItemRemoved = wait_for_addon_item_removed(ID);
removeItem(item);
// Force XBL to apply
item.clientTop;
await promiseItemRemoved;
ok(
!!(addon.pendingOperations & AddonManager.PENDING_UNINSTALL),
"Add-on should be pending uninstall"
);
hasPendingMessage(item, "Pending message should be visible");
promiseItemAdded = wait_for_addon_item_added(ID);
await install_addon(xpi2);
await promiseItemAdded;
addon = await promiseAddonByID(ID);
await check_addon(addon, "2.0");
ok(!addon.userDisabled, "Add-on should not be disabled");
promiseItemRemoved = wait_for_addon_item_removed(ID);
await addon.uninstall();
await promiseItemRemoved;
is(get_list_item_count(), 0, "Should be no items in the list");
}
// Install version 1, disable it, click the remove button and then upgrade to
// version 2 with the manager open
async function test_upgrade_pending_uninstall_disabled_v1_to_v2() {
let promiseItemAdded = wait_for_addon_item_added(ID);
await install_addon(xpi1);
await promiseItemAdded;
let promiseItemUpdated = wait_for_addon_item_updated(ID);
let addon = await promiseAddonByID(ID);
await addon.disable();
await promiseItemUpdated;
await check_addon(addon, "1.0");
ok(addon.userDisabled, "Add-on should be disabled");
let item = getAddonCard(gManagerWindow, ID);
let promiseItemRemoved = wait_for_addon_item_removed(ID);
removeItem(item);
// Force XBL to apply
item.clientTop;
await promiseItemRemoved;
ok(
!!(addon.pendingOperations & AddonManager.PENDING_UNINSTALL),
"Add-on should be pending uninstall"
);
hasPendingMessage(item, "Pending message should be visible");
promiseItemAdded = wait_for_addon_item_added(ID);
await install_addon(xpi2);
addon = await promiseAddonByID(ID);
await promiseItemAdded;
await check_addon(addon, "2.0");
ok(addon.userDisabled, "Add-on should be disabled");
promiseItemRemoved = wait_for_addon_item_removed(ID);
await addon.uninstall();
await promiseItemRemoved;
is(get_list_item_count(), 0, "Should be no items in the list");
}
add_setup(async function () {
xpi1 = await AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "1.0",
browser_specific_settings: { gecko: { id: ID } },
},
});
xpi2 = await AddonTestUtils.createTempWebExtensionFile({
manifest: {
version: "2.0",
browser_specific_settings: { gecko: { id: ID } },
},
});
// Accept all prompts.
mockPromptService()._response = 0;
});
add_task(async function test_upgrades() {
// Close existing about:addons tab if a test failure has
// prevented it from being closed.
if (gManagerWindow) {
await close_manager(gManagerWindow);
}
gManagerWindow = await open_manager("addons://list/extension");
await test_upgrade_v1_to_v2();
await test_upgrade_disabled_v1_to_v2();
await test_upgrade_pending_uninstall_v1_to_v2();
await test_upgrade_pending_uninstall_disabled_v1_to_v2();
await close_manager(gManagerWindow);
gManagerWindow = null;
});
|