Bug 1960285 - Add details to "Extension is invalid" error r=rpl,devtools-reviewers,frontend-codestyle-reviewers,ochameau
Differential Revision: https://phabricator.services.mozilla.com/D245391
This commit is contained in:
@@ -128,6 +128,7 @@ module.exports = [
|
||||
"devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-json/manifest.json",
|
||||
"devtools/client/jsonview/test/invalid_json.json",
|
||||
"devtools/client/webconsole/test/browser/test-syntaxerror-worklet.js",
|
||||
"devtools/server/tests/xpcshell/addons/invalid-extension-manifest-badjson/manifest.json",
|
||||
|
||||
// devtools specific format test file
|
||||
"devtools/server/tests/xpcshell/xpcshell_debugging_script.js",
|
||||
|
||||
@@ -1076,6 +1076,7 @@ devtools/client/performance-new/shared/profiler_get_symbols.js
|
||||
devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-json/manifest.json
|
||||
devtools/client/jsonview/test/invalid_json.json
|
||||
devtools/client/webconsole/test/browser/test-syntaxerror-worklet.js
|
||||
devtools/server/tests/xpcshell/addons/invalid-extension-manifest-badjson/manifest.json
|
||||
|
||||
# devtools specific format test file
|
||||
devtools/server/tests/xpcshell/xpcshell_debugging_script.js
|
||||
|
||||
@@ -32,7 +32,13 @@ class AddonsActor extends Actor {
|
||||
addonFile = new FileUtils.File(addonPath);
|
||||
addon = await AddonManager.installTemporaryAddon(addonFile);
|
||||
} catch (error) {
|
||||
throw new Error(`Could not install add-on at '${addonPath}': ${error}`);
|
||||
let msg = `${error}`;
|
||||
if (error.additionalErrors?.length) {
|
||||
// The generic "Extension is invalid" error does not offer any concrete
|
||||
// advice. Include the additional details to help with debugging.
|
||||
msg += `\n${error.additionalErrors.join("\n")}`;
|
||||
}
|
||||
throw new Error(`Could not install add-on at '${addonPath}': ${msg}`);
|
||||
}
|
||||
|
||||
Services.obs.notifyObservers(null, "devtools-installed-addon", addon.id);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// This is not a valid manifest.json file.
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"description": "manifest.json missing required field 'name'",
|
||||
"manifest_version": 3,
|
||||
"version": "1"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Supposedly localized extension",
|
||||
"description": "has default_locale without mandatory _locales/en/messages.json",
|
||||
"default_locale": "en",
|
||||
"manifest_version": 3,
|
||||
"version": "1"
|
||||
}
|
||||
@@ -14,22 +14,22 @@ async function connect() {
|
||||
return [client, addons];
|
||||
}
|
||||
|
||||
function getPlatformFilePath(path) {
|
||||
const allowMissing = false;
|
||||
const usePlatformSeparator = true;
|
||||
return getFilePath(path, allowMissing, usePlatformSeparator);
|
||||
}
|
||||
|
||||
// The AddonsManager test helper can only be called once per test script.
|
||||
// This `setup` task will run first.
|
||||
add_task(async function setup() {
|
||||
add_setup(async () => {
|
||||
await startupAddonsManager();
|
||||
});
|
||||
|
||||
add_task(async function testSuccessfulInstall() {
|
||||
const [client, addons] = await connect();
|
||||
|
||||
const allowMissing = false;
|
||||
const usePlatformSeparator = true;
|
||||
const addonPath = getFilePath(
|
||||
"addons/web-extension",
|
||||
allowMissing,
|
||||
usePlatformSeparator
|
||||
);
|
||||
const addonPath = getPlatformFilePath("addons/web-extension");
|
||||
const installedAddon = await addons.installTemporaryAddon(addonPath, false);
|
||||
equal(installedAddon.id, "test-addons-actor@mozilla.org");
|
||||
// The returned object is currently not a proper actor.
|
||||
@@ -53,3 +53,60 @@ add_task(async function testNonExistantPath() {
|
||||
|
||||
await close(client);
|
||||
});
|
||||
|
||||
add_task(async function testInvalidExtensionMissingManifestJson() {
|
||||
const [client, addons] = await connect();
|
||||
|
||||
await Assert.rejects(
|
||||
addons.installTemporaryAddon(getPlatformFilePath("addons"), false),
|
||||
/Could not install add-on.*does not contain a valid manifest/
|
||||
);
|
||||
|
||||
await close(client);
|
||||
});
|
||||
|
||||
add_task(async function testInvalidExtensionManifestJsonIsNotJson() {
|
||||
const [client, addons] = await connect();
|
||||
|
||||
await Assert.rejects(
|
||||
addons.installTemporaryAddon(
|
||||
getPlatformFilePath("addons/invalid-extension-manifest-badjson"),
|
||||
false
|
||||
),
|
||||
// It would be ideal if the error message contained manifest.json, but at
|
||||
// least having some description is better than nothing.
|
||||
/Could not install add-on.*SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data/
|
||||
);
|
||||
|
||||
await close(client);
|
||||
});
|
||||
|
||||
add_task(async function testInvalidExtensionManifestJsonMissingRequiredKey() {
|
||||
const [client, addons] = await connect();
|
||||
|
||||
await Assert.rejects(
|
||||
addons.installTemporaryAddon(
|
||||
getPlatformFilePath("addons/invalid-extension-manifest"),
|
||||
false
|
||||
),
|
||||
/Could not install add-on.*Error: Extension is invalid\nReading manifest: Property "name" is required/
|
||||
);
|
||||
|
||||
await close(client);
|
||||
});
|
||||
|
||||
add_task(async function testInvalidExtensionMissingLocales() {
|
||||
const [client, addons] = await connect();
|
||||
|
||||
await Assert.rejects(
|
||||
addons.installTemporaryAddon(
|
||||
getPlatformFilePath("addons/invalid-extension-missing-locales"),
|
||||
false
|
||||
),
|
||||
// It would be ideal if the error message contained manifest.json, but at
|
||||
// least having some description is better than nothing.
|
||||
/Could not install add-on.*Error: Extension is invalid\nLoading locale file _locales\/en\/messages.json: .*NS_ERROR_FILE_NOT_FOUND/
|
||||
);
|
||||
|
||||
await close(client);
|
||||
});
|
||||
|
||||
@@ -39,6 +39,9 @@ support-files = [
|
||||
"setBreakpoint-on-line-with-multiple-statements.js",
|
||||
"setBreakpoint-on-line-with-no-offsets.js",
|
||||
"setBreakpoint-on-line-with-no-offsets-in-gcd-script.js",
|
||||
"addons/invalid-extension-manifest/manifest.json",
|
||||
"addons/invalid-extension-manifest-badjson/manifest.json",
|
||||
"addons/invalid-extension-missing-locales/manifest.json",
|
||||
"addons/web-extension/manifest.json",
|
||||
"addons/web-extension-upgrade/manifest.json",
|
||||
"addons/web-extension2/manifest.json",
|
||||
|
||||
Reference in New Issue
Block a user