Bug 1499693 - Choose correct add-on icon size in about:addons. r=mstriemer,aswan, a=RyanVM
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Wed, 31 Oct 2018 16:15:54 +0000
changeset 498277 8a28169fa91dbde370d47bd91bc1b0c91f89cacf
parent 498276 6099d57303a51b53735b2a81131cfc19dc8c1953
child 498278 39fba433d3258c1086a4575734740760feafb8e7
push id10087
push userryanvm@gmail.com
push dateThu, 01 Nov 2018 13:32:13 +0000
treeherdermozilla-beta@8a28169fa91d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, aswan, RyanVM
bugs1499693
milestone64.0
Bug 1499693 - Choose correct add-on icon size in about:addons. r=mstriemer,aswan, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D9347
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_details.js
toolkit/mozapps/extensions/test/browser/browser_webext_icon.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -2627,17 +2627,17 @@ var gDetailView = {
     document.getElementById("detail-legacy-warning").href = SUPPORT_URL + "webextensions";
 
     // Make sure to select the correct category
     let category = (isDisabledLegacy(aAddon) || isDisabledUnsigned(aAddon)) ?
                    "addons://legacy" : `addons://list/${aAddon.type}`;
     gCategories.select(category);
 
     document.getElementById("detail-name").textContent = aAddon.name;
-    var icon = AddonManager.getPreferredIconURL(aAddon, 64, window);
+    var icon = AddonManager.getPreferredIconURL(aAddon, 32, window);
     document.getElementById("detail-icon").src = icon ? icon : "";
     document.getElementById("detail-creator").setCreator(aAddon.creator, aAddon.homepageURL);
 
     var version = document.getElementById("detail-version");
     if (shouldShowVersionNumber(aAddon)) {
       version.hidden = false;
       version.value = aAddon.version;
     } else {
--- a/toolkit/mozapps/extensions/content/extensions.xml
+++ b/toolkit/mozapps/extensions/content/extensions.xml
@@ -907,17 +907,17 @@
           this.mAddon = aAddon;
 
           this._installStatus.mAddon = this.mAddon;
           this._updateDates();
           this._updateState();
 
           this.setAttribute("name", aAddon.name);
 
-          var iconURL = AddonManager.getPreferredIconURL(aAddon, 32, window);
+          var iconURL = AddonManager.getPreferredIconURL(aAddon, 24, window);
           if (iconURL)
             this._icon.src = iconURL;
           else
             this._icon.src = "";
 
           if (this.mAddon.description)
             this._description.value = this.mAddon.description;
           else
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -87,13 +87,14 @@ skip-if = (verify && (os == 'win'))
 [browser_updatessl.js]
 [browser_webapi.js]
 [browser_webapi_access.js]
 [browser_webapi_addon_listener.js]
 [browser_webapi_enable.js]
 [browser_webapi_install.js]
 [browser_webapi_theme.js]
 [browser_webapi_uninstall.js]
+[browser_webext_icon.js]
 [browser_webext_options.js]
 tags = webextensions
 skip-if = os == 'linux' || (os == 'mac' && debug) # bug 1483347
 [browser_webext_options_addon_reload.js]
 tags = webextensions
--- a/toolkit/mozapps/extensions/test/browser/browser_details.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_details.js
@@ -520,17 +520,17 @@ add_test(function() {
       optionsURL: "chrome://foo/content/options.xul",
       applyBackgroundUpdates: AddonManager.AUTOUPDATE_ENABLE,
       operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE,
     }]);
 
     is(get("detail-name").textContent, "Test add-on replacement", "Name should be correct");
     is_element_visible(get("detail-version"), "Version should not be hidden");
     is(get("detail-version").value, "2.5", "Version should be correct");
-    is(get("detail-icon").src, "chrome://foo/skin/icon264.png", "Icon should be correct");
+    is(get("detail-icon").src, "chrome://foo/skin/icon.png", "Icon should be correct");
     is_element_hidden(get("detail-creator"), "Creator should be hidden");
     is(get("detail-desc").textContent, "Short description replacement", "Description should be correct");
     is(get("detail-fulldesc").textContent, "Longer description replacement", "Full description should be correct");
 
     is_element_hidden(get("detail-contributions"), "Contributions section should be hidden");
 
     is_element_hidden(get("detail-dateUpdated"), "Update date should be hidden");
 
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_webext_icon.js
@@ -0,0 +1,69 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+function pngArrayBuffer(size) {
+  const canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
+  canvas.height = canvas.width = size;
+  const ctx = canvas.getContext("2d");
+  ctx.fillStyle = "blue";
+  ctx.fillRect(0, 0, size, size);
+  return new Promise(resolve => {
+    canvas.toBlob((blob) => {
+      const fileReader = new FileReader();
+      fileReader.onload = () => {
+        resolve(fileReader.result);
+      };
+      fileReader.readAsArrayBuffer(blob);
+    });
+  });
+}
+
+async function checkIconInView(view, name, findIcon) {
+  const manager = await open_manager(view);
+  const icon = findIcon(manager.document);
+  const size = Number(icon.src.match(/icon(\d+)\.png/)[1]);
+  is(icon.clientWidth, icon.clientHeight, `The icon should be square in ${name}`);
+  is(size, icon.clientWidth, `The correct icon size should have been chosen in ${name}`);
+  await close_manager(manager);
+}
+
+add_task(async function test_addon_icon() {
+  // This test loads an extension with a variety of icon sizes, and checks that the
+  // fitting one is chosen. If this fails it's because you changed the icon size in
+  // about:addons but didn't update some AddonManager.getPreferredIconURL call.
+  const id = "@test-addon-icon";
+  const icons = {};
+  const files = {};
+  const file = await pngArrayBuffer(256);
+  for (let size = 1; size <= 256; ++size) {
+    let fileName = `icon${size}.png`;
+    icons[size] = fileName;
+    files[fileName] = file;
+  }
+  const extensionDefinition = {
+    useAddonManager: "temporary",
+    manifest: {
+      "applications": {
+        "gecko": {id},
+      },
+      icons,
+    },
+    files,
+  };
+
+  const extension = ExtensionTestUtils.loadExtension(extensionDefinition);
+  await extension.startup();
+
+  await checkIconInView("addons://list/extension", "list", doc => {
+    const addon = get_addon_element(doc.defaultView, id);
+    const content = doc.getAnonymousElementByAttribute(addon, "class", "content-container");
+    return content.querySelector(".icon");
+  });
+
+  await checkIconInView("addons://detail/" + encodeURIComponent(id), "details", doc => {
+    return doc.getElementById("detail-icon");
+  });
+
+  await extension.unload();
+});