From 0cdf73ebb1771b6783c307855331517d807802d3 Mon Sep 17 00:00:00 2001 From: Nihanth Subramanya Date: Sun, 23 Jun 2019 01:36:36 +0000 Subject: [PATCH] Bug 1550662 - Make "Reload All Tabs" simply discard browsers when switching Content Blocking modes. r=mconley,johannh Differential Revision: https://phabricator.services.mozilla.com/D34524 --HG-- extra : moz-landing-system : lando --- .../preferences/in-content/privacy.js | 27 ++++++++++++------- .../tests/browser_contentblocking.js | 11 ++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/browser/components/preferences/in-content/privacy.js b/browser/components/preferences/in-content/privacy.js index 9afe1c5672a2..bef668269195 100644 --- a/browser/components/preferences/in-content/privacy.js +++ b/browser/components/preferences/in-content/privacy.js @@ -1150,19 +1150,26 @@ var gPrivacyPane = { }, /** - * Reload all tabs in all windows, except the active Preferences tab. + * Discard the browsers of all tabs in all windows. Pinned tabs, as + * well as tabs for which discarding doesn't succeed (e.g. selected + * tabs, tabs with beforeunload listeners), are reloaded. */ reloadAllOtherTabs() { - let activeWindow = window.BrowserWindowTracker.getTopWindow(); - let selectedPrefTab = activeWindow.gBrowser.selectedTab; - for (let win of window.BrowserWindowTracker.orderedWindows) { - let tabbrowser = win.gBrowser; - let tabsToReload = [...tabbrowser.tabs]; - if (win == activeWindow ) { - tabsToReload = tabsToReload.filter(tab => tab !== selectedPrefTab); + let ourTab = BrowserWindowTracker.getTopWindow().gBrowser.selectedTab; + BrowserWindowTracker.orderedWindows.forEach(win => { + let otherGBrowser = win.gBrowser; + for (let tab of otherGBrowser.tabs) { + if (tab == ourTab) { + // Don't reload our preferences tab. + continue; + } + + if (tab.pinned || !otherGBrowser.discardBrowser(tab)) { + otherGBrowser.reloadTab(tab); + } } - tabbrowser.reloadTabs(tabsToReload); - } + }); + for (let notification of document.querySelectorAll(".reload-tabs")) { notification.hidden = true; } diff --git a/browser/components/preferences/in-content/tests/browser_contentblocking.js b/browser/components/preferences/in-content/tests/browser_contentblocking.js index 23947a6f2a22..7a0778f0aab3 100644 --- a/browser/components/preferences/in-content/tests/browser_contentblocking.js +++ b/browser/components/preferences/in-content/tests/browser_contentblocking.js @@ -525,6 +525,8 @@ add_task(async function testContentBlockingReloadWarning() { add_task(async function testReloadTabsMessage() { Services.prefs.setStringPref(CAT_PREF, "strict"); let exampleTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com"); + let examplePinnedTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com"); + gBrowser.pinTab(examplePinnedTab); await openPreferencesViaOpenPreferencesAPI("privacy", {leaveOpen: true}); let doc = gBrowser.contentDocument; let standardWarning = doc.querySelector("#contentBlockingOptionStandard .content-blocking-warning.reload-tabs"); @@ -533,14 +535,19 @@ add_task(async function testReloadTabsMessage() { Services.prefs.setStringPref(CAT_PREF, "standard"); ok(!BrowserTestUtils.is_hidden(standardWarning), "The warning in the standard section should be showing"); + let exampleTabBrowserDiscardedPromise = BrowserTestUtils.waitForEvent(exampleTab, "TabBrowserDiscarded"); + let examplePinnedTabLoadPromise = BrowserTestUtils.browserLoaded(examplePinnedTab.linkedBrowser); standardReloadButton.click(); - // The example page had a load event - await BrowserTestUtils.browserLoaded(exampleTab.linkedBrowser); + // The pinned example page had a load event + await examplePinnedTabLoadPromise; + // The other one had its browser discarded + await exampleTabBrowserDiscardedPromise; 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.removeTab(examplePinnedTab); gBrowser.removeCurrentTab(); });