fune/toolkit/components/extensions/test/xpcshell/test_ext_manifest.js
Rob Wu 64ad4811f6 Bug 1570715 - Treat (deprecation) warnings as errors r=rpl
Add new preference `extensions.webextensions.warnings-as-errors` that
defaults to `true` in tests. Tests that expect warnings are modified
to briefly flip the pref for the specific part of the test that needs
an exception.

As part of the refactor, log entries for schema entries that contain
`"onError": "warn"` will now be prefixed by "Warning" instead of
"Error", to be consistent with the change from bug 1495908.

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

--HG--
extra : moz-landing-system : lando
2019-09-16 16:35:59 +00:00

95 lines
2.1 KiB
JavaScript

/* -*- 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(icon)}`
);
} else {
ok(!normalized.error, `Should not have an error ${JSON.stringify(icon)}`);
}
}
add_task(async function test_manifest() {
let badpaths = ["", " ", "\t", "http://foo.com/icon.png"];
for (let path of badpaths) {
await testIconPaths(
path,
{
icons: path,
},
/Error processing icons/
);
await testIconPaths(
path,
{
icons: {
"16": path,
},
},
/Error processing icons/
);
}
let paths = [
"icon.png",
"/icon.png",
"./icon.png",
"path to an icon.png",
" icon.png",
];
for (let path of paths) {
// manifest.icons is an object
await testIconPaths(
path,
{
icons: path,
},
/Error processing icons/
);
await testIconPaths(path, {
icons: {
"16": path,
},
});
}
});
add_task(async function test_manifest_warnings_on_unexpected_props() {
let extension = await ExtensionTestUtils.loadExtension({
manifest: {
background: {
scripts: ["bg.js"],
wrong_prop: true,
},
},
files: {
"bg.js": "",
},
});
ExtensionTestUtils.failOnSchemaWarnings(false);
await extension.startup();
ExtensionTestUtils.failOnSchemaWarnings(true);
// Retrieve the warning message collected by the Extension class
// packagingWarning method.
const { warnings } = extension.extension;
equal(warnings.length, 1, "Got the expected number of manifest warnings");
const expectedMessage =
"Reading manifest: Warning processing background.wrong_prop";
ok(
warnings[0].startsWith(expectedMessage),
"Got the expected warning message format"
);
await extension.unload();
});