зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1348252 - Disable buttons and display loading message in Site Data section while loading data, r=Gijs
MozReview-Commit-ID: 9EfG71hRoDe --HG-- extra : rebase_source : 5163e88d3ebd7b7dd0578b27e9934e6a340bf6fb
This commit is contained in:
Родитель
7f0b8b2dd6
Коммит
1338acd53a
|
@ -43,6 +43,8 @@ this.SiteDataManager = {
|
|||
_quotaUsageRequests: null,
|
||||
|
||||
updateSites() {
|
||||
Services.obs.notifyObservers(null, "sitedatamanager:updating-sites", null);
|
||||
|
||||
// Clear old data and requests first
|
||||
this._sites.clear();
|
||||
this._cancelQuotaUpdate();
|
||||
|
|
|
@ -55,9 +55,11 @@ var gAdvancedPane = {
|
|||
|
||||
if (Services.prefs.getBoolPref("browser.storageManager.enabled")) {
|
||||
Services.obs.addObserver(this, "sitedatamanager:sites-updated", false);
|
||||
Services.obs.addObserver(this, "sitedatamanager:updating-sites", false);
|
||||
let unload = () => {
|
||||
window.removeEventListener("unload", unload);
|
||||
Services.obs.removeObserver(this, "sitedatamanager:sites-updated");
|
||||
Services.obs.removeObserver(this, "sitedatamanager:updating-sites");
|
||||
};
|
||||
window.addEventListener("unload", unload);
|
||||
SiteDataManager.updateSites();
|
||||
|
@ -68,6 +70,8 @@ var gAdvancedPane = {
|
|||
|
||||
let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "storage-permissions";
|
||||
document.getElementById("siteDataLearnMoreLink").setAttribute("href", url);
|
||||
let siteDataGroup = document.getElementById("siteDataGroup");
|
||||
siteDataGroup.hidden = false;
|
||||
}
|
||||
|
||||
setEventListener("layers.acceleration.disabled", "change",
|
||||
|
@ -358,16 +362,22 @@ var gAdvancedPane = {
|
|||
gSubDialog.open("chrome://browser/content/preferences/siteDataSettings.xul");
|
||||
},
|
||||
|
||||
updateTotalSiteDataSize() {
|
||||
SiteDataManager.getTotalUsage()
|
||||
.then(usage => {
|
||||
let size = DownloadUtils.convertByteUnits(usage);
|
||||
let prefStrBundle = document.getElementById("bundlePreferences");
|
||||
let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
|
||||
totalSiteDataSizeLabel.textContent = prefStrBundle.getFormattedString("totalSiteDataSize", size);
|
||||
let siteDataGroup = document.getElementById("siteDataGroup");
|
||||
siteDataGroup.hidden = false;
|
||||
});
|
||||
toggleSiteData(shouldShow) {
|
||||
let clearButton = document.getElementById("clearSiteDataButton");
|
||||
let settingsButton = document.getElementById("siteDataSettings");
|
||||
clearButton.disabled = !shouldShow;
|
||||
settingsButton.disabled = !shouldShow;
|
||||
},
|
||||
|
||||
updateTotalDataSizeLabel(usage) {
|
||||
let prefStrBundle = document.getElementById("bundlePreferences");
|
||||
let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
|
||||
if (usage < 0) {
|
||||
totalSiteDataSizeLabel.textContent = prefStrBundle.getString("loadingSiteDataSize");
|
||||
} else {
|
||||
let size = DownloadUtils.convertByteUnits(usage);
|
||||
totalSiteDataSizeLabel.textContent = prefStrBundle.getFormattedString("totalSiteDataSize", size);
|
||||
}
|
||||
},
|
||||
|
||||
// Retrieves the amount of space currently used by disk cache
|
||||
|
@ -791,16 +801,22 @@ var gAdvancedPane = {
|
|||
},
|
||||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
if (AppConstants.MOZ_UPDATER) {
|
||||
switch (aTopic) {
|
||||
case "nsPref:changed":
|
||||
this.updateReadPrefs();
|
||||
break;
|
||||
switch (aTopic) {
|
||||
case "nsPref:changed":
|
||||
this.updateReadPrefs();
|
||||
break;
|
||||
|
||||
case "sitedatamanager:sites-updated":
|
||||
this.updateTotalSiteDataSize();
|
||||
break;
|
||||
}
|
||||
case "sitedatamanager:updating-sites":
|
||||
// While updating, we want to disable this section and display loading message until updated
|
||||
this.toggleSiteData(false);
|
||||
this.updateTotalDataSizeLabel(-1);
|
||||
break;
|
||||
|
||||
case "sitedatamanager:sites-updated":
|
||||
this.toggleSiteData(true);
|
||||
SiteDataManager.getTotalUsage()
|
||||
.then(this.updateTotalDataSizeLabel.bind(this));
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@ const TEST_BASE_URL = TEST_ORIGIN + "/browser/browser/components/preferences/in-
|
|||
const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
|
||||
|
||||
const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm", {});
|
||||
const { DownloadUtils } = Cu.import("resource://gre/modules/DownloadUtils.jsm", {});
|
||||
const { SiteDataManager } = Cu.import("resource:///modules/SiteDataManager.jsm", {});
|
||||
const { OfflineAppCacheHelper } = Cu.import("resource:///modules/offlineAppCache.jsm", {});
|
||||
|
||||
|
@ -225,6 +226,51 @@ registerCleanupFunction(function() {
|
|||
mockOfflineAppCacheHelper.unregister();
|
||||
});
|
||||
|
||||
// Test buttons are disabled and loading message shown while updating sites
|
||||
add_task(function *() {
|
||||
yield SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
|
||||
let updatedPromise = promiseSitesUpdated();
|
||||
yield openPreferencesViaOpenPreferencesAPI("advanced", "networkTab", { leaveOpen: true });
|
||||
yield updatedPromise;
|
||||
|
||||
let actual = null;
|
||||
let expected = null;
|
||||
let doc = gBrowser.selectedBrowser.contentDocument;
|
||||
let clearBtn = doc.getElementById("clearSiteDataButton");
|
||||
let settingsButton = doc.getElementById("siteDataSettings");
|
||||
let prefStrBundle = doc.getElementById("bundlePreferences");
|
||||
let totalSiteDataSizeLabel = doc.getElementById("totalSiteDataSize");
|
||||
is(clearBtn.disabled, false, "Should enable clear button after sites updated");
|
||||
is(settingsButton.disabled, false, "Should enable settings button after sites updated");
|
||||
yield SiteDataManager.getTotalUsage()
|
||||
.then(usage => {
|
||||
actual = totalSiteDataSizeLabel.textContent;
|
||||
expected = prefStrBundle.getFormattedString(
|
||||
"totalSiteDataSize", DownloadUtils.convertByteUnits(usage));
|
||||
is(actual, expected, "Should show the right total site data size");
|
||||
});
|
||||
|
||||
Services.obs.notifyObservers(null, "sitedatamanager:updating-sites", null);
|
||||
is(clearBtn.disabled, true, "Should disable clear button while updating sites");
|
||||
is(settingsButton.disabled, true, "Should disable settings button while updating sites");
|
||||
actual = totalSiteDataSizeLabel.textContent;
|
||||
expected = prefStrBundle.getString("loadingSiteDataSize");
|
||||
is(actual, expected, "Should show the loading message while updating");
|
||||
|
||||
Services.obs.notifyObservers(null, "sitedatamanager:sites-updated", null);
|
||||
is(clearBtn.disabled, false, "Should enable clear button after sites updated");
|
||||
is(settingsButton.disabled, false, "Should enable settings button after sites updated");
|
||||
yield SiteDataManager.getTotalUsage()
|
||||
.then(usage => {
|
||||
actual = totalSiteDataSizeLabel.textContent;
|
||||
expected = prefStrBundle.getFormattedString(
|
||||
"totalSiteDataSize", DownloadUtils.convertByteUnits(usage));
|
||||
is(actual, expected, "Should show the right total site data size");
|
||||
});
|
||||
|
||||
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(function* () {
|
||||
yield SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
|
||||
addPersistentStoragePerm(TEST_ORIGIN);
|
||||
|
|
|
@ -267,9 +267,11 @@ var gPrivacyPane = {
|
|||
|
||||
if (Services.prefs.getBoolPref("browser.storageManager.enabled")) {
|
||||
Services.obs.addObserver(this, "sitedatamanager:sites-updated", false);
|
||||
Services.obs.addObserver(this, "sitedatamanager:updating-sites", false);
|
||||
let unload = () => {
|
||||
window.removeEventListener("unload", unload);
|
||||
Services.obs.removeObserver(this, "sitedatamanager:sites-updated");
|
||||
Services.obs.removeObserver(this, "sitedatamanager:updating-sites");
|
||||
};
|
||||
window.addEventListener("unload", unload);
|
||||
SiteDataManager.updateSites();
|
||||
|
@ -1180,14 +1182,22 @@ var gPrivacyPane = {
|
|||
gSubDialog.open("chrome://browser/content/preferences/siteDataSettings.xul");
|
||||
},
|
||||
|
||||
updateTotalSiteDataSize() {
|
||||
SiteDataManager.getTotalUsage()
|
||||
.then(usage => {
|
||||
let size = DownloadUtils.convertByteUnits(usage);
|
||||
let prefStrBundle = document.getElementById("bundlePreferences");
|
||||
let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
|
||||
totalSiteDataSizeLabel.textContent = prefStrBundle.getFormattedString("totalSiteDataSize", size);
|
||||
});
|
||||
toggleSiteData(shouldShow) {
|
||||
let clearButton = document.getElementById("clearSiteDataButton");
|
||||
let settingsButton = document.getElementById("siteDataSettings");
|
||||
clearButton.disabled = !shouldShow;
|
||||
settingsButton.disabled = !shouldShow;
|
||||
},
|
||||
|
||||
updateTotalDataSizeLabel(usage) {
|
||||
let prefStrBundle = document.getElementById("bundlePreferences");
|
||||
let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
|
||||
if (usage < 0) {
|
||||
totalSiteDataSizeLabel.textContent = prefStrBundle.getString("loadingSiteDataSize");
|
||||
} else {
|
||||
let size = DownloadUtils.convertByteUnits(usage);
|
||||
totalSiteDataSizeLabel.textContent = prefStrBundle.getFormattedString("totalSiteDataSize", size);
|
||||
}
|
||||
},
|
||||
|
||||
// Retrieves the amount of space currently used by disk cache
|
||||
|
@ -1447,8 +1457,16 @@ var gPrivacyPane = {
|
|||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "sitedatamanager:updating-sites":
|
||||
// While updating, we want to disable this section and display loading message until updated
|
||||
this.toggleSiteData(false);
|
||||
this.updateTotalDataSizeLabel(-1);
|
||||
break;
|
||||
|
||||
case "sitedatamanager:sites-updated":
|
||||
this.updateTotalSiteDataSize();
|
||||
this.toggleSiteData(true);
|
||||
SiteDataManager.getTotalUsage()
|
||||
.then(this.updateTotalDataSizeLabel.bind(this));
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -15,6 +15,7 @@ const TEST_BASE_URL = TEST_ORIGIN + "/browser/browser/components/preferences/in-
|
|||
const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
|
||||
|
||||
const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm", {});
|
||||
const { DownloadUtils } = Cu.import("resource://gre/modules/DownloadUtils.jsm", {});
|
||||
const { SiteDataManager } = Cu.import("resource:///modules/SiteDataManager.jsm", {});
|
||||
const { OfflineAppCacheHelper } = Cu.import("resource:///modules/offlineAppCache.jsm", {});
|
||||
|
||||
|
@ -166,6 +167,51 @@ registerCleanupFunction(function() {
|
|||
mockOfflineAppCacheHelper.unregister();
|
||||
});
|
||||
|
||||
// Test buttons are disabled and loading message shown while updating sites
|
||||
add_task(function *() {
|
||||
yield SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
|
||||
let updatedPromise = promiseSiteDataManagerSitesUpdated();
|
||||
yield openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
|
||||
yield updatedPromise;
|
||||
|
||||
let actual = null;
|
||||
let expected = null;
|
||||
let doc = gBrowser.selectedBrowser.contentDocument;
|
||||
let clearBtn = doc.getElementById("clearSiteDataButton");
|
||||
let settingsButton = doc.getElementById("siteDataSettings");
|
||||
let prefStrBundle = doc.getElementById("bundlePreferences");
|
||||
let totalSiteDataSizeLabel = doc.getElementById("totalSiteDataSize");
|
||||
is(clearBtn.disabled, false, "Should enable clear button after sites updated");
|
||||
is(settingsButton.disabled, false, "Should enable settings button after sites updated");
|
||||
yield SiteDataManager.getTotalUsage()
|
||||
.then(usage => {
|
||||
actual = totalSiteDataSizeLabel.textContent;
|
||||
expected = prefStrBundle.getFormattedString(
|
||||
"totalSiteDataSize", DownloadUtils.convertByteUnits(usage));
|
||||
is(actual, expected, "Should show the right total site data size");
|
||||
});
|
||||
|
||||
Services.obs.notifyObservers(null, "sitedatamanager:updating-sites", null);
|
||||
is(clearBtn.disabled, true, "Should disable clear button while updating sites");
|
||||
is(settingsButton.disabled, true, "Should disable settings button while updating sites");
|
||||
actual = totalSiteDataSizeLabel.textContent;
|
||||
expected = prefStrBundle.getString("loadingSiteDataSize");
|
||||
is(actual, expected, "Should show the loading message while updating");
|
||||
|
||||
Services.obs.notifyObservers(null, "sitedatamanager:sites-updated", null);
|
||||
is(clearBtn.disabled, false, "Should enable clear button after sites updated");
|
||||
is(settingsButton.disabled, false, "Should enable settings button after sites updated");
|
||||
yield SiteDataManager.getTotalUsage()
|
||||
.then(usage => {
|
||||
actual = totalSiteDataSizeLabel.textContent;
|
||||
expected = prefStrBundle.getFormattedString(
|
||||
"totalSiteDataSize", DownloadUtils.convertByteUnits(usage));
|
||||
is(actual, expected, "Should show the right total site data size");
|
||||
});
|
||||
|
||||
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(function* () {
|
||||
yield SpecialPowers.pushPrefEnv({set: [["browser.storageManager.enabled", true]]});
|
||||
addPersistentStoragePerm(TEST_ORIGIN);
|
||||
|
|
|
@ -184,6 +184,7 @@ actualAppCacheSize=Your application cache is currently using %1$S %2$S of disk s
|
|||
# %1$S = size
|
||||
# %2$S = unit (MB, KB, etc.)
|
||||
totalSiteDataSize=Your stored site data is currently using %1$S %2$S of disk space
|
||||
loadingSiteDataSize=Calculating site data size…
|
||||
clearSiteDataPromptTitle=Clear all cookies and site data
|
||||
clearSiteDataPromptText=Selecting ‘Clear Now’ will clear all cookies and site data stored by Firefox. This may sign you out of websites and remove offline web content.
|
||||
clearSiteDataNow=Clear Now
|
||||
|
|
|
@ -184,6 +184,7 @@ actualAppCacheSize=Your application cache is currently using %1$S %2$S of disk s
|
|||
# %1$S = size
|
||||
# %2$S = unit (MB, KB, etc.)
|
||||
totalSiteDataSize=Your stored site data is currently using %1$S %2$S of disk space
|
||||
loadingSiteDataSize=Calculating site data size…
|
||||
clearSiteDataPromptTitle=Clear all cookies and site data
|
||||
clearSiteDataPromptText=Selecting ‘Clear Now’ will clear all cookies and site data stored by Firefox. This may sign you out of websites and remove offline web content.
|
||||
clearSiteDataNow=Clear Now
|
||||
|
|
Загрузка…
Ссылка в новой задаче