Bug 1338525 - Add test coverage for theme validation r=mikedeboer

MozReview-Commit-ID: FLYMpceZYhA

--HG--
extra : rebase_source : 4c11ce0ee80a53326709ddeb10527ce83d6b9846
This commit is contained in:
Matthew Wein 2017-03-09 16:56:46 -05:00
Родитель 4193302534
Коммит 44cfffc793
4 изменённых файлов: 129 добавлений и 0 удалений

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

@ -121,6 +121,7 @@ support-files =
[browser_ext_tabs_zoom.js]
[browser_ext_tabs_update_url.js]
[browser_ext_themes_icons.js]
[browser_ext_themes_validation.js]
[browser_ext_topwindowid.js]
[browser_ext_url_overrides_newtab.js]
[browser_ext_url_overrides_home.js]

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

@ -0,0 +1,56 @@
"use strict";
add_task(function* setup() {
yield SpecialPowers.pushPrefEnv({
set: [["extensions.webextensions.themes.enabled", true]],
});
});
/**
* Helper function for testing a theme with invalid properties.
* @param {object} invalidProps The invalid properties to load the theme with.
*/
function* testThemeWithInvalidProperties(invalidProps) {
let manifest = {
"theme": {},
};
invalidProps.forEach(prop => {
// Some properties require additional information:
switch (prop) {
case "background":
manifest[prop] = {"scripts": ["background.js"]};
break;
case "permissions":
manifest[prop] = ["tabs"];
break;
case "omnibox":
manifest[prop] = {"keyword": "test"};
break;
default:
manifest[prop] = {};
}
});
let extension = ExtensionTestUtils.loadExtension({manifest});
SimpleTest.waitForExplicitFinish();
let waitForConsole = new Promise(resolve => {
SimpleTest.monitorConsole(resolve, [{
message: /Reading manifest: Themes defined in the manifest may only contain static resources/,
}]);
});
yield Assert.rejects(extension.startup(), null, "Theme should fail to load if it contains invalid properties");
SimpleTest.endMonitorConsole();
yield waitForConsole;
}
add_task(function* test_that_theme_with_invalid_properties_fails_to_load() {
let invalidProps = ["page_action", "browser_action", "background", "permissions", "omnibox", "commands"];
for (let prop in invalidProps) {
yield testThemeWithInvalidProperties([prop]);
}
yield testThemeWithInvalidProperties(invalidProps);
});

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

@ -0,0 +1,71 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
Cu.import("resource://gre/modules/Schemas.jsm");
const {
validateThemeManifest,
} = ExtensionUtils;
const BASE_SCHEMA_URL = "chrome://extensions/content/schemas/manifest.json";
const CATEGORY_EXTENSION_SCHEMAS = "webextension-schemas";
const baseManifestProperties = [
"manifest_version",
"minimum_chrome_version",
"applications",
"browser_specific_settings",
"name",
"short_name",
"description",
"author",
"version",
"homepage_url",
"icons",
"incognito",
"background",
"options_ui",
"content_scripts",
"permissions",
"web_accessible_resources",
"developer",
];
function* getAdditionalInvalidManifestProperties() {
let invalidProperties = [];
yield Schemas.load(BASE_SCHEMA_URL);
for (let [name, url] of XPCOMUtils.enumerateCategoryEntries(CATEGORY_EXTENSION_SCHEMAS)) {
if (name !== "theme") {
yield Schemas.load(url);
let types = Schemas.schemaJSON.get(url)[0].types;
types.forEach(type => {
if (type.$extend == "WebExtensionManifest") {
let properties = Object.getOwnPropertyNames(type.properties);
invalidProperties.push(...properties);
}
});
}
}
// Also test an unrecognized property.
invalidProperties.push("unrecognized_property");
return invalidProperties;
}
function checkProperties(actual, expected) {
Assert.equal(actual.length, expected.length, `Should have found ${expected.length} invalid properties`);
for (let i = 0; i < expected.length; i++) {
Assert.ok(actual.includes(expected[i]), `The invalid properties should contain "${expected[i]}"`);
}
}
add_task(function* test_theme_supported_properties() {
let additionalInvalidProperties = yield getAdditionalInvalidManifestProperties();
let actual = validateThemeManifest([...baseManifestProperties, ...additionalInvalidProperties]);
let expected = ["background", "permissions", "content_scripts", ...additionalInvalidProperties];
checkProperties(actual, expected);
});

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

@ -77,6 +77,7 @@ head = head.js head_sync.js
skip-if = os == "android"
[test_ext_storage_sync_crypto.js]
skip-if = os == "android"
[test_ext_themes_supported_properties.js]
[test_ext_topSites.js]
skip-if = os == "android"
[test_getAPILevelForWindow.js]