1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Test for bug 649778 - document.write may cause a document to be written to disk cache even when the page has Cache-Control: no-store
// Globals
var testPath = "http://mochi.test:8888/browser/dom/html/test/";
var popup;
var {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", null);
var {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
function checkCache(url, inMemory, shouldExist, cb)
{
var cache = Services.cache2;
var storage = cache.diskCacheStorage(LoadContextInfo.default, false);
function CheckCacheListener(inMemory, shouldExist)
{
this.inMemory = inMemory;
this.shouldExist = shouldExist;
this.onCacheEntryCheck = function() {
return Components.interfaces.nsICacheEntryOpenCallback.ENTRY_WANTED;
};
this.onCacheEntryAvailable = function oCEA(entry, isNew, appCache, status) {
if (shouldExist) {
ok(entry, "Entry not found");
is(this.inMemory, !entry.persistent, "Entry is " + (inMemory ? "" : " not ") + " in memory as expected");
is(status, Components.results.NS_OK, "Entry not found");
} else {
ok(!entry, "Entry found");
is(status, Components.results.NS_ERROR_CACHE_KEY_NOT_FOUND,
"Invalid error code");
}
setTimeout(cb, 0);
};
};
storage.asyncOpenURI(Services.io.newURI(url, null, null), "",
Components.interfaces.nsICacheStorage.OPEN_READONLY,
new CheckCacheListener(inMemory, shouldExist));
}
function getPopupURL() {
var sh = popup.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.sessionHistory;
return sh.getEntryAtIndex(sh.index, false).URI.spec;
}
var wyciwygURL;
function testContinue() {
wyciwygURL = getPopupURL();
is(wyciwygURL.substring(0, 10), "wyciwyg://", "Unexpected URL.");
popup.close()
// We have to find the entry and it must not be persisted to disk
checkCache(wyciwygURL, true, true, finish);
}
function waitForWyciwygDocument() {
try {
var url = getPopupURL();
if (url.substring(0, 10) == "wyciwyg://") {
setTimeout(testContinue, 0);
return;
}
}
catch (e) {
}
setTimeout(waitForWyciwygDocument, 100);
}
// Entry point from Mochikit
function test() {
waitForExplicitFinish();
popup = window.open(testPath + "file_bug649778.html", "popup 0",
"height=200,width=200,location=yes," +
"menubar=yes,status=yes,toolbar=yes,dependent=yes");
waitForWyciwygDocument();
}
|