Bug 580298 - Hide version numbers for lightweight themes; r=Mossop a=blocking-betaN+
authorSiddharth Agarwal <sid.bugzilla@gmail.com>
Wed, 26 Jan 2011 14:12:38 -0500
changeset 61337 a6a96e15c369
parent 61336 2d3c0374a0f9
child 61338 63adefe33a92
push id18317
push usereakhgari@mozilla.com
push dateWed, 26 Jan 2011 19:12:56 +0000
treeherdermozilla-central@a6a96e15c369 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop, blocking-betaN
bugs580298
milestone2.0b11pre
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 580298 - Hide version numbers for lightweight themes; r=Mossop a=blocking-betaN+
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/content/extensions.xml
toolkit/mozapps/extensions/test/browser/Makefile.in
toolkit/mozapps/extensions/test/browser/browser_bug580298.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -1154,16 +1154,26 @@ function shouldAutoUpdate(aAddon, aDefau
     return false;
   if (aAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_ENABLE)
     return true;
   if (aAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DISABLE)
     return false;
   return aDefault !== undefined ? aDefault : AddonManager.autoUpdateDefault;
 }
 
+function shouldShowVersionNumber(aAddon) {
+  if (!aAddon.version)
+    return false;
+
+  // The version number is hidden for lightweight themes.
+  if (aAddon.type == "theme")
+    return !/@personas\.mozilla\.org$/.test(aAddon.id);
+
+  return true;
+}
 
 function createItem(aObj, aIsInstall, aIsRemote) {
   let item = document.createElement("richlistitem");
 
   item.setAttribute("class", "addon addon-view");
   item.setAttribute("name", aObj.name);
   item.setAttribute("type", aObj.type);
   item.setAttribute("remote", !!aIsRemote);
@@ -2269,17 +2279,17 @@ var gDetailView = {
       gCategories.select("addons://list/" + aAddon.type);
 
     document.getElementById("detail-name").textContent = aAddon.name;
     var icon = aAddon.icon64URL ? aAddon.icon64URL : aAddon.iconURL;
     document.getElementById("detail-icon").src = icon ? icon : null;
     document.getElementById("detail-creator").setCreator(aAddon.creator, aAddon.homepageURL);
 
     var version = document.getElementById("detail-version");
-    if (aAddon.version) {
+    if (shouldShowVersionNumber(aAddon)) {
       version.hidden = false;
       version.value = aAddon.version;
     } else {
       version.hidden = true;
     }
 
     var screenshot = document.getElementById("detail-screenshot");
     if (aAddon.screenshots && aAddon.screenshots.length > 0) {
--- a/toolkit/mozapps/extensions/content/extensions.xml
+++ b/toolkit/mozapps/extensions/content/extensions.xml
@@ -1089,17 +1089,17 @@
           this.setAttribute("name", aAddon.name);
 
           var iconURL = this.mAddon.iconURL;
           if (iconURL)
             this._icon.src = iconURL;
           else
             this._icon.src = null;
 
-          if (this.mAddon.version)
+          if (shouldShowVersionNumber(this.mAddon))
             this._version.value = this.mAddon.version;
           else
             this._version.hidden = true;
 
           if (this.mAddon.description)
             this._description.value = this.mAddon.description;
           else
             this._description.hidden = true;
@@ -1290,17 +1290,17 @@
                              this.mAddon.install.state != AddonManager.STATE_INSTALLED);
           this._showStatus(showProgress ? "progress" : "none");
         ]]></body>
       </method>
 
       <method name="_updateUpgradeInfo">
         <body><![CDATA[
           // Only update the version string if we're displaying the upgrade info
-          if (this.hasAttribute("upgrade"))
+          if (this.hasAttribute("upgrade") && shouldShowVersionNumber(this.mAddon))
             this._version.value = this.mManualUpdate.version;
         ]]></body>
       </method>
 
       <method name="_fetchReleaseNotes">
         <parameter name="aURI"/>
         <body><![CDATA[
           var self = this;
--- a/toolkit/mozapps/extensions/test/browser/Makefile.in
+++ b/toolkit/mozapps/extensions/test/browser/Makefile.in
@@ -53,16 +53,17 @@ include $(DEPTH)/config/autoconf.mk
   browser_bug562854.js \
   browser_bug562890.js \
   browser_bug562899.js \
   browser_bug562992.js \
   browser_bug567127.js \
   browser_bug567137.js \
   browser_bug572561.js \
   browser_bug577990.js \
+  browser_bug580298.js \
   browser_bug581076.js \
   browser_bug586574.js \
   browser_bug587970.js \
   browser_bug591465.js \
   browser_bug591663.js \
   browser_bug593535.js \
   browser_bug596336.js \
   browser_bug608316.js \
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug580298.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Tests that certain types of addons do not have their version number
+// displayed. This currently only includes lightweight themes.
+
+var gManagerWindow;
+var gCategoryUtilities;
+var gProvider;
+
+function test() {
+  waitForExplicitFinish();
+
+  gProvider = new MockProvider();
+
+  gProvider.createAddons([{
+    id: "extension@tests.mozilla.org",
+    name: "Extension 1",
+    type: "extension",
+    version: "123"
+  }, {
+    id: "theme@tests.mozilla.org",
+    name: "Theme 2",
+    type: "theme",
+    version: "456"
+  }, {
+    id: "lwtheme@personas.mozilla.org",
+    name: "Persona 3",
+    type: "theme",
+    version: "789"
+  }]);
+
+  open_manager(null, function(aWindow) {
+    gManagerWindow = aWindow;
+    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
+    run_next_test();
+  });
+}
+
+function end_test() {
+  close_manager(gManagerWindow, finish);
+}
+
+function get(aId) {
+  return gManagerWindow.document.getElementById(aId);
+}
+
+function get_node(parent, anonid) {
+  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
+}
+
+function open_details(aList, aItem, aCallback) {
+  aList.ensureElementIsVisible(aItem);
+  EventUtils.synthesizeMouseAtCenter(aItem, { clickCount: 1 }, gManagerWindow);
+  EventUtils.synthesizeMouseAtCenter(aItem, { clickCount: 2 }, gManagerWindow);
+  wait_for_view_load(gManagerWindow, aCallback);
+}
+
+function check_addon_has_version(aList, aName, aVersion) {
+  for (let i = 0; i < aList.itemCount; i++) {
+    let item = aList.getItemAtIndex(i);
+    if (get_node(item, "name").value === aName) {
+      ok(true, "Item with correct name found");
+      is(get_node(item, "version").value, aVersion, "Item has correct version");
+      return item;
+    }
+  }
+  ok(false, "Item with correct name was not found");
+  return null;
+}
+
+add_test(function() {
+  gCategoryUtilities.openType("extension", function() {
+    info("Extension");
+    let list = gManagerWindow.document.getElementById("addon-list");
+    let item = check_addon_has_version(list, "Extension 1", "123");
+    open_details(list, item, function() {
+      is_element_visible(get("detail-version"), "Details view has version visible");
+      is(get("detail-version").value, "123", "Details view has correct version");
+      run_next_test();
+    });
+  });
+});
+
+add_test(function() {
+  gCategoryUtilities.openType("theme", function() {
+    info("Normal theme");
+    let list = gManagerWindow.document.getElementById("addon-list");
+    let item = check_addon_has_version(list, "Theme 2", "456");
+    open_details(list, item, function() {
+      is_element_visible(get("detail-version"), "Details view has version visible");
+      is(get("detail-version").value, "456", "Details view has correct version");
+      run_next_test();
+    });
+  });
+});
+
+add_test(function() {
+  gCategoryUtilities.openType("theme", function() {
+    info("Lightweight theme");
+    let list = gManagerWindow.document.getElementById("addon-list");
+    // See that the version isn't displayed
+    let item = check_addon_has_version(list, "Persona 3", "");
+    open_details(list, item, function() {
+      is_element_hidden(get("detail-version"), "Details view has version hidden");
+      // If the version element is hidden then we don't care about its value
+      run_next_test();
+    });
+  });
+});