diff --git a/mozilla/dom/tests/mochitest/ajax/offline/Makefile.in b/mozilla/dom/tests/mochitest/ajax/offline/Makefile.in index 199ef707ff0..04598ae4768 100644 --- a/mozilla/dom/tests/mochitest/ajax/offline/Makefile.in +++ b/mozilla/dom/tests/mochitest/ajax/offline/Makefile.in @@ -52,6 +52,7 @@ _TEST_FILES = \ test_missingFile.html \ test_simpleManifest.html \ test_identicalManifest.html \ + test_changingManifest.html \ test_offlineIFrame.html \ badManifestMagic.cacheManifest \ badManifestMagic.cacheManifest^headers^ \ @@ -60,6 +61,9 @@ _TEST_FILES = \ simpleManifest.cacheManifest \ simpleManifest.cacheManifest^headers^ \ simpleManifest.notmanifest \ + changing1Sec.sjs \ + changing1Hour.sjs \ + changingManifest.sjs \ offlineChild.html \ $(NULL) diff --git a/mozilla/dom/tests/mochitest/ajax/offline/changing1Hour.sjs b/mozilla/dom/tests/mochitest/ajax/offline/changing1Hour.sjs new file mode 100644 index 00000000000..2a103596507 --- /dev/null +++ b/mozilla/dom/tests/mochitest/ajax/offline/changing1Hour.sjs @@ -0,0 +1,8 @@ +function handleRequest(request, response) +{ + response.setStatusLine(request.httpVersion, 200, "Ok"); + response.setHeader("Content-Type", "text/plain"); + response.setHeader("Cache-Control", "max-age=3600"); + + response.write(Date.now()); +} diff --git a/mozilla/dom/tests/mochitest/ajax/offline/changing1Sec.sjs b/mozilla/dom/tests/mochitest/ajax/offline/changing1Sec.sjs new file mode 100644 index 00000000000..cb9428b6c32 --- /dev/null +++ b/mozilla/dom/tests/mochitest/ajax/offline/changing1Sec.sjs @@ -0,0 +1,9 @@ +function handleRequest(request, response) +{ + response.setStatusLine(request.httpVersion, 200, "Ok"); + response.setHeader("Content-Type", "text/plain"); + response.setHeader("Cache-Control", "max-age=1"); + + response.write(Date.now()); +} + diff --git a/mozilla/dom/tests/mochitest/ajax/offline/changingManifest.sjs b/mozilla/dom/tests/mochitest/ajax/offline/changingManifest.sjs new file mode 100644 index 00000000000..b0d06196237 --- /dev/null +++ b/mozilla/dom/tests/mochitest/ajax/offline/changingManifest.sjs @@ -0,0 +1,12 @@ +function handleRequest(request, response) +{ + response.setStatusLine(request.httpVersion, 200, "Ok"); + response.setHeader("Content-Type", "text/cache-manifest"); + response.setHeader("Cache-Control", "no-cache"); + + response.write("CACHE MANIFEST\n"); + response.write("#" + Date.now() + "\n"); + response.write("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changing1Hour.sjs\n"); + response.write("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changing1Sec.sjs\n"); +} + diff --git a/mozilla/dom/tests/mochitest/ajax/offline/offlineTests.js b/mozilla/dom/tests/mochitest/ajax/offline/offlineTests.js index a8a92cbd414..06a062984a4 100644 --- a/mozilla/dom/tests/mochitest/ajax/offline/offlineTests.js +++ b/mozilla/dom/tests/mochitest/ajax/offline/offlineTests.js @@ -4,6 +4,63 @@ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var Cc = Components.classes; var Ci = Components.interfaces; +const kNetBase = 2152398848; // 0x804B0000 +var NS_ERROR_CACHE_KEY_NOT_FOUND = kNetBase + 61; +var NS_ERROR_CACHE_KEY_WAIT_FOR_VALIDATION = kNetBase + 64; + +// Reading the contents of multiple cache entries asynchronously +function OfflineCacheContents(urls) { + this.urls = urls; + this.contents = {}; +} + +OfflineCacheContents.prototype = { +QueryInterface: function(iid) { + if (!iid.equals(Ci.nsISupports) && + !iid.equals(Ci.nsICacheListener)) { + throw Cr.NS_ERROR_NO_INTERFACE; + } + return this; + }, +onCacheEntryAvailable: function(desc, accessGranted, status) { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + if (!desc) { + this.fetch(this.callback); + return; + } + + var stream = desc.QueryInterface(Ci.nsICacheEntryDescriptor).openInputStream(0); + var sstream = Components.classes["@mozilla.org/scriptableinputstream;1"] + .createInstance(Components.interfaces.nsIScriptableInputStream); + sstream.init(stream); + this.contents[desc.key] = sstream.read(sstream.available()); + sstream.close(); + desc.close(); + this.fetch(this.callback); + }, + +fetch: function(callback) +{ + this.callback = callback; + if (this.urls.length == 0) { + callback(this.contents); + return; + } + + var url = this.urls.shift(); + var self = this; + + var cacheService = Cc["@mozilla.org/network/cache-service;1"] + .getService(Ci.nsICacheService); + var cacheSession = cacheService.createSession("HTTP-offline", + Ci.nsICache.STORE_OFFLINE, + true); + cacheSession.asyncOpenCacheEntry(url, Ci.nsICache.ACCESS_READ, this); +} + +}; + var OfflineTest = { _slaveWindow: null, @@ -103,6 +160,11 @@ is: function(a, b, name) return this._masterWindow.SimpleTest.is(a, b, name); }, +isnot: function(a, b, name) +{ + return this._masterWindow.SimpleTest.isnot(a, b, name); +}, + clear: function() { // Clear the ownership list @@ -179,7 +241,7 @@ priv: function(func) var self = this; return function() { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); - func(); + func(arguments); } }, @@ -191,7 +253,7 @@ checkCache: function(url, expectEntry) Ci.nsICache.STORE_OFFLINE, true); try { - var entry = cacheSession.openCacheEntry(url, Ci.nsICache.ACCESS_READ, true); + var entry = cacheSession.openCacheEntry(url, Ci.nsICache.ACCESS_READ, false); if (expectEntry) { this.ok(true, url + " should exist in the offline cache"); } else { @@ -199,15 +261,19 @@ checkCache: function(url, expectEntry) } entry.close(); } catch (e) { - // this constant isn't in Components.results - const kNetBase = 2152398848; // 0x804B0000 - var NS_ERROR_CACHE_KEY_NOT_FOUND = kNetBase + 61 if (e.result == NS_ERROR_CACHE_KEY_NOT_FOUND) { if (expectEntry) { this.ok(false, url + " should exist in the offline cache"); } else { this.ok(true, url + " should not exist in the offline cache"); } + } else if (e.result == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) { + // There was a cache key that we couldn't access yet, that's good enough. + if (expectEntry) { + this.ok(true, url + " should exist in the offline cache"); + } else { + this.ok(false, url + " should not exist in the offline cache"); + } } else { throw e; } diff --git a/mozilla/dom/tests/mochitest/ajax/offline/test_changingManifest.html b/mozilla/dom/tests/mochitest/ajax/offline/test_changingManifest.html new file mode 100644 index 00000000000..93decb34413 --- /dev/null +++ b/mozilla/dom/tests/mochitest/ajax/offline/test_changingManifest.html @@ -0,0 +1,85 @@ + +
+