summaryrefslogtreecommitdiffstats
path: root/dom/html/test/browser_bug649778.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/test/browser_bug649778.js')
-rw-r--r--dom/html/test/browser_bug649778.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/dom/html/test/browser_bug649778.js b/dom/html/test/browser_bug649778.js
new file mode 100644
index 000000000..6356d20fe
--- /dev/null
+++ b/dom/html/test/browser_bug649778.js
@@ -0,0 +1,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();
+}