Bug 1337938 - Add test for permissions localization strings r?aswan
MozReview-Commit-ID: 27nwTtVLRzE
--- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
@@ -2,16 +2,18 @@
XPCOMUtils.defineLazyGetter(this, "ExtensionManager", () => {
const {ExtensionManager}
= Cu.import("resource://gre/modules/ExtensionChild.jsm", {});
return ExtensionManager;
});
Cu.import("resource://gre/modules/ExtensionPermissions.jsm");
+const BROWSER_PROPERTIES = "chrome://browser/locale/browser.properties";
+
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
// Find the DOMWindowUtils for the background page for the given
// extension (wrapper)
function findWinUtils(extension) {
let extensionChild = ExtensionManager.extensions.get(extension.extension.id);
@@ -359,8 +361,51 @@ add_task(async function test_alreadyGran
await checkRequest({origins: ["http://*.optional-domain.com/"]}, false,
"already granted optional wildcard origin");
await checkRequest({origins: ["http://host.optional-domain.com/"]}, false,
"host matching optional wildcard origin");
handle.destruct();
await extension.unload();
});
+
+// IMPORTANT: Do not change this list without review from a Web Extensions peer!
+
+const GRANTED_WITHOUT_USER_PROMPT = [
+ "activeTab",
+ "alarms",
+ "browsingData",
+ "contextMenus",
+ "contextualIdentities",
+ "cookies",
+ "downloads.open",
+ "downloads.shelf",
+ "geckoProfiler",
+ "identity",
+ "idle",
+ "menus",
+ "proxy",
+ "storage",
+ "theme",
+ "webRequest",
+ "webRequestBlocking",
+];
+
+add_task(function test_permissions_have_localization_strings() {
+ const ns = Schemas.getNamespace("manifest");
+
+ const permissions = ns.get("Permission").choices;
+ const optional = ns.get("OptionalPermission").choices;
+
+ const bundle = Services.strings.createBundle(BROWSER_PROPERTIES);
+
+ for (const choice of permissions.concat(optional)) {
+ for (const perm of choice.enumeration || []) {
+ try {
+ const str = bundle.GetStringFromName(`webextPerms.description.${perm}`);
+ ok(str.length, `Found localization string for '${perm}' permission`);
+ } catch (e) {
+ ok(GRANTED_WITHOUT_USER_PROMPT.includes(perm),
+ `Permission '${perm}' intentionally granted without prompting the user`);
+ }
+ }
+ }
+});