Bug 1402373 - Slack's red badge favicon is shown for no reason and then isn't cleared when all messages are read. r=nanj,Mardak a=sylvestre
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 28 Sep 2017 17:32:57 +0200
changeset 434392 32f35f222072feaaeccd61abbdbbb95d72fcfb3b
parent 434391 79e814603e68d8fb13d12c09481fea06fd6098c0
child 434393 2ffd463c87e049e7bb712092e96300734cc33fc2
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnanj, Mardak, sylvestre
bugs1402373
milestone57.0
Bug 1402373 - Slack's red badge favicon is shown for no reason and then isn't cleared when all messages are read. r=nanj,Mardak a=sylvestre MozReview-Commit-ID: D1t9xo3Dlfv
browser/base/content/test/favicons/.eslintrc.js
browser/base/content/test/favicons/browser.ini
browser/base/content/test/favicons/browser_multiple_icons_in_short_timeframe.js
browser/base/content/test/favicons/discovery.html
browser/base/content/test/favicons/head.js
browser/base/moz.build
browser/modules/ContentLinkHandler.jsm
copy from browser/base/content/test/general/.eslintrc.js
copy to browser/base/content/test/favicons/.eslintrc.js
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/favicons/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+support-files =
+  head.js
+  discovery.html
+
+[browser_multiple_icons_in_short_timeframe.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/favicons/browser_multiple_icons_in_short_timeframe.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function() {
+  const ROOT = "http://mochi.test:8888/browser/browser/base/content/test/favicons/";
+  const URL = ROOT + "discovery.html";
+
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
+
+  // Because there is debounce logic in ContentLinkHandler.jsm to reduce the
+  // favicon loads, we have to wait some time before checking that icon was
+  // stored properly.
+  let promiseIcon = BrowserTestUtils.waitForCondition(
+    () => {
+      let tabIcon = gBrowser.getIcon();
+      info("Found icon " + tabIcon);
+      return tabIcon == ROOT + "two.png";
+    },
+    "wait for icon load to finish", 200, 25);
+
+  await ContentTask.spawn(gBrowser.selectedBrowser, ROOT, root => {
+    let doc = content.document;
+    let head = doc.getElementById("linkparent");
+    let link = doc.createElement("link");
+    link.rel = "icon";
+    link.href = root + "one.png";
+    link.type = "image/png";
+    head.appendChild(link);
+    let link2 = link.cloneNode(false);
+    link2.href = root + "two.png";
+    head.appendChild(link2);
+  });
+
+  await promiseIcon;
+  // The test must have at least one pass.
+  Assert.equal(gBrowser.getIcon(), ROOT + "two.png",
+               "The expected icon has been set");
+
+  await BrowserTestUtils.removeTab(tab);
+});
copy from browser/base/content/test/general/discovery.html
copy to browser/base/content/test/favicons/discovery.html
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/favicons/head.js
@@ -0,0 +1,9 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserTestUtils",
+  "resource://testing-common/BrowserTestUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "ContentTask",
+  "resource://testing-common/ContentTask.jsm");
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -17,16 +17,17 @@ MOCHITEST_CHROME_MANIFESTS += [
     'content/test/chrome/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += [
     'content/test/about/browser.ini',
     'content/test/alerts/browser.ini',
     'content/test/captivePortal/browser.ini',
     'content/test/contextMenu/browser.ini',
+    'content/test/favicons/browser.ini',
     'content/test/forms/browser.ini',
     'content/test/general/browser.ini',
     'content/test/metaTags/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/pageinfo/browser.ini',
     'content/test/performance/browser.ini',
     'content/test/performance/hidpi/browser.ini',
     'content/test/performance/lowdpi/browser.ini',
--- a/browser/modules/ContentLinkHandler.jsm
+++ b/browser/modules/ContentLinkHandler.jsm
@@ -151,17 +151,17 @@ function faviconTimeoutCallback(aFavicon
     }
 
     // Note that some sites use hi-res icons without specifying them as
     // apple-touch or fluid icons.
     if (icon.isRichIcon || icon.width >= FAVICON_RICH_ICON_MIN_WIDTH) {
       if (!largestRichIcon || largestRichIcon.width < icon.width) {
         largestRichIcon = icon;
       }
-    } else if (!defaultIcon) {
+    } else {
       defaultIcon = icon;
     }
   }
 
   // Now set the favicons for the page in the following order:
   // 1. Set the best rich icon if any.
   // 2. Set the preferred one if any, otherwise use the default one.
   // This order allows smaller icon frames to eventually override rich icon