Bug 1355795 - about:preferences#privacy is broken with browser.cache.offline.enable=false, r=jaws
If browser.cache.offline.enable was set to false, then calls to nsIApplicationCacheService would throw. The SiteDataManger and OfflineGroup using nsIApplicationCacheService has been moved into the privacy pane. We should test that the privacy pane is loaded well.
MozReview-Commit-ID: C9RRRYmb3Zb
--- a/browser/components/preferences/SiteDataManager.jsm
+++ b/browser/components/preferences/SiteDataManager.jsm
@@ -104,17 +104,23 @@ this.SiteDataManager = {
for (let request of this._quotaUsageRequests) {
request.cancel();
}
this._quotaUsageRequests = null;
}
},
_updateAppCache() {
- let groups = this._appCache.getGroups();
+ let groups = null;
+ try {
+ groups = this._appCache.getGroups();
+ } catch (e) {
+ return;
+ }
+
for (let site of this._sites.values()) {
for (let group of groups) {
let uri = Services.io.newURI(group);
if (site.perm.matchesURI(uri, true)) {
let cache = this._appCache.getActiveCache(group);
site.appCacheList.push(cache);
}
}
--- a/browser/components/preferences/in-content-old/tests/browser_bug795764_cachedisabled.js
+++ b/browser/components/preferences/in-content-old/tests/browser_bug795764_cachedisabled.js
@@ -7,42 +7,55 @@ Components.utils.import("resource://gre/
function test() {
waitForExplicitFinish();
let prefs = [
"browser.cache.offline.enable",
"browser.cache.disk.enable",
"browser.cache.memory.enable",
];
+ for (let pref of prefs) {
+ Services.prefs.setBoolPref(pref, false);
+ }
+
+ // Adding one fake site so that the SiteDataManager would run.
+ // Otherwise, without any site then it would just return so we would end up in not testing SiteDataManager.
+ let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("https://www.foo.com");
+ Services.perms.addFromPrincipal(principal, "persistent-storage", Ci.nsIPermissionManager.ALLOW_ACTION);
registerCleanupFunction(function() {
for (let pref of prefs) {
Services.prefs.clearUserPref(pref);
}
+ Services.perms.removeFromPrincipal(principal, "persistent-storage");
});
- for (let pref of prefs) {
- Services.prefs.setBoolPref(pref, false);
- }
-
open_preferences(runTest);
}
function runTest(win) {
is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded");
let tab = win.document;
let elements = tab.getElementById("mainPrefPane").children;
+ let offlineGroupDisabled = !SpecialPowers.getBoolPref("browser.preferences.offlineGroup.enabled");
// Test if advanced pane is opened correctly
win.gotoPref("paneAdvanced");
for (let element of elements) {
if (element.nodeName == "preferences") {
continue;
}
+ // The siteDataGroup in the Storage Management project will replace the offlineGroup eventually,
+ // so during the transition period, we have to check the pref to see if the offlineGroup
+ // should be hidden always. See the bug 1354530 for the details.
+ if (element.id == "offlineGroup" && offlineGroupDisabled) {
+ is_element_hidden(element, "Disabled offlineGroup should be hidden");
+ continue;
+ }
let attributeValue = element.getAttribute("data-category");
if (attributeValue == "paneAdvanced") {
is_element_visible(element, "Advanced elements should be visible");
} else {
is_element_hidden(element, "Non-Advanced elements should be hidden");
}
}
--- a/browser/components/preferences/in-content/tests/browser_bug795764_cachedisabled.js
+++ b/browser/components/preferences/in-content/tests/browser_bug795764_cachedisabled.js
@@ -1,52 +1,66 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
-Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
+const { interfaces: Ci, utils: Cu } = Components;
+Cu.import("resource://gre/modules/PlacesUtils.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
function test() {
waitForExplicitFinish();
let prefs = [
"browser.cache.offline.enable",
"browser.cache.disk.enable",
"browser.cache.memory.enable",
];
+ for (let pref of prefs) {
+ Services.prefs.setBoolPref(pref, false);
+ }
+
+ // Adding one fake site so that the SiteDataManager would run.
+ // Otherwise, without any site then it would just return so we would end up in not testing SiteDataManager.
+ let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("https://www.foo.com");
+ Services.perms.addFromPrincipal(principal, "persistent-storage", Ci.nsIPermissionManager.ALLOW_ACTION);
registerCleanupFunction(function() {
for (let pref of prefs) {
Services.prefs.clearUserPref(pref);
}
+ Services.perms.removeFromPrincipal(principal, "persistent-storage");
});
- for (let pref of prefs) {
- Services.prefs.setBoolPref(pref, false);
- }
-
open_preferences(runTest);
}
function runTest(win) {
is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded");
let tab = win.document;
let elements = tab.getElementById("mainPrefPane").children;
+ let offlineGroupDisabled = !SpecialPowers.getBoolPref("browser.preferences.offlineGroup.enabled");
- // Test if advanced pane is opened correctly
- win.gotoPref("paneAdvanced");
+ // Test if privacy pane is opened correctly
+ win.gotoPref("panePrivacy");
for (let element of elements) {
if (element.nodeName == "preferences") {
continue;
}
+ // The siteDataGroup in the Storage Management project will replace the offlineGroup eventually,
+ // so during the transition period, we have to check the pref to see if the offlineGroup
+ // should be hidden always. See the bug 1354530 for the details.
+ if (element.id == "offlineGroup" && offlineGroupDisabled) {
+ is_element_hidden(element, "Disabled offlineGroup should be hidden");
+ continue;
+ }
let attributeValue = element.getAttribute("data-category");
- if (attributeValue == "paneAdvanced") {
- is_element_visible(element, "Advanced elements should be visible");
+ if (attributeValue == "panePrivacy") {
+ is_element_visible(element, "Privacy elements should be visible");
} else {
- is_element_hidden(element, "Non-Advanced elements should be hidden");
+ is_element_hidden(element, "Non-Privacy elements should be hidden");
}
}
gBrowser.removeCurrentTab();
win.close();
finish();
}