Bug 1519616 - Explicitly clear theme preview on details for non-themes. r=aswan, a=RyanVM
authorMark Striemer <mstriemer@mozilla.com>
Tue, 15 Jan 2019 19:55:21 +0000
changeset 509523 2ea881a24d05154d0a048e06045f5b5e5ba08481
parent 509522 c789ccba525f0ce9b30faba06177d1ff9fb35042
child 509524 86f5a024cd49e9485a91b89a826815fb0de507b1
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, RyanVM
bugs1519616
milestone65.0
Bug 1519616 - Explicitly clear theme preview on details for non-themes. r=aswan, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D16589
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -2589,16 +2589,17 @@ var gListView = {
 var gDetailView = {
   node: null,
   _addon: null,
   _loadingTimer: null,
   _autoUpdate: null,
 
   initialize() {
     this.node = document.getElementById("detail-view");
+    this.headingImage = this.node.querySelector(".card-heading-image");
 
     this._autoUpdate = document.getElementById("detail-autoUpdate");
 
     this._autoUpdate.addEventListener("command", () => {
       this._addon.applyBackgroundUpdates = this._autoUpdate.value;
     }, true);
   },
 
@@ -2612,18 +2613,20 @@ var gDetailView = {
 
   _updateView(aAddon, aIsRemote, aScrollToPreferences) {
     setSearchLabel(aAddon.type);
 
     // 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;
+        this.headingImage.src = previewURL;
       }
+    } else {
+      this.headingImage.src = "";
     }
 
     AddonManager.addManagerListener(this);
     this.clearLoading();
 
     this._addon = aAddon;
     gEventManager.registerAddonListener(this, aAddon.id);
     gEventManager.registerInstallListener(this);
--- a/toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
@@ -43,40 +43,69 @@ async function init(startPage) {
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   return gCategoryUtilities.openType(startPage);
 }
 
 add_task(async function testThemePreviewShown() {
   await init("theme");
 
   await AddonTestUtils.promiseInstallXPI(getThemeData());
-  let addon = await AddonManager.getAddonByID(id);
+  let theme = await AddonManager.getAddonByID(id);
 
-  ok(addon.screenshots[0].url, "The add-on has a preview URL");
-  let previewURL = addon.screenshots[0].url;
+  ok(theme.screenshots[0].url, "The add-on has a preview URL");
+  let previewURL = theme.screenshots[0].url;
 
   let doc = gManagerWindow.document;
   let item = doc.querySelector(`richlistitem[value="${id}"]`);
 
   await BrowserTestUtils.waitForCondition(
-    () => item.getAttribute("status") == "installed",
+    () => item.getAttribute("status") == "installed" && item.getAttribute("previewURL"),
     "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");
 
+  // Now check that an add-on doesn't have a preview (bug 1519616).
+  let extensionId = "extension@mochi.test";
+  await AddonTestUtils.promiseInstallXPI({
+    "manifest.json": {
+      applications: {
+        gecko: {id: extensionId},
+      },
+      manifest_version: 2,
+      name: "anextension",
+      description: "wow. such extension.",
+      author: "Woof",
+      version: "1",
+    },
+  });
+
+  await gCategoryUtilities.openType("extension");
+
+  // Go to the detail page.
+  item = doc.querySelector(`richlistitem[value="${extensionId}"]`);
+  item.click();
+  await wait_for_view_load(gManagerWindow);
+
+  // Check that the image has no src attribute.
+  image = doc.querySelector(".theme-screenshot");
+  ok(!image.src, "There is no preview for extensions");
+
   await close_manager(gManagerWindow);
-  await addon.uninstall();
+  await theme.uninstall();
+
+  let extension = await AddonManager.getAddonByID(extensionId);
+  await extension.uninstall();
 });
 
 add_task(async function testThemeOrdering() {
   // Install themes before loading the manager, if it's open they'll sort by install date.
   let themeId = id => id + "@mochi.test";
   let themeIds = [themeId(5), themeId(6), themeId(7), themeId(8)];
   await AddonTestUtils.promiseInstallXPI(getThemeData(themeId(6), {name: "BBB"}));
   await AddonTestUtils.promiseInstallXPI(getThemeData(themeId(7), {name: "CCC"}));