Bug 1524001 update manifest to validate manifest.icons, r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D18105

--HG--
rename : toolkit/components/extensions/test/xpcshell/test_ext_manifest.js => browser/components/extensions/test/xpcshell/test_ext_manifest.js
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2019-02-14 01:32:31 +00:00
Родитель 40e0ac9225
Коммит 5b5b01194d
5 изменённых файлов: 80 добавлений и 35 удалений

Просмотреть файл

@ -0,0 +1,48 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
async function testIconPaths(icon, manifest, expectedError) {
let normalized = await ExtensionTestUtils.normalizeManifest(manifest);
if (expectedError) {
ok(expectedError.test(normalized.error),
`Should have an error for ${JSON.stringify(manifest)}`);
} else {
ok(!normalized.error, `Should not have an error ${JSON.stringify(manifest)}, ${normalized.error}`);
}
}
add_task(async function test_manifest() {
let badpaths = ["", " ", "\t", "http://foo.com/icon.png"];
for (let path of badpaths) {
for (let action of ["browser_action", "page_action", "sidebar_action"]) {
let manifest = {};
manifest[action] = {default_icon: path};
let error = new RegExp(`Error processing ${action}.default_icon`);
await testIconPaths(path, manifest, error);
manifest[action] = {default_icon: {"16": path}};
await testIconPaths(path, manifest, error);
}
}
let paths = ["icon.png", "/icon.png", "./icon.png", "path to an icon.png", " icon.png"];
for (let path of paths) {
for (let action of ["browser_action", "page_action", "sidebar_action"]) {
let manifest = {};
manifest[action] = {default_icon: path};
if (action == "sidebar_action") {
// Sidebar requires panel.
manifest[action].default_panel = "foo.html";
}
await testIconPaths(path, manifest);
manifest[action] = {default_icon: {"16": path}};
if (action == "sidebar_action") {
manifest[action].default_panel = "foo.html";
}
await testIconPaths(path, manifest);
}
}
});

Просмотреть файл

@ -17,6 +17,7 @@ dupe-manifest =
# For tests which should only run with both remote extensions and remote content. # For tests which should only run with both remote extensions and remote content.
[test_ext_geckoProfiler_schema.js] [test_ext_geckoProfiler_schema.js]
[test_ext_manifest.js]
[test_ext_manifest_commands.js] [test_ext_manifest_commands.js]
[test_ext_manifest_omnibox.js] [test_ext_manifest_omnibox.js]
[test_ext_manifest_permissions.js] [test_ext_manifest_permissions.js]

Просмотреть файл

@ -95,7 +95,7 @@
"type": "object", "type": "object",
"optional": true, "optional": true,
"patternProperties": { "patternProperties": {
"^[1-9]\\d*$": { "type": "string" } "^[1-9]\\d*$": { "$ref": "ExtensionFileUrl" }
} }
}, },

Просмотреть файл

@ -2,48 +2,42 @@
/* vim: set sts=2 sw=2 et tw=80: */ /* vim: set sts=2 sw=2 et tw=80: */
"use strict"; "use strict";
async function testIconPaths(icon, manifest, expectedError) {
let normalized = await ExtensionTestUtils.normalizeManifest(manifest);
if (expectedError) {
ok(expectedError.test(normalized.error),
`Should have an error for ${JSON.stringify(icon)}`);
} else {
ok(!normalized.error, `Should not have an error ${JSON.stringify(icon)}`);
}
}
add_task(async function test_manifest() { add_task(async function test_manifest() {
let badpaths = ["", " ", "\t", "http://foo.com/icon.png"]; let badpaths = ["", " ", "\t", "http://foo.com/icon.png"];
for (let path of badpaths) { for (let path of badpaths) {
let normalized = await ExtensionTestUtils.normalizeManifest({ await testIconPaths(path, {
"browser_action": { "icons": path,
"default_icon": path, }, /Error processing icons/);
await testIconPaths(path, {
"icons": {
"16": path,
}, },
}); }, /Error processing icons/);
ok(/Error processing browser_action.default_icon/.test(normalized.error),
`Should have an error for ${JSON.stringify(path)}`);
normalized = await ExtensionTestUtils.normalizeManifest({
"browser_action": {
"default_icon": {
"16": path,
},
},
});
ok(/Error processing browser_action.default_icon/.test(normalized.error),
`Should have an error for ${JSON.stringify(path)}`);
} }
let paths = ["icon.png", "/icon.png", "./icon.png", "path to an icon.png", " icon.png"]; let paths = ["icon.png", "/icon.png", "./icon.png", "path to an icon.png", " icon.png"];
for (let path of paths) { for (let path of paths) {
let normalized = await ExtensionTestUtils.normalizeManifest({ // manifest.icons is an object
"browser_action": { await testIconPaths(path, {
"default_icon": { "icons": path,
"16": path, }, /Error processing icons/);
},
await testIconPaths(path, {
"icons": {
"16": path,
}, },
}); });
ok(!normalized.error, `Should not have an error ${JSON.stringify(path)}`);
normalized = await ExtensionTestUtils.normalizeManifest({
"browser_action": {
"default_icon": path,
},
});
ok(!normalized.error, `Should not have an error ${JSON.stringify(path)}`);
} }
}); });

Просмотреть файл

@ -11,6 +11,7 @@ function backgroundGetSelf() {
browser.management.getSelf().then(extInfo => { browser.management.getSelf().then(extInfo => {
let url = browser.extension.getURL("*"); let url = browser.extension.getURL("*");
extInfo.hostPermissions = extInfo.hostPermissions.filter(i => i != url); extInfo.hostPermissions = extInfo.hostPermissions.filter(i => i != url);
extInfo.url = browser.extension.getURL("");
browser.test.sendMessage("management-getSelf", extInfo); browser.test.sendMessage("management-getSelf", extInfo);
}, error => { }, error => {
browser.test.notifyFail(`getSelf rejected with error: ${error}`); browser.test.notifyFail(`getSelf rejected with error: ${error}`);
@ -65,8 +66,9 @@ add_task(async function test_management_get_self_complete() {
equal(extInfo.updateUrl, manifest.applications.gecko.update_url, "getSelf returned the expected updateUrl"); equal(extInfo.updateUrl, manifest.applications.gecko.update_url, "getSelf returned the expected updateUrl");
ok(extInfo.optionsUrl.endsWith(manifest.options_ui.page), "getSelf returned the expected optionsUrl"); ok(extInfo.optionsUrl.endsWith(manifest.options_ui.page), "getSelf returned the expected optionsUrl");
for (let [index, size] of Object.keys(manifest.icons).sort().entries()) { for (let [index, size] of Object.keys(manifest.icons).sort().entries()) {
let iconUrl = `${extInfo.url}${manifest.icons[size]}`;
equal(extInfo.icons[index].size, +size, "getSelf returned the expected icon size"); equal(extInfo.icons[index].size, +size, "getSelf returned the expected icon size");
equal(extInfo.icons[index].url, manifest.icons[size], "getSelf returned the expected icon url"); equal(extInfo.icons[index].url, iconUrl, "getSelf returned the expected icon url");
} }
deepEqual(extInfo.permissions.sort(), permissions.sort(), "getSelf returned the expected permissions"); deepEqual(extInfo.permissions.sort(), permissions.sort(), "getSelf returned the expected permissions");
deepEqual(extInfo.hostPermissions.sort(), hostPermissions.sort(), "getSelf returned the expected hostPermissions"); deepEqual(extInfo.hostPermissions.sort(), hostPermissions.sort(), "getSelf returned the expected hostPermissions");