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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
Components.utils.import("resource://gre/modules/AppConstants.jsm");
const ID = "webextension1@tests.mozilla.org";
const PREF_SELECTED_LOCALE = "general.useragent.locale";
const profileDir = gProfD.clone();
profileDir.append("extensions");
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
startupManager();
const { GlobalManager, Management } = Components.utils.import("resource://gre/modules/Extension.jsm", {});
function promiseAddonStartup() {
return new Promise(resolve => {
let listener = (evt, extension) => {
Management.off("ready", listener);
resolve(extension);
};
Management.on("ready", listener);
});
}
function promiseInstallWebExtension(aData) {
let addonFile = createTempWebExtensionFile(aData);
return promiseInstallAllFiles([addonFile]).then(() => {
Services.obs.notifyObservers(addonFile, "flush-cache-entry", null);
return promiseAddonStartup();
});
}
add_task(function*() {
equal(GlobalManager.extensionMap.size, 0);
yield Promise.all([
promiseInstallAllFiles([do_get_addon("webextension_1")], true),
promiseAddonStartup()
]);
equal(GlobalManager.extensionMap.size, 1);
ok(GlobalManager.extensionMap.has(ID));
let chromeReg = AM_Cc["@mozilla.org/chrome/chrome-registry;1"].
getService(AM_Ci.nsIChromeRegistry);
try {
chromeReg.convertChromeURL(NetUtil.newURI("chrome://webex/content/webex.xul"));
do_throw("Chrome manifest should not have been registered");
}
catch (e) {
// Expected the chrome url to not be registered
}
let addon = yield promiseAddonByID(ID);
do_check_neq(addon, null);
do_check_eq(addon.version, "1.0");
do_check_eq(addon.name, "Web Extension Name");
do_check_true(addon.isCompatible);
do_check_false(addon.appDisabled);
do_check_true(addon.isActive);
do_check_false(addon.isSystem);
do_check_eq(addon.type, "extension");
do_check_true(addon.isWebExtension);
do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);
let uri = do_get_addon_root_uri(profileDir, ID);
do_check_eq(addon.iconURL, uri + "icon48.png");
do_check_eq(addon.icon64URL, uri + "icon64.png");
// Should persist through a restart
yield promiseShutdownManager();
equal(GlobalManager.extensionMap.size, 0);
startupManager();
yield promiseAddonStartup();
equal(GlobalManager.extensionMap.size, 1);
ok(GlobalManager.extensionMap.has(ID));
addon = yield promiseAddonByID(ID);
do_check_neq(addon, null);
do_check_eq(addon.version, "1.0");
do_check_eq(addon.name, "Web Extension Name");
do_check_true(addon.isCompatible);
do_check_false(addon.appDisabled);
do_check_true(addon.isActive);
do_check_false(addon.isSystem);
do_check_eq(addon.type, "extension");
do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);
let file = getFileForAddon(profileDir, ID);
do_check_true(file.exists());
uri = do_get_addon_root_uri(profileDir, ID);
do_check_eq(addon.iconURL, uri + "icon48.png");
do_check_eq(addon.icon64URL, uri + "icon64.png");
addon.userDisabled = true;
equal(GlobalManager.extensionMap.size, 0);
addon.userDisabled = false;
yield promiseAddonStartup();
equal(GlobalManager.extensionMap.size, 1);
ok(GlobalManager.extensionMap.has(ID));
addon.uninstall();
equal(GlobalManager.extensionMap.size, 0);
do_check_false(GlobalManager.extensionMap.has(ID));
yield promiseShutdownManager();
});
// Writing the manifest direct to the profile should work
add_task(function*() {
yield promiseWriteWebManifestForExtension({
name: "Web Extension Name",
version: "1.0",
manifest_version: 2,
applications: {
gecko: {
id: ID
}
}
}, profileDir);
startupManager();
yield promiseAddonStartup();
let addon = yield promiseAddonByID(ID);
do_check_neq(addon, null);
do_check_eq(addon.version, "1.0");
do_check_eq(addon.name, "Web Extension Name");
do_check_true(addon.isCompatible);
do_check_false(addon.appDisabled);
do_check_true(addon.isActive);
do_check_false(addon.isSystem);
do_check_eq(addon.type, "extension");
do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);
let file = getFileForAddon(profileDir, ID);
do_check_true(file.exists());
addon.uninstall();
yield promiseRestartManager();
});
add_task(function* test_manifest_localization() {
const extensionId = "webextension3@tests.mozilla.org";
yield promiseInstallAllFiles([do_get_addon("webextension_3")], true);
yield promiseAddonStartup();
let addon = yield promiseAddonByID(extensionId);
addon.userDisabled = true;
equal(addon.name, "Web Extensiøn foo ☹");
equal(addon.description, "Descriptïon bar ☹ of add-on");
Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
yield promiseRestartManager();
addon = yield promiseAddonByID(extensionId);
equal(addon.name, "Web Extensiøn le foo ☺");
equal(addon.description, "Descriptïon le bar ☺ of add-on");
Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de");
yield promiseRestartManager();
addon = yield promiseAddonByID(extensionId);
equal(addon.name, "Web Extensiøn foo ☹");
equal(addon.description, "Descriptïon bar ☹ of add-on");
addon.uninstall();
});
// Missing version should cause a failure
add_task(function*() {
yield promiseWriteWebManifestForExtension({
name: "Web Extension Name",
manifest_version: 2,
applications: {
gecko: {
id: ID
}
}
}, profileDir);
yield promiseRestartManager();
let addon = yield promiseAddonByID(ID);
do_check_eq(addon, null);
let file = getFileForAddon(profileDir, ID);
do_check_false(file.exists());
yield promiseRestartManager();
});
// Incorrect manifest version should cause a failure
add_task(function*() {
yield promiseWriteWebManifestForExtension({
name: "Web Extension Name",
version: "1.0",
manifest_version: 1,
applications: {
gecko: {
id: ID
}
}
}, profileDir);
yield promiseRestartManager();
let addon = yield promiseAddonByID(ID);
do_check_eq(addon, null);
let file = getFileForAddon(profileDir, ID);
do_check_false(file.exists());
yield promiseRestartManager();
});
// install.rdf should be read before manifest.json
add_task(function*() {
yield Promise.all([
promiseInstallAllFiles([do_get_addon("webextension_2")], true)
]);
yield promiseRestartManager();
let installrdf_id = "first-webextension2@tests.mozilla.org";
let first_addon = yield promiseAddonByID(installrdf_id);
do_check_neq(first_addon, null);
do_check_false(first_addon.appDisabled);
do_check_true(first_addon.isActive);
do_check_false(first_addon.isSystem);
let manifestjson_id= "last-webextension2@tests.mozilla.org";
let last_addon = yield promiseAddonByID(manifestjson_id);
do_check_eq(last_addon, null);
yield promiseRestartManager();
});
// Test that the "options_ui" manifest section is processed correctly.
add_task(function* test_options_ui() {
let OPTIONS_RE = /^moz-extension:\/\/[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\/options\.html$/;
const extensionId = "webextension@tests.mozilla.org";
yield promiseInstallWebExtension({
manifest: {
applications: {gecko: {id: extensionId}},
"options_ui": {
"page": "options.html",
},
},
});
let addon = yield promiseAddonByID(extensionId);
equal(addon.optionsType, AddonManager.OPTIONS_TYPE_INLINE_BROWSER,
"Addon should have an INLINE_BROWSER options type");
ok(OPTIONS_RE.test(addon.optionsURL),
"Addon should have a moz-extension: options URL for /options.html");
addon.uninstall();
const ID2 = "webextension2@tests.mozilla.org";
yield promiseInstallWebExtension({
manifest: {
applications: {gecko: {id: ID2}},
"options_ui": {
"page": "options.html",
"open_in_tab": true,
},
},
});
addon = yield promiseAddonByID(ID2);
equal(addon.optionsType, AddonManager.OPTIONS_TYPE_TAB,
"Addon should have a TAB options type");
ok(OPTIONS_RE.test(addon.optionsURL),
"Addon should have a moz-extension: options URL for /options.html");
addon.uninstall();
});
// Test that experiments permissions add the appropriate dependencies.
add_task(function* test_experiments_dependencies() {
if (AppConstants.RELEASE_OR_BETA)
// Experiments are not enabled on release builds.
return;
let addonFile = createTempWebExtensionFile({
manifest: {
applications: {gecko: {id: "meh@experiment"}},
"permissions": ["experiments.meh"],
},
});
yield promiseInstallAllFiles([addonFile]);
let addon = yield new Promise(resolve => AddonManager.getAddonByID("meh@experiment", resolve));
deepEqual(addon.dependencies, ["meh@experiments.addons.mozilla.org"],
"Addon should have the expected dependencies");
equal(addon.appDisabled, true, "Add-on should be app disabled due to missing dependencies");
addon.uninstall();
});
// Test that experiments API extensions install correctly.
add_task(function* test_experiments_api() {
if (AppConstants.RELEASE_OR_BETA)
// Experiments are not enabled on release builds.
return;
const extensionId = "meh@experiments.addons.mozilla.org";
let addonFile = createTempXPIFile({
id: extensionId,
type: 256,
version: "0.1",
name: "Meh API",
});
yield promiseInstallAllFiles([addonFile]);
let addons = yield new Promise(resolve => AddonManager.getAddonsByTypes(["apiextension"], resolve));
let addon = addons.pop();
equal(addon.id, extensionId, "Add-on should be installed as an API extension");
addons = yield new Promise(resolve => AddonManager.getAddonsByTypes(["extension"], resolve));
equal(addons.pop().id, extensionId, "Add-on type should be aliased to extension");
addon.uninstall();
});
add_task(function* developerShouldOverride() {
let addon = yield promiseInstallWebExtension({
manifest: {
default_locale: "en",
developer: {
name: "__MSG_name__",
url: "__MSG_url__"
},
author: "Will be overridden by developer",
homepage_url: "https://will.be.overridden",
},
files: {
"_locales/en/messages.json": `{
"name": {
"message": "en name"
},
"url": {
"message": "https://example.net/en"
}
}`
}
});
addon = yield promiseAddonByID(addon.id);
equal(addon.creator, "en name");
equal(addon.homepageURL, "https://example.net/en");
addon.uninstall();
});
add_task(function* developerEmpty() {
for (let developer of [{}, null, {name: null, url: null}]) {
let addon = yield promiseInstallWebExtension({
manifest: {
author: "Some author",
developer: developer,
homepage_url: "https://example.net",
manifest_version: 2,
name: "Web Extension Name",
version: "1.0",
}
});
addon = yield promiseAddonByID(addon.id);
equal(addon.creator, "Some author");
equal(addon.homepageURL, "https://example.net");
addon.uninstall();
}
});
add_task(function* authorNotString() {
for (let author of [{}, [], 42]) {
let addon = yield promiseInstallWebExtension({
manifest: {
author: author,
manifest_version: 2,
name: "Web Extension Name",
version: "1.0",
}
});
addon = yield promiseAddonByID(addon.id);
equal(addon.creator, null);
addon.uninstall();
}
});
|