Bug 1376892 - Don't show stop button for local url loads. r=jaws
☠☠ backed out by b4e656e5a996 ☠ ☠
authorPerry Jiang <jiangperry@gmail.com>
Mon, 10 Jul 2017 13:17:06 -0700
changeset 368982 394e4cd341caa5c111d19905913ba31c0eac4185
parent 368981 6b05837ec165b57ac8d581b8c57d1e942dbd2049
child 368983 92e63be29ec4e09a36d64958db2d4177f80c4598
push id92590
push userfelipc@gmail.com
push dateFri, 14 Jul 2017 23:52:30 +0000
treeherdermozilla-inbound@92e63be29ec4 [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 MozReview-Commit-ID: 9YrsiscPLUs
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:home",
+                                                        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:home",
+                                                        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:home",
+                                                        waitForStateStop: true});
+  let animatePromise = getAnimatePromise(stopReloadContainer);
+  BrowserTestUtils.loadURI(tab.linkedBrowser, "https://example.com");
+  await animatePromise;
+  await waitForNoAnimation(stopReloadContainer);
+  await BrowserTestUtils.removeTab(tab);
+
+  info("Test finished: stop-reload animates when navigating local URI from non-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',