Bug 1337938 - Add test for permissions localization strings r?aswan draft
authorTomislav Jovanovic <tomica@gmail.com>
Sat, 26 Aug 2017 22:30:35 +0200
changeset 654429 ca2b679d97cc8586a872cc5c7cf37fb511263feb
parent 653118 56188620cce00b19700fbb8efaafea65e6ca8c61
child 728574 f824046c106e5e4f2e380d0a124bb69013c89a50
push id76583
push userbmo:tomica@gmail.com
push dateMon, 28 Aug 2017 21:39:29 +0000
reviewersaswan
bugs1337938
milestone57.0a1
Bug 1337938 - Add test for permissions localization strings r?aswan MozReview-Commit-ID: 27nwTtVLRzE
toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
--- 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`);
+      }
+    }
+  }
+});