Bug 1543037 - Improve "Reload all tabs" experience. r=johannh
authorErica Wright <ewright@mozilla.com>
Wed, 24 Apr 2019 15:43:40 +0000
changeset 471320 60c8ad955f976d5f88887fe71294f6185c02e9c5
parent 471319 904076df6327430699a83cfc75c2caca72dfa872
child 471321 d0eebfb3d9160645793e1ad8a04b89b76faad529
push id112913
push useropoprus@mozilla.com
push dateThu, 25 Apr 2019 22:21:16 +0000
treeherdermozilla-inbound@5279ac14ae48 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1543037
milestone68.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 1543037 - Improve "Reload all tabs" experience. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D27936
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/tests/browser_contentblocking.js
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -469,21 +469,21 @@ var gPrivacyPane = {
     Preferences.get("network.cookie.cookieBehavior").on("change",
       gPrivacyPane.readBlockCookies.bind(gPrivacyPane));
     Preferences.get("browser.contentblocking.category").on("change",
       gPrivacyPane.highlightCBCategory);
 
     // If any relevant content blocking pref changes, show a warning that the changes will
     // not be implemented until they refresh their tabs.
     for (let pref of CONTENT_BLOCKING_PREFS) {
-      Preferences.get(pref).on("change", gPrivacyPane.notifyUserToReload);
+      Preferences.get(pref).on("change", gPrivacyPane.maybeNotifyUserToReload);
     }
-    Preferences.get("urlclassifier.trackingTable").on("change", gPrivacyPane.notifyUserToReload);
+    Preferences.get("urlclassifier.trackingTable").on("change", gPrivacyPane.maybeNotifyUserToReload);
     for (let button of document.querySelectorAll(".reload-tabs-button")) {
-      button.addEventListener("command", gPrivacyPane.reloadAllTabs);
+      button.addEventListener("command", gPrivacyPane.reloadAllOtherTabs);
     }
 
     let cryptoMinersOption = document.getElementById("contentBlockingCryptominersOption");
     let fingerprintersOption = document.getElementById("contentBlockingFingerprintersOption");
 
     cryptoMinersOption.hidden =
       !Services.prefs.getBoolPref("browser.contentblocking.cryptomining.preferences.ui.enabled");
     fingerprintersOption.hidden =
@@ -1116,31 +1116,52 @@ var gPrivacyPane = {
       case "all-third-parties":
         return Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN;
       default:
         return undefined;
     }
   },
 
   /**
-   * Reload all tabs in all windows.
+   * Reload all tabs in all windows, except the active Preferences tab.
    */
-  reloadAllTabs() {
+  reloadAllOtherTabs() {
+    let activeWindow = window.BrowserWindowTracker.getTopWindow();
+    let selectedPrefTab = activeWindow.gBrowser.selectedTab;
     for (let win of window.BrowserWindowTracker.orderedWindows) {
       let tabbrowser = win.gBrowser;
-      tabbrowser.reloadTabs(tabbrowser.tabs);
+      let tabsToReload = [...tabbrowser.tabs];
+      if (win == activeWindow ) {
+        tabsToReload = tabsToReload.filter(tab => tab !== selectedPrefTab);
+      }
+      tabbrowser.reloadTabs(tabsToReload);
+    }
+    for (let notification of document.querySelectorAll(".reload-tabs")) {
+      notification.hidden = true;
     }
   },
 
   /**
-   * Show a warning to the user that they need to reload their tabs to apply the setting.
+   * If there are more tabs than just the preferences tab, show a warning to the user that
+   * they need to reload their tabs to apply the setting.
    */
-  notifyUserToReload() {
-    for (let notification of document.querySelectorAll(".reload-tabs")) {
-      notification.hidden = false;
+  maybeNotifyUserToReload() {
+    let shouldShow = false;
+    if (window.BrowserWindowTracker.orderedWindows.length > 1) {
+      shouldShow = true;
+    } else {
+      let tabbrowser = window.BrowserWindowTracker.getTopWindow().gBrowser;
+      if (tabbrowser.tabs.length > 1) {
+        shouldShow = true;
+      }
+    }
+    if (shouldShow) {
+      for (let notification of document.querySelectorAll(".reload-tabs")) {
+        notification.hidden = false;
+      }
     }
   },
 
   /**
    * Displays fine-grained, per-site preferences for cookies.
    */
   showCookieExceptions() {
     var params = {
--- a/browser/components/preferences/in-content/tests/browser_contentblocking.js
+++ b/browser/components/preferences/in-content/tests/browser_contentblocking.js
@@ -6,16 +6,17 @@ ChromeUtils.defineModuleGetter(this, "Pr
 const TP_PREF = "privacy.trackingprotection.enabled";
 const TP_PBM_PREF = "privacy.trackingprotection.pbmode.enabled";
 const NCB_PREF = "network.cookie.cookieBehavior";
 const CAT_PREF = "browser.contentblocking.category";
 const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled";
 const CM_PREF = "privacy.trackingprotection.cryptomining.enabled";
 const PREF_TEST_NOTIFICATIONS = "browser.safebrowsing.test-notifications.enabled";
 const STRICT_PREF = "browser.contentblocking.features.strict";
+const PRIVACY_PAGE = "about:preferences#privacy";
 
 const {
   EnterprisePolicyTesting,
   PoliciesPrefTracker,
 } = ChromeUtils.import("resource://testing-common/EnterprisePolicyTesting.jsm", null);
 
 requestLongerTimeout(2);
 
@@ -486,8 +487,50 @@ add_task(async function testContentBlock
   Services.prefs.setStringPref(CAT_PREF, "strict");
 
   let strictWarning = doc.querySelector("#contentBlockingOptionStrict .content-blocking-warning.reload-tabs");
   ok(!BrowserTestUtils.is_hidden(strictWarning), "The warning in the strict section should be showing");
 
   Services.prefs.setStringPref(CAT_PREF, "standard");
   gBrowser.removeCurrentTab();
 });
+
+// Tests that changing a content blocking pref does not show the content blocking warning
+// if it is the only tab.
+add_task(async function testContentBlockingReloadWarning() {
+  Services.prefs.setStringPref(CAT_PREF, "standard");
+  await BrowserTestUtils.loadURI(gBrowser.selectedBrowser, PRIVACY_PAGE);
+
+  let reloadWarnings = [...gBrowser.contentDocument.querySelectorAll(".content-blocking-warning.reload-tabs")];
+  ok(reloadWarnings.every((el) => el.hidden), "all of the warnings to reload tabs are initially hidden");
+
+  is(BrowserWindowTracker.windowCount, 1, "There is only one window open");
+  is(gBrowser.tabs.length, 1, "There is only one tab open");
+  Services.prefs.setStringPref(CAT_PREF, "strict");
+
+  ok(reloadWarnings.every((el) => el.hidden), "all of the warnings to reload tabs are still hidden");
+  Services.prefs.setStringPref(CAT_PREF, "standard");
+  await BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "about:newtab");
+});
+
+// Checks that the reload tabs message reloads all tabs except the active tab.
+add_task(async function testReloadTabsMessage() {
+  Services.prefs.setStringPref(CAT_PREF, "strict");
+  let exampleTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com");
+  await openPreferencesViaOpenPreferencesAPI("privacy", {leaveOpen: true});
+  let doc = gBrowser.contentDocument;
+  let standardWarning = doc.querySelector("#contentBlockingOptionStandard .content-blocking-warning.reload-tabs");
+  let standardReloadButton = doc.querySelector("#contentBlockingOptionStandard .reload-tabs-button");
+
+  Services.prefs.setStringPref(CAT_PREF, "standard");
+  ok(!BrowserTestUtils.is_hidden(standardWarning), "The warning in the standard section should be showing");
+
+  standardReloadButton.click();
+  // The example page had a load event
+  await BrowserTestUtils.browserLoaded(exampleTab.linkedBrowser);
+
+  ok(BrowserTestUtils.is_hidden(standardWarning), "The warning in the standard section should have hidden after being clicked");
+
+  // cleanup
+  Services.prefs.setStringPref(CAT_PREF, "standard");
+  gBrowser.removeTab(exampleTab);
+  gBrowser.removeCurrentTab();
+});