Bug 1376892 - Don't show stop button for local url loads. r=jaws
authorPerry Jiang <jiangperry@gmail.com>
Mon, 10 Jul 2017 13:17:06 -0700
changeset 418712 bb2904560e11fcaded572b00e0b1f434844a43c5
parent 418711 52da209e46fbcb3e7913ef28c0d4762ed13f8a62
child 418713 dbb63faa7da342f7e55ab65c33e905dafd5b7295
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1376892
milestone56.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 1376892 - Don't show stop button for local url loads. r=jaws
browser/base/content/browser.js
browser/base/content/test/about/.eslintrc.js
browser/base/content/test/about/browser.ini
browser/base/content/test/about/browser_aboutStopReload.js
browser/base/moz.build
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4987,17 +4987,17 @@ var CombinedStopReload = {
       this.animate = Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled") &&
                      Services.prefs.getBoolPref("browser.stopReloadAnimation.enabled");
       Services.prefs.addObserver("toolkit.cosmeticAnimations.enabled", this);
       this.stopReloadContainer.addEventListener("animationend", this);
     });
   },
 
   switchToStop(aRequest, aWebProgress) {
-    if (!this._initialized)
+    if (!this._initialized || !this._shouldSwitch(aRequest))
       return;
 
     let shouldAnimate = AppConstants.MOZ_PHOTON_ANIMATIONS &&
                         aRequest instanceof Ci.nsIRequest &&
                         aWebProgress.isTopLevel &&
                         aWebProgress.isLoadingDocument &&
                         this.animate;
 
@@ -5005,17 +5005,18 @@ var CombinedStopReload = {
     if (shouldAnimate)
       this.stopReloadContainer.setAttribute("animate", "true");
     else
       this.stopReloadContainer.removeAttribute("animate");
     this.reload.setAttribute("displaystop", "true");
   },
 
   switchToReload(aRequest, aWebProgress) {
-    if (!this._initialized)
+    if (!this._initialized || !this._shouldSwitch(aRequest) ||
+        !this.reload.hasAttribute("displaystop"))
       return;
 
     let shouldAnimate = AppConstants.MOZ_PHOTON_ANIMATIONS &&
                         aRequest instanceof Ci.nsIRequest &&
                         aWebProgress.isTopLevel &&
                         !aWebProgress.isLoadingDocument &&
                         this.animate;
 
@@ -5042,16 +5043,29 @@ var CombinedStopReload = {
     this.reload.disabled = true;
     this._timer = setTimeout(function(self) {
       self._timer = 0;
       self.reload.disabled = XULBrowserWindow.reloadCommand
                                              .getAttribute("disabled") == "true";
     }, 650, this);
   },
 
+  _shouldSwitch(aRequest) {
+    if (!aRequest ||
+        !aRequest.originalURI ||
+        aRequest.originalURI.spec.startsWith("about:reader"))
+      return true;
+
+    if (aRequest.originalURI.schemeIs("chrome") ||
+        aRequest.originalURI.schemeIs("about"))
+      return false;
+
+    return true;
+  },
+
   _cancelTransition() {
     if (this._timer) {
       clearTimeout(this._timer);
       this._timer = 0;
     }
   }
 };
 
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/about/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/browser-test"
+  ]
+};
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/about/browser.ini
@@ -0,0 +1,1 @@
+[browser_aboutStopReload.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/about/browser_aboutStopReload.js
@@ -0,0 +1,90 @@
+async function waitForNoAnimation(elt) {
+  return BrowserTestUtils.waitForCondition(() => !elt.hasAttribute("animate"));
+}
+
+async function getAnimatePromise(elt) {
+  return BrowserTestUtils.waitForAttribute("animate", elt)
+    .then(() => Assert.ok(true, `${elt.id} should animate`));
+}
+
+function stopReloadMutationCallback() {
+  Assert.ok(false, "stop-reload's animate attribute should not have been mutated");
+}
+
+add_task(async function checkDontShowStopOnNewTab() {
+  let stopReloadContainer = document.getElementById("stop-reload-button");
+  let stopReloadContainerObserver = new MutationObserver(stopReloadMutationCallback);
+
+  await waitForNoAnimation(stopReloadContainer);
+  stopReloadContainerObserver.observe(stopReloadContainer, { attributeFilter: ["animate"]});
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+                                                        opening: "about:robots",
+                                                        waitForStateStop: true});
+  await BrowserTestUtils.removeTab(tab);
+
+  Assert.ok(true, "Test finished: stop-reload does not animate when navigating to local URI on new tab");
+  stopReloadContainerObserver.disconnect();
+});
+
+add_task(async function checkDontShowStopFromLocalURI() {
+  let stopReloadContainer = document.getElementById("stop-reload-button");
+  let stopReloadContainerObserver = new MutationObserver(stopReloadMutationCallback);
+
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+                                                        opening: "about:robots",
+                                                        waitForStateStop: true});
+  await waitForNoAnimation(stopReloadContainer);
+  stopReloadContainerObserver.observe(stopReloadContainer, { attributeFilter: ["animate"]});
+  await BrowserTestUtils.loadURI(tab.linkedBrowser, "about:mozilla");
+  await BrowserTestUtils.removeTab(tab);
+
+  Assert.ok(true, "Test finished: stop-reload does not animate when navigating between local URIs");
+  stopReloadContainerObserver.disconnect();
+});
+
+add_task(async function checkDontShowStopFromNonLocalURI() {
+  let stopReloadContainer = document.getElementById("stop-reload-button");
+  let stopReloadContainerObserver = new MutationObserver(stopReloadMutationCallback);
+
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+                                                        opening: "https://example.com",
+                                                        waitForStateStop: true});
+  await waitForNoAnimation(stopReloadContainer);
+  stopReloadContainerObserver.observe(stopReloadContainer, { attributeFilter: ["animate"]});
+  await BrowserTestUtils.loadURI(tab.linkedBrowser, "about:mozilla");
+  await BrowserTestUtils.removeTab(tab);
+
+  Assert.ok(true, "Test finished: stop-reload does not animate when navigating to local URI from non-local URI");
+  stopReloadContainerObserver.disconnect();
+});
+
+add_task(async function checkDoShowStopOnNewTab() {
+  let stopReloadContainer = document.getElementById("stop-reload-button");
+  let animatePromise = getAnimatePromise(stopReloadContainer);
+
+  await waitForNoAnimation(stopReloadContainer);
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+                                                        opening: "https://example.com",
+                                                        waitForStateStop: true});
+  await animatePromise;
+  await waitForNoAnimation(stopReloadContainer);
+  await BrowserTestUtils.removeTab(tab);
+
+  info("Test finished: stop-reload animates when navigating to non-local URI on new tab");
+});
+
+add_task(async function checkDoShowStopFromLocalURI() {
+  let stopReloadContainer = document.getElementById("stop-reload-button");
+
+  await waitForNoAnimation(stopReloadContainer);
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+                                                        opening: "about:robots",
+                                                        waitForStateStop: true});
+  let animatePromise = getAnimatePromise(stopReloadContainer);
+  await BrowserTestUtils.loadURI(tab.linkedBrowser, "https://example.com");
+  await animatePromise;
+  await waitForNoAnimation(stopReloadContainer);
+  await BrowserTestUtils.removeTab(tab);
+
+  info("Test finished: stop-reload animates when navigating to non-local URI from local URI");
+});
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -10,16 +10,17 @@ MOCHITEST_MANIFESTS += [
     'content/test/general/mochitest.ini',
 ]
 
 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/forms/browser.ini',
     'content/test/general/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/pageinfo/browser.ini',
     'content/test/performance/browser.ini',