Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3b27110

Browse files
committed
Backed out changeset f3c1becf9396 (bug 1237782) for browser-chrome failures at dom/tests/mochitest/ajax/offline/browser_disableAppcache.js on a CLOSED TREE
1 parent ea35d79 commit 3b27110

46 files changed

Lines changed: 164 additions & 112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

browser/base/content/test/general/browser.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
[DEFAULT]
99
prefs =
10+
browser.cache.offline.insecure.enable=true
1011
plugin.load_flash_only=false # for plugin usage in browser_tab_dragdrop.js
1112
support-files =
1213
alltabslistener.html

browser/base/content/test/sanitize/browser_sanitizeDialog.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,6 @@ add_task(async function test_form_entries() {
490490

491491
// Test for offline cache deletion
492492
add_task(async function test_offline_cache() {
493-
Services.prefs.setBoolPref("browser.cache.offline.enable", true);
494-
Services.prefs.setBoolPref("browser.cache.offline.storage.enable", true);
495493
// Prepare stuff, we will work with www.example.com
496494
var URL = "http://www.example.com";
497495
var URI = makeURI(URL);
@@ -570,8 +568,6 @@ add_task(async function test_offline_cache() {
570568
cacheListener
571569
);
572570
await wh.promiseClosed;
573-
Services.prefs.clearUserPref("browser.cache.offline.enable");
574-
Services.prefs.clearUserPref("browser.cache.offline.storage.enable");
575571
});
576572

577573
// Test for offline apps permission deletion

dom/base/nsGlobalWindowInner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,8 @@ bool nsGlobalWindowInner::IsPrivilegedChromeWindow(JSContext* aCx,
29622962
/* static */
29632963
bool nsGlobalWindowInner::OfflineCacheAllowedForContext(JSContext* aCx,
29642964
JSObject* aObj) {
2965-
return IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
2965+
return IsSecureContextOrObjectIsFromSecureContext(aCx, aObj) ||
2966+
Preferences::GetBool("browser.cache.offline.insecure.enable");
29662967
}
29672968

29682969
/* static */

dom/tests/mochitest/ajax/offline/browser_disableAppcache.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,135 @@ const PATH =
22
"http://example.com/browser/dom/tests/mochitest/ajax/offline/";
33
const URL = PATH + "file_simpleManifest.html";
44
const MANIFEST = PATH + "file_simpleManifest.cacheManifest";
5+
const PREF_INSECURE_APPCACHE = "browser.cache.offline.insecure.enable";
56
const PREF_NETWORK_PROXY = "network.proxy.type";
67

8+
function setSJSState(sjsPath, stateQuery) {
9+
let client = new XMLHttpRequest();
10+
client.open("GET", sjsPath + "?state=" + stateQuery, false);
11+
let appcachechannel = SpecialPowers.wrap(client).channel.QueryInterface(Ci.nsIApplicationCacheChannel);
12+
13+
return new Promise((resolve, reject) => {
14+
client.addEventListener("load", resolve);
15+
client.addEventListener("error", reject);
16+
17+
appcachechannel.chooseApplicationCache = false;
18+
appcachechannel.inheritApplicationCache = false;
19+
appcachechannel.applicationCache = null;
20+
21+
client.send();
22+
});
23+
}
24+
25+
add_task(async function() {
26+
/* This test loads "evil" content and verified it isn't loaded when appcache is disabled, which emulates loading stale cache from an untrusted network:
27+
- Sets frame to load "evil" content
28+
- Loads HTML file which also loads and caches content into AppCache
29+
- Sets frame to load "good"
30+
- Check we still have "evil" content from AppCache
31+
- Disables appcache
32+
- Check content is "good"
33+
*/
34+
await SpecialPowers.pushPrefEnv({
35+
set: [
36+
[PREF_INSECURE_APPCACHE, true]
37+
]
38+
});
39+
await setSJSState(PATH + "file_testFile.sjs", "evil");
40+
await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
41+
await ContentTask.spawn(gBrowser.selectedBrowser, null, async () => {
42+
let windowPromise = new Promise((resolve, reject) => {
43+
function init() {
44+
if (content.document.readyState == "complete") {
45+
const frame = content.document.getElementById("childframe");
46+
const state = frame.contentDocument.getElementById("state");
47+
is(state.textContent, "evil", "Loaded evil content");
48+
resolve();
49+
}
50+
}
51+
content.document.onreadystatechange = init;
52+
init();
53+
});
54+
let appcachePromise = new Promise((resolve, reject) => {
55+
function appcacheInit() {
56+
if (content.applicationCache.status === content.applicationCache.IDLE) {
57+
ok(true, "Application cache loaded");
58+
resolve();
59+
} else {
60+
info("State was: " + content.applicationCache.status);
61+
}
62+
}
63+
content.applicationCache.oncached = appcacheInit;
64+
content.applicationCache.onnoupdate = appcacheInit;
65+
content.applicationCache.onerror = () => {
66+
ok(false, "Application cache failed");
67+
reject();
68+
};
69+
appcacheInit();
70+
});
71+
await Promise.all([windowPromise, appcachePromise]);
72+
});
73+
gBrowser.removeCurrentTab();
74+
75+
// Turn network and proxy off so we can check the content loads still
76+
await setSJSState(PATH + "file_testFile.sjs", "good");
77+
Services.cache2.clear();
78+
79+
// Check we still have the "evil" content despite the state change
80+
await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
81+
await ContentTask.spawn(gBrowser.selectedBrowser, null, async () => {
82+
const frame = content.document.getElementById("childframe");
83+
const state = frame.contentDocument.getElementById("state");
84+
is(state.textContent, "evil", "Loaded evil content from cache");
85+
});
86+
gBrowser.removeCurrentTab();
87+
88+
89+
await SpecialPowers.pushPrefEnv({
90+
set: [
91+
[PREF_INSECURE_APPCACHE, false]
92+
]
93+
});
94+
await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
95+
96+
// Check that the "good" content is back now appcache is disabled
97+
await ContentTask.spawn(gBrowser.selectedBrowser, [URL], async (URL) => {
98+
const frame = content.document.getElementById("childframe");
99+
const state = frame.contentDocument.getElementById("state");
100+
is(state.textContent, "good", "Loaded good content");
101+
// Eval is needed to execure in child context.
102+
content.window.eval("OfflineTest.clear()");
103+
});
104+
105+
gBrowser.removeCurrentTab();
106+
await setSJSState(PATH + "file_testFile.sjs", "");
107+
await SpecialPowers.popPrefEnv();
108+
});
109+
7110
add_task(async function test_pref_removes_api() {
111+
await SpecialPowers.pushPrefEnv({
112+
set: [
113+
[PREF_INSECURE_APPCACHE, true]
114+
]
115+
});
8116
await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
9117
await ContentTask.spawn(gBrowser.selectedBrowser, null, async () => {
10118
// Have to use in page checking as IsSecureContextOrObjectIsFromSecureContext is true for spawn()
11119
is(content.document.getElementById("hasAppcache").textContent, "yes", "Appcache is enabled");
12120
is(content.document.getElementById("hasOfflineResourceList").textContent, "yes", "OfflineResourceList is enabled");
13121
});
14122
gBrowser.removeCurrentTab();
123+
124+
await SpecialPowers.pushPrefEnv({
125+
set: [
126+
[PREF_INSECURE_APPCACHE, false]
127+
]
128+
});
129+
await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
130+
await ContentTask.spawn(gBrowser.selectedBrowser, [URL], async (URL) => {
131+
is(content.document.getElementById("hasAppcache").textContent, "no", "Appcache is disabled");
132+
is(content.document.getElementById("hasOfflineResourceList").textContent, "no", "OfflineResourceList is disabled");
133+
content.window.eval("OfflineTest.clear()");
134+
});
135+
gBrowser.removeCurrentTab();
15136
});

modules/libpref/init/StaticPrefList.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,6 @@
653653
value: true
654654
mirror: always
655655

656-
- name: browser.cache.offline.storage.enable
657-
type: bool
658-
#ifdef EARLY_BETA_OR_EARLIER
659-
value: false
660-
#else
661-
value: true
662-
#endif
663-
mirror: always
664-
665656
- name: browser.cache.disk.enable
666657
type: RelaxedAtomicBool
667658
value: true

modules/libpref/init/all.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ pref("browser.cache.check_doc_frequency", 3);
221221
// The half life used to re-compute cache entries frecency in hours.
222222
pref("browser.cache.frecency_half_life_hours", 6);
223223

224+
// AppCache over insecure connection is disabled by default
225+
pref("browser.cache.offline.insecure.enable", false);
226+
224227
// offline cache capacity in kilobytes
225228
pref("browser.cache.offline.capacity", 512000);
226229

netwerk/cache/nsCacheService.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ using namespace mozilla::net;
5050
* nsCacheProfilePrefObserver
5151
*****************************************************************************/
5252
#define OFFLINE_CACHE_ENABLE_PREF "browser.cache.offline.enable"
53-
#define OFFLINE_CACHE_STORAGE_ENABLE_PREF "browser.cache.offline.storage.enable"
5453
#define OFFLINE_CACHE_DIR_PREF "browser.cache.offline.parent_directory"
5554
#define OFFLINE_CACHE_CAPACITY_PREF "browser.cache.offline.capacity"
5655
#define OFFLINE_CACHE_CAPACITY 512000
@@ -64,7 +63,6 @@ static const char* observerList[] = {
6463

6564
static const char* prefList[] = {
6665
OFFLINE_CACHE_ENABLE_PREF,
67-
OFFLINE_CACHE_STORAGE_ENABLE_PREF,
6866
OFFLINE_CACHE_CAPACITY_PREF,
6967
OFFLINE_CACHE_DIR_PREF,
7068
nullptr,
@@ -80,7 +78,6 @@ class nsCacheProfilePrefObserver : public nsIObserver {
8078
nsCacheProfilePrefObserver()
8179
: mHaveProfile(false),
8280
mOfflineCacheEnabled(false),
83-
mOfflineStorageCacheEnabled(false),
8481
mOfflineCacheCapacity(0),
8582
mCacheCompressionLevel(CACHE_COMPRESSION_LEVEL),
8683
mSanitizeOnShutdown(false),
@@ -112,7 +109,6 @@ class nsCacheProfilePrefObserver : public nsIObserver {
112109
nsCOMPtr<nsIFile> mDiskCacheParentDirectory;
113110

114111
bool mOfflineCacheEnabled;
115-
bool mOfflineStorageCacheEnabled;
116112
int32_t mOfflineCacheCapacity; // in kilobytes
117113
nsCOMPtr<nsIFile> mOfflineCacheParentDirectory;
118114

@@ -241,17 +237,9 @@ void nsCacheProfilePrefObserver::PrefChanged(const char* aPref) {
241237
if (!mHaveProfile) return;
242238
// which preference changed?
243239
nsresult rv;
244-
if (!strcmp(OFFLINE_CACHE_ENABLE_PREF, aPref) ||
245-
!strcmp(OFFLINE_CACHE_STORAGE_ENABLE_PREF, aPref)) {
240+
if (!strcmp(OFFLINE_CACHE_ENABLE_PREF, aPref)) {
246241
rv = Preferences::GetBool(OFFLINE_CACHE_ENABLE_PREF, &mOfflineCacheEnabled);
247-
if (NS_FAILED(rv)) {
248-
return;
249-
}
250-
rv = Preferences::GetBool(OFFLINE_CACHE_STORAGE_ENABLE_PREF,
251-
&mOfflineStorageCacheEnabled);
252-
if (NS_FAILED(rv)) {
253-
return;
254-
}
242+
if (NS_FAILED(rv)) return;
255243
nsCacheService::SetOfflineCacheEnabled(OfflineCacheEnabled());
256244

257245
} else if (!strcmp(OFFLINE_CACHE_CAPACITY_PREF, aPref)) {
@@ -306,11 +294,6 @@ nsresult nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch) {
306294
mOfflineCacheEnabled = true; // presume offline cache is enabled
307295
(void)branch->GetBoolPref(OFFLINE_CACHE_ENABLE_PREF, &mOfflineCacheEnabled);
308296

309-
mOfflineStorageCacheEnabled =
310-
true; // presume offline storage cache is enabled
311-
(void)branch->GetBoolPref(OFFLINE_CACHE_STORAGE_ENABLE_PREF,
312-
&mOfflineStorageCacheEnabled);
313-
314297
mOfflineCacheCapacity = OFFLINE_CACHE_CAPACITY;
315298
(void)branch->GetIntPref(OFFLINE_CACHE_CAPACITY_PREF, &mOfflineCacheCapacity);
316299
mOfflineCacheCapacity = std::max(0, mOfflineCacheCapacity);
@@ -385,7 +368,7 @@ bool nsCacheProfilePrefObserver::OfflineCacheEnabled() {
385368
if ((mOfflineCacheCapacity == 0) || (!mOfflineCacheParentDirectory))
386369
return false;
387370

388-
return mOfflineCacheEnabled && mOfflineStorageCacheEnabled;
371+
return mOfflineCacheEnabled;
389372
}
390373

391374
int32_t nsCacheProfilePrefObserver::CacheCompressionLevel() {

netwerk/test/unit/test_bug248970_cache.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ function run_test() {
129129
// Simulate a profile dir for xpcshell
130130
do_get_profile();
131131

132-
Services.prefs.setBoolPref("browser.cache.offline.enable", true);
133-
Services.prefs.setBoolPref("browser.cache.offline.storage.enable", true);
134-
135132
appCache = Cc["@mozilla.org/network/application-cache-service;1"]
136133
.getService(Ci.nsIApplicationCacheService)
137134
.getApplicationCache("fake-client-id|fake-group-id");

netwerk/test/unit/test_bug650995.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ function run_test() {
167167
httpserver.start(-1);
168168

169169
prefService.setBoolPref("browser.cache.offline.enable", false);
170-
prefService.setBoolPref("browser.cache.offline.storage.enable", false);
171170
prefService.setBoolPref("network.http.rcwn.enabled", false);
172171

173172
nextTest();

netwerk/test/unit/test_bug767025.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ function init_profile() {
7676
);
7777
dump(ps.getBoolPref("browser.cache.offline.enable"));
7878
ps.setBoolPref("browser.cache.offline.enable", true);
79-
ps.setBoolPref("browser.cache.offline.storage.enable", true);
8079
ps.setComplexValue(
8180
"browser.cache.offline.parent_directory",
8281
Ci.nsIFile,

0 commit comments

Comments
 (0)