Skip to content

Commit b158957

Browse files
committed
Bug 1828128 - Relax required syntax for web_accessible_resources r=willdurand
- Do not require any item in the arrays - Allow web_accessible_resources to have unrecognized properties instead of refusing to load the extension. - Fix up minor quality issues in tests. Differential Revision: https://phabricator.services.mozilla.com/D175484 UltraBlame original commit: 2dfd444d61d409fabb43861943d1d55826682625
1 parent c5fa5c0 commit b158957

File tree

2 files changed

+98
-24
lines changed

2 files changed

+98
-24
lines changed

toolkit/components/extensions/schemas/manifest.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,16 @@
296296
"min_manifest_version": 3,
297297
"type": "array",
298298
"postprocess": "webAccessibleMatching",
299-
"minItems": 1,
300299
"items": {
301300
"type": "object",
302301
"properties": {
303302
"resources": {
304303
"type": "array",
305-
"minItems": 1,
306304
"items": { "type": "string" }
307305
},
308306
"matches": {
309307
"optional": true,
310308
"type": "array",
311-
"minItems": 1,
312309
"items": { "$ref": "MatchPattern" }
313310
},
314311
"extension_ids": {
@@ -321,7 +318,8 @@
321318
]
322319
}
323320
}
324-
}
321+
},
322+
"additionalProperties": { "$ref": "UnrecognizedProperty" }
325323
}
326324
}
327325
]

toolkit/components/extensions/test/xpcshell/test_ext_web_accessible_resources_matches.js

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const IMAGE_ARRAYBUFFER = Uint8Array.from(image, byte => byte.charCodeAt(0))
1313
.buffer;
1414

1515
add_task(async function test_web_accessible_resources_matching() {
16-
let extension = await ExtensionTestUtils.loadExtension({
16+
let extension = ExtensionTestUtils.loadExtension({
1717
manifest: {
1818
manifest_version: 3,
1919
web_accessible_resources: [
@@ -30,7 +30,7 @@ add_task(async function test_web_accessible_resources_matching() {
3030
"web_accessible_resources object format incorrect"
3131
);
3232

33-
extension = await ExtensionTestUtils.loadExtension({
33+
extension = ExtensionTestUtils.loadExtension({
3434
manifest: {
3535
manifest_version: 3,
3636
web_accessible_resources: [
@@ -46,7 +46,7 @@ add_task(async function test_web_accessible_resources_matching() {
4646
ok(true, "web_accessible_resources with matches loads");
4747
await extension.unload();
4848

49-
extension = await ExtensionTestUtils.loadExtension({
49+
extension = ExtensionTestUtils.loadExtension({
5050
manifest: {
5151
manifest_version: 3,
5252
web_accessible_resources: [
@@ -62,7 +62,7 @@ add_task(async function test_web_accessible_resources_matching() {
6262
ok(true, "web_accessible_resources with extensions loads");
6363
await extension.unload();
6464

65-
extension = await ExtensionTestUtils.loadExtension({
65+
extension = ExtensionTestUtils.loadExtension({
6666
manifest: {
6767
manifest_version: 3,
6868
web_accessible_resources: [
@@ -79,7 +79,7 @@ add_task(async function test_web_accessible_resources_matching() {
7979
ok(true, "web_accessible_resources with matches and extensions loads");
8080
await extension.unload();
8181

82-
extension = await ExtensionTestUtils.loadExtension({
82+
extension = ExtensionTestUtils.loadExtension({
8383
manifest: {
8484
manifest_version: 3,
8585
web_accessible_resources: [
@@ -95,7 +95,7 @@ add_task(async function test_web_accessible_resources_matching() {
9595
ok(true, "web_accessible_resources with empty extensions loads");
9696
await extension.unload();
9797

98-
extension = await ExtensionTestUtils.loadExtension({
98+
extension = ExtensionTestUtils.loadExtension({
9999
manifest: {
100100
manifest_version: 3,
101101
web_accessible_resources: [
@@ -446,23 +446,99 @@ add_task(async function test_web_accessible_resources_empty_extension_ids() {
446446
"expected access to the extension's resource"
447447
);
448448

449-
450-
451-
452-
try {
453-
await ExtensionTestUtils.fetch(
449+
await Assert.rejects(
450+
ExtensionTestUtils.fetch(
454451
secondExtension.extension.baseURI.resolve("page.html"),
455452
fileURL
456-
);
457-
ok(false, "expected an error to be thrown");
458-
} catch (e) {
459-
Assert.equal(
460-
e?.message,
461-
"NetworkError when attempting to fetch resource.",
462-
"expected a network error"
463-
);
464-
}
453+
),
454+
e => e?.message === "NetworkError when attempting to fetch resource.",
455+
"other extension should not be able to fetch when extension_ids is empty"
456+
);
465457

466458
await extension.unload();
467459
await secondExtension.unload();
468460
});
461+
462+
add_task(async function test_web_accessible_resources_empty_array() {
463+
let extension = ExtensionTestUtils.loadExtension({
464+
manifest: {
465+
manifest_version: 3,
466+
web_accessible_resources: [],
467+
},
468+
});
469+
await extension.startup();
470+
ok(true, "empty web_accessible_resources loads");
471+
await extension.unload();
472+
});
473+
474+
add_task(async function test_web_accessible_resources_empty_resources() {
475+
let extension = ExtensionTestUtils.loadExtension({
476+
manifest: {
477+
manifest_version: 3,
478+
web_accessible_resources: [{ resources: [], matches: ["*://*/*"] }],
479+
},
480+
});
481+
await extension.startup();
482+
ok(true, "empty web_accessible_resources[0].resources loads");
483+
await extension.unload();
484+
});
485+
486+
add_task(async function test_web_accessible_resources_empty_everything() {
487+
let extension = ExtensionTestUtils.loadExtension({
488+
manifest: {
489+
manifest_version: 3,
490+
web_accessible_resources: [
491+
{ resources: [], matches: [], extension_ids: [] },
492+
],
493+
},
494+
});
495+
await extension.startup();
496+
ok(true, "empty resources, matches & extension_ids loads");
497+
await extension.unload();
498+
});
499+
500+
add_task(async function test_web_accessible_resources_empty_matches() {
501+
let extension = ExtensionTestUtils.loadExtension({
502+
manifest: {
503+
manifest_version: 3,
504+
web_accessible_resources: [{ resources: ["file.txt"], matches: [] }],
505+
},
506+
files: {
507+
"file.txt": "some content",
508+
},
509+
});
510+
await extension.startup();
511+
ok(true, "empty web_accessible_resources[0].matches loads");
512+
513+
const fileURL = extension.extension.baseURI.resolve("file.txt");
514+
await Assert.rejects(
515+
ExtensionTestUtils.fetch("http://example.com", fileURL),
516+
e => e?.message === "NetworkError when attempting to fetch resource.",
517+
"empty matches[] = not web-accessible"
518+
);
519+
await extension.unload();
520+
});
521+
522+
add_task(async function test_web_accessible_resources_unknown_property() {
523+
let extension = ExtensionTestUtils.loadExtension({
524+
manifest: {
525+
manifest_version: 3,
526+
web_accessible_resources: [{ resources: [], matches: [], idk: null }],
527+
},
528+
});
529+
530+
let { messages } = await promiseConsoleOutput(async () => {
531+
ExtensionTestUtils.failOnSchemaWarnings(false);
532+
await extension.startup();
533+
ExtensionTestUtils.failOnSchemaWarnings(true);
534+
});
535+
536+
AddonTestUtils.checkMessages(messages, {
537+
expected: [
538+
{
539+
message: /Reading manifest: Warning processing web_accessible_resources.0.idk: An unexpected property was found in the WebExtension manifest./,
540+
},
541+
],
542+
});
543+
await extension.unload();
544+
});

0 commit comments

Comments
 (0)