Bug 468442 - Change tests dep on PUT/DELETE support to use SJS states, r=dcamp
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 18 Feb 2009 14:31:30 +0100
changeset 25132 fad4b32df3745b3fb3eac9c1b888df12e452c477
parent 25131 2d2a34c4233d3760661798a0eb0c2c4dc01883e5
child 25133 0c9af8ac1a417461bd02df91f0a90b9e39dad569
push idunknown
push userunknown
push dateunknown
reviewersdcamp
bugs468442
milestone1.9.2a1pre
Bug 468442 - Change tests dep on PUT/DELETE support to use SJS states, r=dcamp
dom/tests/mochitest/ajax/offline/460353_iframe_ownmanifest.html
dom/tests/mochitest/ajax/offline/Makefile.in
dom/tests/mochitest/ajax/offline/changingManifest.cacheManifest
dom/tests/mochitest/ajax/offline/changingManifest.cacheManifest^headers^
dom/tests/mochitest/ajax/offline/changingManifest.sjs
dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
dom/tests/mochitest/ajax/offline/obsolete.html
dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs
dom/tests/mochitest/ajax/offline/offlineTests.js
dom/tests/mochitest/ajax/offline/test_bug460353.html
dom/tests/mochitest/ajax/offline/test_changingManifest.html
dom/tests/mochitest/ajax/offline/test_obsolete.html
dom/tests/mochitest/ajax/offline/test_offlineMode.html
dom/tests/mochitest/ajax/offline/test_refetchManifest.html
dom/tests/mochitest/ajax/offline/test_updatingManifest.html
dom/tests/mochitest/ajax/offline/updating.cacheManifest
dom/tests/mochitest/ajax/offline/updating.cacheManifest^headers^
dom/tests/mochitest/ajax/offline/updatingIFrame.html
dom/tests/mochitest/ajax/offline/updatingIFrame.html^headers^
dom/tests/mochitest/ajax/offline/updatingIframe.sjs
dom/tests/mochitest/ajax/offline/updatingImplicit.html
dom/tests/mochitest/ajax/offline/updatingManifest.sjs
--- a/dom/tests/mochitest/ajax/offline/460353_iframe_ownmanifest.html
+++ b/dom/tests/mochitest/ajax/offline/460353_iframe_ownmanifest.html
@@ -1,9 +1,9 @@
-<html xmlns="http://www.w3.org/1999/xhtml" manifest="updating.cacheManifest">
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="updatingManifest.sjs">
 <head>
 <title>Bug 460353, iframe with a different manifest reference</title>
 
 <script type="text/javascript">
 
 applicationCache.onerror = function() {
   parent.frameOnUpdate("diff", false);
 }
--- a/dom/tests/mochitest/ajax/offline/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/Makefile.in
@@ -69,16 +69,17 @@ include $(topsrcdir)/config/rules.mk
 	445544.cacheManifest \
 	445544.cacheManifest^headers^ \
 	test_bug460353.html \
 	460353_iframe_nomanifest.html \
 	460353_iframe_ownmanifest.html \
 	460353_iframe_samemanifest.html \
 	test_obsolete.html \
 	obsolete.html \
+	obsoletingManifest.sjs \
 	badManifestMagic.cacheManifest \
 	badManifestMagic.cacheManifest^headers^ \
 	bypass.cacheManifest \
 	bypass.cacheManifest^headers^ \
 	bypass.html \
 	fallback.html \
 	fallback2.html \
 	fallbackTop.html \
@@ -87,30 +88,27 @@ include $(topsrcdir)/config/rules.mk
 	foreign1.cacheManifest \
 	foreign1.cacheManifest^headers^ \
 	foreign2.cacheManifest \
 	foreign2.cacheManifest^headers^ \
 	foreign2.html \
 	notonwhitelist.html \
 	onwhitelist.html \
 	onwhitelist.html^headers^ \
-	updatingIFrame.html \
-	updatingIFrame.html^headers^ \
+	updatingIframe.sjs \
 	updatingImplicit.html \
 	missingFile.cacheManifest \
 	missingFile.cacheManifest^headers^ \
 	simpleManifest.cacheManifest \
 	simpleManifest.cacheManifest^headers^ \
-	updating.cacheManifest \
-	updating.cacheManifest^headers^ \
+	updatingManifest.sjs \
 	simpleManifest.notmanifest \
 	changing1Sec.sjs \
 	changing1Hour.sjs \
-	changingManifest.cacheManifest \
-	changingManifest.cacheManifest^headers^ \
+	changingManifest.sjs \
 	offlineChild.html \
 	test_xhtmlManifest.xhtml \
 	test_missingManifest.html \
 	missing.html \
 	$(NULL)
 
 libs::	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
deleted file mode 100644
--- a/dom/tests/mochitest/ajax/offline/changingManifest.cacheManifest
+++ /dev/null
@@ -1,6 +0,0 @@
-CACHE MANIFEST
-# v1 - this will be replaced by test scripts.
-changing1Hour.sjs
-changing1Sec.sjs
-NETWORK:
-onwhitelist.html
deleted file mode 100644
--- a/dom/tests/mochitest/ajax/offline/changingManifest.cacheManifest^headers^
+++ /dev/null
@@ -1,2 +0,0 @@
-Content-Type: text/cache-manifest
-Cache-Control: no-cache
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/changingManifest.sjs
@@ -0,0 +1,27 @@
+function handleRequest(request, response)
+{
+  var match = request.queryString.match(/^state=(.*)$/);
+  if (match)
+  {
+    response.setStatusLine(request.httpVersion, 204, "No content");
+    setState("offline.changingManifest", match[1]);
+  }
+
+  if (request.queryString == "")
+  {
+    response.setStatusLine(request.httpVersion, 200, "Ok");
+    response.setHeader("Content-Type", "text/cache-manifest");
+    response.setHeader("Cache-Control", "no-cache");
+    response.write(
+      "CACHE MANIFEST\n" +
+      "# v" + getState("offline.changingManifest") + "\n" +
+      "changing1Hour.sjs\n" +
+      "changing1Sec.sjs\n");
+      
+    if (getState("offline.changingManifest") != "2") {
+      response.write(
+        "NETWORK:\n" +
+        "onwhitelist.html\n");
+    }
+  }
+}
--- a/dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
@@ -44,12 +44,13 @@ relativesrcdir	= dom/tests/mochitest/aja
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = sub sub2
 
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES	= \
         opp.html \
+        script.js \
         $(NULL)
 
 libs::	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
--- a/dom/tests/mochitest/ajax/offline/obsolete.html
+++ b/dom/tests/mochitest/ajax/offline/obsolete.html
@@ -1,9 +1,9 @@
-<html manifest="obsolete.cacheManifest">
+<html manifest="obsoletingManifest.sjs">
 <head>
 <title>obsolete test</title>
 <script type="text/javascript">
 
 function obsolete(evt)
 {
   window.opener.ok(true, "Got an 'obsolete' event");
 
@@ -27,30 +27,37 @@ function obsolete(evt)
 
 function fail(evt)
 {
   window.opener.ok(false, "Got an unexpected event: " + evt.type)
   window.opener.finish();
 }
 
 applicationCache.oncached = function() {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
   // ok, we've successfully loaded from the initial cache.
   try {
     applicationCache.swapCache();
     window.opener.todo(false, "We shouldn't have to swapCache in the oncached handler (bug 443023)");
   } catch(e) {
   }
 
   // Now delete the manifest and refresh, we should get an "obsolete" message.
   applicationCache.oncached = fail;
   applicationCache.onupdateready = fail;
   applicationCache.onobsolete = obsolete;
 
+  // Make the obsoleting.sjs return 404 NOT FOUND code
   var req = new XMLHttpRequest();
-  req.open("DELETE", "obsolete.cacheManifest");
+  req.open("GET", "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs?state=");
+  var channel = req.channel
+    .QueryInterface(Components.interfaces.nsIApplicationCacheChannel);
+  channel.chooseApplicationCache = false;
+  channel.inheritApplicationCache = false;
   req.send("");
   req.onreadystatechange = function() {
     if (req.readyState == 4) {
       applicationCache.update();
     }
   }
 }
 
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs
@@ -0,0 +1,31 @@
+var manifest =
+  "CACHE MANIFEST\n" +
+  "obsolete.html\n";
+
+function handleRequest(request, response)
+{
+  var match = request.queryString.match(/^state=(.*)$/);
+  if (match)
+  {
+    response.setStatusLine(request.httpVersion, 204, "No content");
+    response.setHeader("Cache-Control", "no-cache");
+    setState("offline.obsoletingManifest", match[1]);
+  }
+
+  if (request.queryString == "")
+  {
+    switch (getState("offline.obsoletingManifest"))
+    {
+      case "": // The default value
+        response.setStatusLine(request.httpVersion, 404, "Not found");
+        response.setHeader("Cache-Control", "no-cache");
+        break;
+      case "manifestPresent":
+        response.setStatusLine(request.httpVersion, 200, "Ok");
+        response.setHeader("Content-Type", "text/cache-manifest");
+        response.setHeader("Cache-Control", "no-cache");
+        response.write(manifest);
+        break;
+    }
+  }
+}
--- a/dom/tests/mochitest/ajax/offline/offlineTests.js
+++ b/dom/tests/mochitest/ajax/offline/offlineTests.js
@@ -61,16 +61,19 @@ var OfflineTest = {
 _slaveWindow: null,
 
 // The window where test results should be sent.
 _masterWindow: null,
 
 // Array of all PUT overrides on the server
 _pathOverrides: [],
 
+// SJSs whom state was changed to be reverted on teardown
+_SJSsStated: [],
+
 setupChild: function()
 {
   if (window.parent.OfflineTest.hasSlave()) {
     return false;
   }
 
   this._slaveWindow = null;
   this._masterWindow = window.top;
@@ -125,16 +128,18 @@ teardown: function()
   var uri = Cc["@mozilla.org/network/io-service;1"]
             .getService(Ci.nsIIOService)
             .newURI(window.location.href, null, null);
   pm.remove(uri.host, "offline-app");
 
   // Clear all overrides on the server
   for (override in this._pathOverrides)
     this.deleteData(this._pathOverrides[override]);
+  for (statedSJS in this._SJSsStated)
+    this.setSJSState(this._SJSsStated[statedSJS], "");
 
   this.clear();
 },
 
 finish: function()
 {
   SimpleTest.finish();
 
@@ -308,31 +313,28 @@ checkCache: function(url, expectEntry)
         this.ok(mustBeValid, url + " should not exist in the offline cache");
       }
     } else {
       throw e;
     }
   }
 },
 
-putData: function(serverPath, contentType, data)
+setSJSState: function(sjsPath, stateQuery)
 {
-  if (!data.length)
-    throw "Data length mush be specified";
-
   var client = new XMLHttpRequest();
-  client.open("PUT", serverPath, false);
-  client.setRequestHeader("Content-Type", contentType);
-  client.send(data);
+  client.open("GET", sjsPath + "?state=" + stateQuery, false);
 
-  this._pathOverrides.push(serverPath);
-},
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var appcachechannel = client.channel.QueryInterface(Ci.nsIApplicationCacheChannel);
+  appcachechannel.chooseApplicationCache = false;
+  appcachechannel.inheritApplicationCache = false;
+  appcachechannel.applicationCache = null;
 
-deleteData: function(serverPath)
-{
-  delete this._pathOverrides[serverPath];
+  client.send();
 
-  var client = new XMLHttpRequest();
-  client.open("DELETE", serverPath, false);
-  client.send();
+  if (stateQuery == "")
+    delete this._SJSsStated[sjsPath];
+  else
+    this._SJSsStated.push(sjsPath);
 }
 
 };
--- a/dom/tests/mochitest/ajax/offline/test_bug460353.html
+++ b/dom/tests/mochitest/ajax/offline/test_bug460353.html
@@ -77,17 +77,17 @@ function finish()
   var pm = Cc["@mozilla.org/permissionmanager;1"]
            .getService(Ci.nsIPermissionManager);
   var uri = Cc["@mozilla.org/network/io-service;1"]
             .getService(Ci.nsIIOService)
             .newURI(window.location.href, null, null);
   pm.remove(uri.host, "offline-app");
 
   cleanCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest");
-  cleanCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updating.cacheManifest");
+  cleanCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs");
 
   SimpleTest.finish();
 }
 
 function cleanCache(manifestURL)
 {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
--- a/dom/tests/mochitest/ajax/offline/test_changingManifest.html
+++ b/dom/tests/mochitest/ajax/offline/test_changingManifest.html
@@ -1,9 +1,9 @@
-<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.cacheManifest">
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
 <head>
 <title>changing manifest test</title>
 
 <script type="text/javascript" src="/MochiKit/packed.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
@@ -14,21 +14,16 @@ var gGotDownloading = false;
 
 var g1SecUrl =  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changing1Sec.sjs";
 var g1HourUrl = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changing1Hour.sjs";
 
 var gCacheContents = null;
 
 function finish()
 {
-  // Get rid of the changed manifest.
-  var req = new XMLHttpRequest();
-  req.open("DELETE", "changingManifest.cacheManifest", false);
-  req.send("");
-
   OfflineTest.teardown();
   OfflineTest.finish();
 }
 
 function manifestUpdatedAgain()
 {
   OfflineTest.ok(gGotChecking, "Should get a checking event on the second update");
   OfflineTest.ok(gGotDownloading, "Should get a downloading event on the second update");
@@ -63,27 +58,17 @@ function failAndFinish(e) {
 }
 
 function manifestUpdated()
 {
   OfflineTest.ok(gGotChecking, "Should get a checking event");
   OfflineTest.ok(gGotDownloading, "Should get a downloading event");
 
   // Replace this manifest with a new one.
-
-  // XXX: After this put, we will no longer have Cache-Control:
-  // no-cache on the manifest, so future updates will just use the
-  // cached manifest.
-  var req = new XMLHttpRequest();
-  req.open("PUT", "changingManifest.cacheManifest", false);
-  req.setRequestHeader("Content-Type", "text/cache-manifest");
-  req.send("CACHE MANIFEST\n" +
-           "# v2\n" +
-           "changing1Hour.sjs\n" +
-           "changing1Sec.sjs\n");
+  OfflineTest.setSJSState("changingManifest.sjs", "2");
 
   // Get the initial contents of the first two files.
   fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
   fetcher.fetch(function(contents) {
     gCacheContents = contents;
 
     // Now make sure applicationCache.update() does what we expect.
     applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
--- a/dom/tests/mochitest/ajax/offline/test_obsolete.html
+++ b/dom/tests/mochitest/ajax/offline/test_obsolete.html
@@ -17,25 +17,21 @@ var Ci = Components.interfaces;
 // Enable the offline-app permission before loading the new window
 var pm = Cc["@mozilla.org/permissionmanager;1"]
         .getService(Ci.nsIPermissionManager);
 var uri = Cc["@mozilla.org/network/io-service;1"]
          .getService(Ci.nsIIOService)
          .newURI(window.location.href, null, null);
 pm.add(uri, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
 
-// Now add the manifest that the test frame will use.
-var manifest =
-"CACHE MANIFEST\n" +
-"obsolete.html\n";
-
+// Make the obsoleting.sjs return a valid manifest
 var req = new XMLHttpRequest();
-req.open("PUT", "obsolete.cacheManifest");
+req.open("GET", "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs?state=manifestPresent");
 req.setRequestHeader("Content-Type", "text/cache-manifest");
-req.send(manifest);
+req.send("");
 req.onreadystatechange = function() {
   if (req.readyState == 4) {
     // now this will properly load the manifest.
     gTestWin = window.open("obsolete.html");
   }
 }
 
 function finish()
--- a/dom/tests/mochitest/ajax/offline/test_offlineMode.html
+++ b/dom/tests/mochitest/ajax/offline/test_offlineMode.html
@@ -1,9 +1,9 @@
-<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updating.cacheManifest">
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs">
 <head>
 <title>Offline mode test</title>
 
 <script type="text/javascript" src="/MochiKit/packed.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
@@ -36,17 +36,17 @@ function dynamicAdded()
 {
   aFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html";
 }
 
 // Called by the dynamically added iframe on load
 function notwhitelistOnLoad()
 {
   gGotDynamicVersion = 1;
-  aFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html";
+  aFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs";
 }
 
 // Called by the explicit iframe on load
 function frameLoad(version)
 {
   gGotExplicitVersion = version;
   gImplicitWindow = window.open("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html");
 }
@@ -70,17 +70,17 @@ function finalize()
   window.clearTimeout(gCompleteTimeout);
 
   var ioserv = Cc["@mozilla.org/network/io-service;1"]
       .getService(Ci.nsIIOService);
 
   if (!ioserv.offline)
   {
     OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html", true);
-    OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html", true);
+    OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", true);
     OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true);
 
     OfflineTest.is(gGotExplicitVersion, 1, "Explicit entry loaded");
     OfflineTest.is(gGotImplicitVersion, 1, "Implicit entry loaded");
     OfflineTest.is(gGotDynamicVersion, 1, "Dynamic entry loaded");
 
     gGotExplicitVersion = 0;
     gGotImplicitVersion = 0;
@@ -91,17 +91,17 @@ function finalize()
     var sessionServ = Cc["@mozilla.org/network/cache-service;1"]
       .getService(Ci.nsICacheService);
     cacheSession = sessionServ.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, Ci.nsICache.STREAM_BASED);
     function doomHTTPCacheEntry(entryKey) {
       entry = cacheSession.openCacheEntry(entryKey, Ci.nsICache.ACCESS_WRITE, false)
       entry.doom();
     }
     doomHTTPCacheEntry("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html");
-    doomHTTPCacheEntry("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html");
+    doomHTTPCacheEntry("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs");
     doomHTTPCacheEntry("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html");
 
 
     ioserv.offline = true;
 
     gCompleteTimeout = window.setTimeout(OfflineTest.priv(finalize), 10000);
 
     // remove error handling. in offline mode
--- a/dom/tests/mochitest/ajax/offline/test_refetchManifest.html
+++ b/dom/tests/mochitest/ajax/offline/test_refetchManifest.html
@@ -1,25 +1,20 @@
-<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.cacheManifest">
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
 <head>
 <title>refetch manifest test</title>
 
 <script type="text/javascript" src="/MochiKit/packed.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
 
 <script type="text/javascript">
 
 function finish()
 {
-  // Get rid of the changed manifest.
-  var req = new XMLHttpRequest();
-  req.open("DELETE", "changingManifest.cacheManifest", false);
-  req.send("");
-
   OfflineTest.teardown();
   OfflineTest.finish();
 }
 
 function failAndFinish(e)
 {
   OfflineTest.ok(false, "Unexpected event: " + e.type);
   finish();
@@ -52,25 +47,17 @@ function manifestUpdated()
     window.setTimeout("applicationCache.update()", 5000);
   });
 }
 
 function replaceManifest()
 {
   // If we replace the manifest after a downloading event, the update
   // should fail when it revalidates the manifest at the end of the update.
-
-  var req = new XMLHttpRequest();
-  req.open("PUT", "changingManifest.cacheManifest", false);
-  req.setRequestHeader("Content-Type", "text/cache-manifest");
-  req.send("CACHE MANIFEST\n" +
-           "# v2\n" +
-           "changing1Hour.sjs\n" +
-           "changing1Sec.sjs\n");
-
+  OfflineTest.setSJSState("changingManifest.sjs", "2");
 }
 
 function cached()
 {
   OfflineTest.ok(true, "Got the expected cached event.");
   finish();
 }
 
--- a/dom/tests/mochitest/ajax/offline/test_updatingManifest.html
+++ b/dom/tests/mochitest/ajax/offline/test_updatingManifest.html
@@ -1,9 +1,9 @@
-<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updating.cacheManifest">
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs">
 <head>
 <title>Cache update test</title>
 
 <script type="text/javascript" src="/MochiKit/packed.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
@@ -16,56 +16,16 @@
  * if the cache associated with the document is still the old
  * one. Then again modifies the manifest, checks items and finally
  * swaps cache for this document, reloads and checks document state.
  */
 
 const NAMESPACE_BYPASS = Components.interfaces.nsIApplicationCacheNamespace.NAMESPACE_BYPASS;
 const NAMESPACE_FALLBACK = Components.interfaces.nsIApplicationCacheNamespace.NAMESPACE_FALLBACK;
 
-var manifestVersion2Content =
-  "CACHE MANIFEST\n" +
-  "# v2\n" +
-  "\n" +
-  "http://localhost:8888/tests/SimpleTest/SimpleTest.js\n" +
-  "http://localhost:8888/MochiKit/packed.js\n" +
-  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js\n" +
-  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html" +
-  "\n" +
-  "FALLBACK:\n" +
-  "namespace1/ fallback.html\n" +
-  "namespace1/sub/ fallback2.html\n";
-
-var manifestVersion3Content =
-  "CACHE MANIFEST\n" +
-  "# v3\n" +
-  "\n" +
-  "http://localhost:8888/MochiKit/packed.js\n" +
-  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js\n" +
-  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html" +
-  "\n" +
-  "FALLBACK:\n" +
-  "namespace1/sub fallback2.html\n" +
-  "\n" +
-  "NETWORK:\n" +
-  "onwhitelist.html\n";
-
-
-var updatingFrameContent =
-  "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
-  "<head>\n" +
-  "<title>Update iframe</title>\n" +
-  "</head>\n" +
-  "<body onload=\"parent.frameLoad(2)\">\n" +
-  "Second version of updating iframe.\n" +
-  "</body>\n" +
-  "</html>\n";
-
-
-
 var gStep = 0;
 var gGotFrameVersion = 0;
 var gCallOnUpdatingFrameLoad = null;
 
 // Helpers
 
 function reloadLocations(frames)
 {
@@ -212,18 +172,17 @@ function implicitCached()
   // Cache object status
   OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.IDLE,
       "we have associated application cache (1)");
 
   OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1");
 
   ++gStep;
 
-  OfflineTest.putData("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updating.cacheManifest",
-      "text/cache-manifest", manifestVersion2Content);
+  OfflineTest.setSJSState("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "second");
 
   applicationCache.update();
   // Invokes manifestUpdated()
 }
 
 function manifestUpdated()
 {
   OfflineTest.ok(gStep == 1 || gStep == 2);
@@ -259,20 +218,18 @@ function manifestUpdated()
         "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false);
 
     // Cache object status
     OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.UPDATEREADY,
         "we have associated application cache and update is pending (2)");
 
     ++gStep;
 
-    OfflineTest.putData("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updating.cacheManifest",
-        "text/cache-manifest", manifestVersion3Content);
-    OfflineTest.putData("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html",
-        "text/html", updatingFrameContent);
+    OfflineTest.setSJSState("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "third");
+    OfflineTest.setSJSState("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", "second");
 
     gGotFrameVersion = 0;
     gCallOnUpdatingFrameLoad = function() {applicationCache.update();};
     updatingFrame.location.reload();
 
     break;
 
   case 2:
@@ -353,14 +310,14 @@ if (OfflineTest.setup()) {
   applicationCache.oncached = OfflineTest.priv(manifestCached);
 }
 
 </script>
 
 </head>
 
 <body>
-  <iframe name="updatingFrame" src="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html"></iframe>
+  <iframe name="updatingFrame" src="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs"></iframe>
   <iframe name="fallbackFrame1" src="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html"></iframe>
   <iframe name="fallbackFrame2" src="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html"></iframe>
   <iframe name="whitelistFrame" src="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html"></iframe>
 </body>
 </html>
deleted file mode 100644
--- a/dom/tests/mochitest/ajax/offline/updating.cacheManifest
+++ /dev/null
@@ -1,12 +0,0 @@
-CACHE MANIFEST
-# v1
-
-http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js
-http://localhost:8888/MochiKit/packed.js
-http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIFrame.html
-
-FALLBACK:
-namespace1/ fallback.html
-
-NETWORK:
-onwhitelist.html
deleted file mode 100644
--- a/dom/tests/mochitest/ajax/offline/updating.cacheManifest^headers^
+++ /dev/null
@@ -1,2 +0,0 @@
-Cache-Control: no-cache
-Content-Type: text/cache-manifest
deleted file mode 100644
--- a/dom/tests/mochitest/ajax/offline/updatingIFrame.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<title>Update iframe</title>
-</head>
-<body onload="parent.frameLoad(1)">
-First version of updating iframe.
-</body>
-</html>
deleted file mode 100644
--- a/dom/tests/mochitest/ajax/offline/updatingIFrame.html^headers^
+++ /dev/null
@@ -1,1 +0,0 @@
-Cache-Control: no-cache
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/updatingIframe.sjs
@@ -0,0 +1,45 @@
+ver1iframe =
+  "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
+  "<head>\n" +
+  "<title>Update iframe</title>\n" +
+  "</head>\n" +
+  "<body onload=\"parent.frameLoad(1)\">\n" +
+  "First version of updating iframe.\n" +
+  "</body>\n" +
+  "</html>\n";
+
+ver2iframe =
+  "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
+  "<head>\n" +
+  "<title>Update iframe</title>\n" +
+  "</head>\n" +
+  "<body onload=\"parent.frameLoad(2)\">\n" +
+  "Second version of updating iframe.\n" +
+  "</body>\n" +
+  "</html>\n";
+
+function handleRequest(request, response)
+{
+  var match = request.queryString.match(/^state=(.*)$/);
+  if (match)
+  {
+    response.setStatusLine(request.httpVersion, 204, "No content");
+    setState("offline.updatingIframe", match[1]);
+  }
+
+  if (request.queryString == "")
+  {
+    response.setStatusLine(request.httpVersion, 200, "Ok");
+    response.setHeader("Content-Type", "text/html");
+    response.setHeader("Cache-Control", "no-cache");
+    switch (getState("offline.updatingIframe"))
+    {
+      case "": // The default value
+        response.write(ver1iframe);
+        break;
+      case "second":
+        response.write(ver2iframe);
+        break;
+    }
+  }
+}
--- a/dom/tests/mochitest/ajax/offline/updatingImplicit.html
+++ b/dom/tests/mochitest/ajax/offline/updatingImplicit.html
@@ -1,9 +1,9 @@
-<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updating.cacheManifest">
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs">
 <head>
 <title>Updating implicit</title>
 
 <script type="text/javascript" src="/MochiKit/packed.js"></script>
 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
 
 <script type="text/javascript">
 
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/updatingManifest.sjs
@@ -0,0 +1,69 @@
+ver1manifest =
+  "CACHE MANIFEST\n" +
+  "# v1\n" +
+  "\n" +
+  "http://localhost:8888/MochiKit/packed.js\n" +
+  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js\n" +
+  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs\n" +
+  "\n" +
+  "FALLBACK:\n" +
+  "namespace1/ fallback.html\n" +
+  "\n" +
+  "NETWORK:\n" +
+  "onwhitelist.html\n";
+
+ver2manifest =
+  "CACHE MANIFEST\n" +
+  "# v2\n" +
+  "\n" +
+  "http://localhost:8888/tests/SimpleTest/SimpleTest.js\n" +
+  "http://localhost:8888/MochiKit/packed.js\n" +
+  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js\n" +
+  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs" +
+  "\n" +
+  "FALLBACK:\n" +
+  "namespace1/ fallback.html\n" +
+  "namespace1/sub/ fallback2.html\n";
+
+ver3manifest =
+  "CACHE MANIFEST\n" +
+  "# v3\n" +
+  "\n" +
+  "http://localhost:8888/MochiKit/packed.js\n" +
+  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js\n" +
+  "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs" +
+  "\n" +
+  "FALLBACK:\n" +
+  "namespace1/sub fallback2.html\n" +
+  "\n" +
+  "NETWORK:\n" +
+  "onwhitelist.html\n";
+
+function handleRequest(request, response)
+{
+  var match = request.queryString.match(/^state=(.*)$/);
+  if (match)
+  {
+    response.setStatusLine(request.httpVersion, 204, "No content");
+    setState("offline.updatingManifest", match[1]);
+  }
+
+  if (request.queryString == "")
+  {
+    response.setStatusLine(request.httpVersion, 200, "Ok");
+    response.setHeader("Content-Type", "text/cache-manifest");
+    response.setHeader("Cache-Control", "no-cache");
+    switch (getState("offline.updatingManifest"))
+    {
+      case "": // The default value
+        response.write(ver1manifest + "\n#" + getState("offline.updatingManifest"));
+        break;
+      case "second":
+        response.write(ver2manifest + "\n#" + getState("offline.updatingManifest"));
+        break;
+      case "third":
+        response.write(ver3manifest + "\n#" + getState("offline.updatingManifest"));
+        break;
+    }
+  }
+}