Bug 1506987 - Include preview for theme in AOM if it is added while open r=aswan
☠☠ backed out by 3c08dc2c9eaa ☠ ☠
authorMark Striemer <mstriemer@mozilla.com>
Sat, 01 Dec 2018 03:55:25 +0000
changeset 508320 fe515e34cc3f080252720e20049dab49815dc194
parent 508319 caef08c907dd6519f2b918cfcfb11a02e3b5cd18
child 508321 0b72233729d8b5562eeaaab6031a249bf90a5a8c
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1506987
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506987 - Include preview for theme in AOM if it is added while open r=aswan Differential Revision: https://phabricator.services.mozilla.com/D12593
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/content/extensions.xml
toolkit/mozapps/extensions/content/extensions.xul
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -285,36 +285,16 @@ function setSearchLabel(type) {
       .textContent = gStrings.ext.GetStringFromName(`searchLabel.${type}`);
     searchLabel.hidden = false;
   } else {
     searchLabel.textContent = "";
     searchLabel.hidden = true;
   }
 }
 
-function setThemeScreenshot(addon, node) {
-  let findElement = () => node.querySelector(".theme-screenshot")
-    || document.getAnonymousElementByAttribute(node, "anonid", "theme-screenshot");
-  let screenshot = findElement();
-  if (!screenshot) {
-    // Force a layout since screenshot might not exist yet on Windows.
-    node.clientTop;
-    screenshot = findElement();
-  }
-  // There's a test that doesn't have this for some reason, but it's doing weird things.
-  if (!screenshot)
-    return;
-  if (addon.type == "theme" && addon.screenshots && addon.screenshots.length > 0) {
-    screenshot.setAttribute("src", addon.screenshots[0].url);
-    screenshot.hidden = false;
-  } else {
-    screenshot.hidden = true;
-  }
-}
-
 /**
  * Obtain the main DOMWindow for the current context.
  */
 function getMainWindow() {
   return window.docShell.rootTreeItem.domWindow;
 }
 
 function getBrowserElement() {
@@ -2443,17 +2423,16 @@ var gListView = {
       for (let installItem of aInstallsList)
         elements.push(createItem(installItem, true));
 
       this.showEmptyNotice(elements.length == 0);
       if (elements.length > 0) {
         sortElements(elements, ["uiState", "name"], true);
         for (let element of elements) {
           this._listBox.appendChild(element);
-          setThemeScreenshot(element.mAddon, element);
         }
       }
 
       this.filterDisabledUnsigned(showOnlyDisabledUnsigned);
       let legacyNotice = document.getElementById("legacy-extensions-notice");
       if (showLegacyInfo) {
         let el = document.getElementById("legacy-extensions-description");
         if (el.childNodes[0].nodeName == "#text") {
@@ -2611,17 +2590,24 @@ var gDetailView = {
   },
 
   onUpdateModeChanged() {
     this.onPropertyChanged(["applyBackgroundUpdates"]);
   },
 
   _updateView(aAddon, aIsRemote, aScrollToPreferences) {
     setSearchLabel(aAddon.type);
-    setThemeScreenshot(aAddon, this.node);
+
+    // Set the preview image for themes, if available.
+    if (aAddon.type == "theme") {
+      let previewURL = aAddon.screenshots && aAddon.screenshots[0] && aAddon.screenshots[0].url;
+      if (previewURL) {
+        this.node.querySelector(".card-heading-image").src = previewURL;
+      }
+    }
 
     AddonManager.addManagerListener(this);
     this.clearLoading();
 
     this._addon = aAddon;
     gEventManager.registerAddonListener(this, aAddon.id);
     gEventManager.registerInstallListener(this);
 
--- a/toolkit/mozapps/extensions/content/extensions.xml
+++ b/toolkit/mozapps/extensions/content/extensions.xml
@@ -586,17 +586,17 @@
         <xul:label anonid="pending" flex="1"/>
         <xul:button anonid="undo-btn" class="button-link"
                     label="&addon.undoAction.label;"
                     tooltipText="&addon.undoAction.tooltip;"
                     oncommand="document.getBindingParent(this).undo();"/>
         <xul:spacer flex="5000"/> <!-- Necessary to allow the message to wrap -->
       </xul:hbox>
 
-      <xul:image class="card-heading-image" anonid="theme-screenshot" hidden="true"/>
+      <xul:image class="card-heading-image" anonid="theme-screenshot" xbl:inherits="src=previewURL"/>
 
       <xul:hbox class="content-container" align="center">
         <xul:vbox class="icon-container">
           <xul:image anonid="icon" class="icon"/>
         </xul:vbox>
         <xul:vbox class="content-inner-container" flex="1">
           <xul:hbox class="basicinfo-container">
               <xul:hbox class="name-container">
@@ -904,16 +904,23 @@
           else
             this._icon.src = "";
 
           if (this.mAddon.description)
             this._description.value = this.mAddon.description;
           else
             this._description.hidden = true;
 
+          // Set a previewURL for themes if one exists.
+          let previewURL = this.mAddon.type == "theme" &&
+            this.mAddon.screenshots &&
+            this.mAddon.screenshots[0] &&
+            this.mAddon.screenshots[0].url;
+          this.setAttribute("previewURL", previewURL ? previewURL : "");
+
           let legacyWarning = legacyExtensionsEnabled && !this.mAddon.install &&
             isLegacyExtension(this.mAddon);
           this.setAttribute("legacy", legacyWarning);
           document.getAnonymousElementByAttribute(this, "anonid", "legacy").href = SUPPORT_URL + "webextensions";
 
           if (!("applyBackgroundUpdates" in this.mAddon) ||
               (this.mAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DISABLE ||
                (this.mAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DEFAULT &&
--- a/toolkit/mozapps/extensions/content/extensions.xul
+++ b/toolkit/mozapps/extensions/content/extensions.xul
@@ -477,17 +477,17 @@
                               label="&addon.undoAction.label;"
                               tooltipText="&addon.undoAction.tooltip;"
                               command="cmd_cancelOperation"/>
                       <spacer flex="5000"/> <!-- Necessary to allow the message to wrap -->
                     </hbox>
                   </vbox>
                   <hbox class="card addon-detail" align="start">
                     <vbox flex="1">
-                      <image class="card-heading-image theme-screenshot" hidden="true"/>
+                      <image class="card-heading-image theme-screenshot"/>
                       <hbox align="start">
                         <vbox id="detail-icon-container" align="end">
                           <image id="detail-icon" class="icon"/>
                         </vbox>
                         <vbox id="detail-summary">
                           <hbox id="detail-name-container" class="name-container"
                                 align="start">
                             <label id="detail-name" flex="1"/>
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -76,16 +76,17 @@ skip-if = os == 'linux' && !debug # Bug 
 [browser_inlinesettings_browser.js]
 skip-if = os == 'mac' || os == 'linux' # Bug 1483347
 [browser_installssl.js]
 skip-if = verify
 [browser_langpack_signing.js]
 [browser_legacy.js]
 [browser_legacy_pre57.js]
 [browser_list.js]
+[browser_theme_previews.js]
 [browser_manualupdates.js]
 [browser_pluginprefs.js]
 [browser_pluginprefs_is_not_disabled.js]
 [browser_plugin_enabled_state_locked.js]
 [browser_recentupdates.js]
 [browser_reinstall.js]
 [browser_sorting.js]
 [browser_sorting_plugins.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
@@ -0,0 +1,67 @@
+const {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm", {});
+
+let gManagerWindow;
+let gCategoryUtilities;
+
+function imageBufferFromDataURI(encodedImageData) {
+  let decodedImageData = atob(encodedImageData);
+  return Uint8Array.from(decodedImageData, byte => byte.charCodeAt(0)).buffer;
+}
+const img = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==";
+const imageBuffer = imageBufferFromDataURI(img);
+
+const id = "theme@mochi.test";
+
+function getThemeData(_id = id, manifest = {}, files = {}) {
+  return {
+    "manifest.json": {
+      applications: {
+        gecko: {id: _id},
+      },
+      manifest_version: 2,
+      name: "atheme",
+      description: "wow. such theme.",
+      author: "Pixel Pusher",
+      version: "1",
+      theme: {},
+      ...manifest,
+    },
+    "preview.png": imageBuffer,
+    ...files,
+  };
+}
+
+add_task(async function testThemePreviewShown() {
+  gManagerWindow = await open_manager(null);
+  gCategoryUtilities = new CategoryUtilities(gManagerWindow);
+
+  await gCategoryUtilities.openType("theme");
+
+  AddonTestUtils.initMochitest(this);
+
+  await AddonTestUtils.promiseInstallXPI(getThemeData());
+  let addon = await AddonManager.getAddonByID(id);
+
+  ok(addon.screenshots[0].url, "The add-on has a preview URL");
+  let previewURL = addon.screenshots[0].url;
+
+  let doc = gManagerWindow.document;
+  let item = doc.querySelector(`richlistitem[value="${id}"]`);
+
+  await BrowserTestUtils.waitForCondition(
+    () => item.getAttribute("status") == "installed",
+    "Wait for the item to update to installed");
+
+  is(item.getAttribute("previewURL"), previewURL, "The previewURL is set on the item");
+  let image = doc.getAnonymousElementByAttribute(item, "anonid", "theme-screenshot");
+  is(image.src, previewURL, "The previewURL is set on the image src");
+
+  item.click();
+  await wait_for_view_load(gManagerWindow);
+
+  image = doc.querySelector(".theme-screenshot");
+  is(image.src, previewURL, "The previewURL is set on the detail image src");
+
+  await close_manager(gManagerWindow);
+  await addon.uninstall();
+});