Backed out 2 changesets (bug 1506987, bug 1507200) for browser-chrome failure in toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
authorDorel Luca <dluca@mozilla.com>
Sun, 02 Dec 2018 00:16:20 +0200
changeset 505546 3c08dc2c9eaa6a4892203375fddc160cd9594a52
parent 505545 a2d943e9f9aa4f27bb879b4b1fc065c0189bba98
child 505547 b54b117c15e9abe79342925671ff13a790c1c454
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1506987, 1507200
milestone65.0a1
backs out0b72233729d8b5562eeaaab6031a249bf90a5a8c
fe515e34cc3f080252720e20049dab49815dc194
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
Backed out 2 changesets (bug 1506987, bug 1507200) for browser-chrome failure in toolkit/mozapps/extensions/test/browser/browser_theme_previews.js Backed out changeset 0b72233729d8 (bug 1507200) Backed out changeset fe515e34cc3f (bug 1506987)
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,16 +285,36 @@ 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() {
@@ -1563,26 +1583,16 @@ function sortElements(aElements, aSortBy
     // If we're in descending order, swap a and b, because
     // we don't ever want to have descending uiStates
     if (!aAscending)
       [a, b] = [b, a];
 
     return (UISTATE_ORDER.indexOf(a) - UISTATE_ORDER.indexOf(b));
   }
 
-  // Prioritize themes that have screenshots.
-  function hasPreview(aHasStr, bHasStr) {
-    let aHas = aHasStr == "true";
-    let bHas = bHasStr == "true";
-    if (aHas == bHas)
-      return 0;
-    dump("difference...\n");
-    return aHas ? -1 : 1;
-  }
-
   function getValue(aObj, aKey) {
     if (!aObj)
       return null;
 
     if (aObj.hasAttribute(aKey))
       return aObj.getAttribute(aKey);
 
     var addon = aObj.mAddon || aObj.mInstall;
@@ -1619,23 +1629,19 @@ function sortElements(aElements, aSortBy
     aSortFuncs[i] = stringCompare;
 
     if (sortBy == "uiState")
       aSortFuncs[i] = uiStateCompare;
     else if (DATE_FIELDS.includes(sortBy))
       aSortFuncs[i] = dateCompare;
     else if (NUMERIC_FIELDS.includes(sortBy))
       aSortFuncs[i] = numberCompare;
-    else if (sortBy == "hasPreview")
-      aSortFuncs[i] = hasPreview;
   }
 
 
-  dump(aSortFuncs.join(",") + "\n");
-
   aElements.sort(function(a, b) {
     if (!aAscending)
       [a, b] = [b, a];
 
     for (let i = 0; i < aSortFuncs.length; i++) {
       var sortBy = aSortBy[i];
       var aValue = getValue(a, sortBy);
       var bValue = getValue(b, sortBy);
@@ -1644,20 +1650,18 @@ function sortElements(aElements, aSortBy
         return 0;
       if (!aValue)
         return -1;
       if (!bValue)
         return 1;
       if (aValue != bValue) {
         var result = aSortFuncs[i](aValue, bValue);
 
-        if (result != 0) {
-          dump(`diff ${sortBy}\n`);
+        if (result != 0)
           return result;
-        }
       }
     }
 
     // If we got here, then all values of a and b
     // must have been equal.
     return 0;
 
   });
@@ -2436,25 +2440,20 @@ var gListView = {
       for (let addonItem of aAddonsList)
         elements.push(createItem(addonItem));
 
       for (let installItem of aInstallsList)
         elements.push(createItem(installItem, true));
 
       this.showEmptyNotice(elements.length == 0);
       if (elements.length > 0) {
-        let sortBy;
-        if (aType == "theme") {
-          sortBy = ["uiState", "hasPreview", "name"];
-        } else {
-          sortBy = ["uiState", "name"];
-        }
-        sortElements(elements, sortBy, true);
+        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") {
@@ -2612,24 +2611,17 @@ var gDetailView = {
   },
 
   onUpdateModeChanged() {
     this.onPropertyChanged(["applyBackgroundUpdates"]);
   },
 
   _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;
-      }
-    }
+    setThemeScreenshot(aAddon, this.node);
 
     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" xbl:inherits="src=previewURL"/>
+      <xul:image class="card-heading-image" anonid="theme-screenshot" hidden="true"/>
 
       <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,24 +904,16 @@
           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 : "");
-          this.setAttribute("hasPreview", previewURL ? "true" : "fase");
-
           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"/>
+                      <image class="card-heading-image theme-screenshot" hidden="true"/>
                       <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,17 +76,16 @@ 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]
deleted file mode 100644
--- a/toolkit/mozapps/extensions/test/browser/browser_theme_previews.js
+++ /dev/null
@@ -1,108 +0,0 @@
-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,
-  };
-}
-
-async function init(startPage) {
-  gManagerWindow = await open_manager(null);
-  gCategoryUtilities = new CategoryUtilities(gManagerWindow);
-  return gCategoryUtilities.openType(startPage);
-}
-
-add_task(async function testThemePreviewShown() {
-  await init("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();
-});
-
-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"}));
-  await AddonTestUtils.promiseInstallXPI(getThemeData(themeId(5), {name: "AAA"}, {previewURL: ""}));
-  await AddonTestUtils.promiseInstallXPI(getThemeData(themeId(8), {name: "DDD"}));
-
-  // Enable a theme to make sure it's first.
-  let addon = await AddonManager.getAddonByID(themeId(8));
-  addon.enable();
-
-  // Load themes now that the extensions are setup.
-  await init("theme");
-
-  // Find the order of ids for the ones we installed.
-  let list = gManagerWindow.document.getElementById("addon-list");
-  let idOrder = list.itemChildren
-    .map(row => row.getAttribute("value"))
-    .filter(id => themeIds.includes(id));
-
-  // Check the order.
-  Assert.deepEqual(
-    idOrder,
-    [
-      themeId(8), // The active theme first.
-      themeId(6), themeId(7), // With previews, ordered by name.
-      themeId(5), // The theme without a preview last.
-    ],
-    "Themes are ordered by enabled, previews, then name");
-
-  await close_manager(gManagerWindow);
-  for (let addon of await promiseAddonsByIDs(themeIds)) {
-    await addon.uninstall();
-  }
-});