Bug 1446948 Fix presentation of unsigned langpacks in about:addons draft
authorAndrew Swan <aswan@mozilla.com>
Thu, 22 Mar 2018 13:08:46 -0700
changeset 771240 99c971a894dc5cadbc2fd79790da46d0454857d4
parent 770611 7b55d395bb63165c20a9230f82b3b14da09bcd2d
push id103628
push useraswan@mozilla.com
push dateThu, 22 Mar 2018 20:09:23 +0000
bugs1446948
milestone61.0a1
Bug 1446948 Fix presentation of unsigned langpacks in about:addons MozReview-Commit-ID: CE7tcq7Bp1g
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/content/extensions.xml
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_langpack_signing.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -227,17 +227,20 @@ function loadView(aViewId) {
 
 function isCorrectlySigned(aAddon) {
   // Add-ons without an "isCorrectlySigned" property are correctly signed as
   // they aren't the correct type for signing.
   return aAddon.isCorrectlySigned !== false;
 }
 
 function isDisabledUnsigned(addon) {
-  return AddonSettings.REQUIRE_SIGNING && !isCorrectlySigned(addon);
+  let signingRequired = (addon.type == "locale") ?
+                        AddonSettings.LANGPACKS_REQUIRE_SIGNING :
+                        AddonSettings.REQUIRE_SIGNING;
+  return signingRequired && !isCorrectlySigned(addon);
 }
 
 function isLegacyExtension(addon) {
   let legacy = false;
   if (addon.type == "extension" && !addon.isWebExtension) {
     legacy = true;
   }
   if (addon.type == "theme") {
@@ -2501,17 +2504,17 @@ var gListView = {
       navigator.plugins.refresh(false);
     }
 
     getAddonsAndInstalls(aType, (aAddonsList, aInstallsList) => {
       if (gViewController && aRequest != gViewController.currentViewRequest)
         return;
 
       let showLegacyInfo = false;
-      if (!legacyExtensionsEnabled) {
+      if (!legacyExtensionsEnabled && aType != "locale") {
         let preLen = aAddonsList.length;
         aAddonsList = aAddonsList.filter(addon => !isLegacyExtension(addon) &&
                                                   !isDisabledUnsigned(addon));
         if (aAddonsList.length != preLen) {
           showLegacyInfo = true;
         }
       }
 
@@ -2556,22 +2559,21 @@ var gListView = {
   hide() {
     gEventManager.unregisterInstallListener(this);
     doPendingUninstalls(this._listBox);
   },
 
   filterDisabledUnsigned(aFilter = true) {
     let foundDisabledUnsigned = false;
 
-    if (AddonSettings.REQUIRE_SIGNING) {
-      for (let item of this._listBox.childNodes) {
-        if (!isCorrectlySigned(item.mAddon))
-          foundDisabledUnsigned = true;
-        else
-          item.hidden = aFilter;
+    for (let item of this._listBox.childNodes) {
+      if (isDisabledUnsigned(item.mAddon)) {
+        foundDisabledUnsigned = true;
+      } else {
+        item.hidden = aFilter;
       }
     }
 
     document.getElementById("show-disabled-unsigned-extensions").hidden =
       aFilter || !foundDisabledUnsigned;
 
     document.getElementById("show-all-extensions").hidden = !aFilter;
     document.getElementById("disabled-unsigned-addons-info").hidden = !aFilter;
--- a/toolkit/mozapps/extensions/content/extensions.xml
+++ b/toolkit/mozapps/extensions/content/extensions.xml
@@ -1198,18 +1198,17 @@
               this.setAttribute("notification", "error");
               this._error.textContent = gStrings.ext.formatStringFromName(
                 "notification.blocked",
                 [this.mAddon.name], 1
               );
               this._errorLink.value = gStrings.ext.GetStringFromName("notification.blocked.link");
               this._errorLink.href = this.mAddon.blocklistURL;
               this._errorLink.hidden = false;
-            } else if (!isUpgrade && !isCorrectlySigned(this.mAddon) &&
-                       AddonSettings.REQUIRE_SIGNING) {
+            } else if (!isUpgrade && isDisabledUnsigned(this.mAddon)) {
               this.setAttribute("notification", "error");
               this._error.textContent = gStrings.ext.formatStringFromName(
                 "notification.unsignedAndDisabled", [this.mAddon.name, gStrings.brandShortName], 2
               );
               this._errorLink.value = gStrings.ext.GetStringFromName("notification.unsigned.link");
               this._errorLink.href = SUPPORT_URL + "unsigned-addons";
               this._errorLink.hidden = false;
             } else if ((!isUpgrade && !this.mAddon.isCompatible) && (AddonManager.checkCompatibility
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -75,16 +75,17 @@ skip-if = buildapp == 'mulet'
 [browser_file_xpi_no_process_switch.js]
 [browser_getmorethemes.js]
 [browser_globalwarnings.js]
 [browser_gmpProvider.js]
 skip-if = os == 'linux' && !debug # Bug 1398766
 [browser_inlinesettings_browser.js]
 [browser_install.js]
 [browser_installssl.js]
+[browser_langpack_signing.js]
 [browser_legacy.js]
 [browser_legacy_pre57.js]
 [browser_legacy_themes.js]
 [browser_list.js]
 [browser_manualupdates.js]
 [browser_newaddon.js]
 [browser_pluginprefs.js]
 [browser_pluginprefs_is_not_disabled.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_langpack_signing.js
@@ -0,0 +1,89 @@
+
+// Tests that signed and unsigned language packs show up correctly in
+// the Languages tab based on the langpack signing preference.
+add_task(async function() {
+  const PREF = "extensions.langpacks.signatures.required";
+
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF, false]]
+  });
+
+  let provider = new MockProvider();
+
+  provider.createAddons([{
+    id: "signed@tests.mozilla.org",
+    name: "Signed langpack",
+    type: "locale",
+    signedState: AddonManager.SIGNEDSTATE_SIGNED,
+    isCorrectlySigned: true,
+  }, {
+    id: "unsigned@tests.mozilla.org",
+    name: "Unsigned langpack",
+    type: "locale",
+    signedState: AddonManager.SIGNEDSTATE_MISSING,
+    isCorrectlySigned: false,
+  }]);
+
+
+  let mgrWin = await open_manager(null);
+
+  function checklist(signingRequired) {
+    let list = mgrWin.document.getElementById("addon-list");
+    is(list.children.length, 2, "Found 2 items in langpack list");
+    for (let item of list.children) {
+      let what, warningVisible, errorVisible;
+
+      if (item.mAddon.id.startsWith("signed")) {
+        // Signed langpack should not have any warning/error
+        what = "signed langpack";
+        warningVisible = false;
+        errorVisible = false;
+      } else if (signingRequired) {
+        // Unsigned should have an error if signing is required
+        what = "unsigned langpack";
+        warningVisible = false;
+        errorVisible = true;
+      } else {
+        // Usnigned should have a warning is signing is not required
+        what = "unsigned langpack";
+        warningVisible = true;
+        errorVisible = false;
+      }
+
+      let warning = mgrWin.document.getAnonymousElementByAttribute(item, "anonid", "warning");
+      let warningLink = mgrWin.document.getAnonymousElementByAttribute(item, "anonid", "warning-link");
+      if (warningVisible) {
+        is_element_visible(warning, `Warning should be visible for ${what}`);
+        is_element_visible(warningLink, `Warning link should be visible for ${what}`);
+      } else {
+        is_element_hidden(warning, `Warning should be hidden for ${what}`);
+        is_element_hidden(warningLink, `Warning link should be hidden for ${what}`);
+      }
+
+      let error = mgrWin.document.getAnonymousElementByAttribute(item, "anonid", "error");
+      let errorLink = mgrWin.document.getAnonymousElementByAttribute(item, "anonid", "error-link");
+      if (errorVisible) {
+        is_element_visible(error, `Error should be visible for ${what}`);
+        is_element_visible(errorLink, `Error link should be visible for ${what}`);
+      } else {
+        is_element_hidden(error, `Error should be hidden for ${what}`);
+        is_element_hidden(errorLink, `Error link should be hidden for ${what}`);
+      }
+    }
+  }
+
+  let catUtils = new CategoryUtilities(mgrWin);
+
+  await catUtils.openType("locale");
+  checklist(false);
+
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF, true]]
+  });
+
+  await catUtils.openType("extension");
+  await catUtils.openType("locale");
+  checklist(true);
+
+  await close_manager(mgrWin);
+});