Bug 1519616 - Explicitly clear theme preview on details for non-themes r=aswan
authorMark Striemer <mstriemer@mozilla.com>
Tue, 15 Jan 2019 19:55:21 +0000
changeset 511085 de208c99e4777cc43aada1e5f52f67f24d63834e
parent 511084 4ebefe9136b5a52ce58b9b46e33e4edf0b23b3b7
child 511086 8ffff925bbb66f61c6b17322c5081628a0c92f16
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1519616
milestone66.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 1519616 - Explicitly clear theme preview on details for non-themes r=aswan 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
@@ -2608,16 +2608,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);
   },
 
@@ -2631,18 +2632,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"}));