Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // 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
3 // Globals
4 var testPath = "http://mochi.test:8888/browser/content/html/content/test/";
5 var popup;
7 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", null);
8 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
10 function checkCache(url, inMemory, shouldExist, cb)
11 {
12 var cache = Services.cache2;
13 var storage = cache.diskCacheStorage(LoadContextInfo.default, false);
15 function CheckCacheListener(inMemory, shouldExist)
16 {
17 this.inMemory = inMemory;
18 this.shouldExist = shouldExist;
19 this.onCacheEntryCheck = function() {
20 return Components.interfaces.nsICacheEntryOpenCallback.ENTRY_WANTED;
21 };
23 this.onCacheEntryAvailable = function oCEA(entry, isNew, appCache, status) {
24 if (shouldExist) {
25 ok(entry, "Entry not found");
26 is(this.inMemory, !entry.persistent, "Entry is " + (inMemory ? "" : " not ") + " in memory as expected");
27 is(status, Components.results.NS_OK, "Entry not found");
28 } else {
29 ok(!entry, "Entry found");
30 is(status, Components.results.NS_ERROR_CACHE_KEY_NOT_FOUND,
31 "Invalid error code");
32 }
34 setTimeout(cb, 0);
35 };
36 };
38 storage.asyncOpenURI(Services.io.newURI(url, null, null), "",
39 Components.interfaces.nsICacheStorage.OPEN_READONLY,
40 new CheckCacheListener(inMemory, shouldExist));
41 }
42 function getPopupURL() {
43 var sh = popup.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
44 .getInterface(Components.interfaces.nsIWebNavigation)
45 .sessionHistory;
47 return sh.getEntryAtIndex(sh.index, false).URI.spec;
48 }
50 var wyciwygURL;
51 function testContinue() {
52 wyciwygURL = getPopupURL();
53 is(wyciwygURL.substring(0, 10), "wyciwyg://", "Unexpected URL.");
54 popup.close()
56 // We have to find the entry and it must not be persisted to disk
57 checkCache(wyciwygURL, true, true, finish);
58 }
60 function waitForWyciwygDocument() {
61 try {
62 var url = getPopupURL();
63 if (url.substring(0, 10) == "wyciwyg://") {
64 setTimeout(testContinue, 0);
65 return;
66 }
67 }
68 catch (e) {
69 }
70 setTimeout(waitForWyciwygDocument, 100);
71 }
73 // Entry point from Mochikit
74 function test() {
75 waitForExplicitFinish();
77 popup = window.open(testPath + "file_bug649778.html", "popup 0",
78 "height=200,width=200,location=yes," +
79 "menubar=yes,status=yes,toolbar=yes,dependent=yes");
81 waitForWyciwygDocument();
82 }