summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/ajax/offline/test_refetchManifest.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/tests/mochitest/ajax/offline/test_refetchManifest.html')
-rw-r--r--dom/tests/mochitest/ajax/offline/test_refetchManifest.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/dom/tests/mochitest/ajax/offline/test_refetchManifest.html b/dom/tests/mochitest/ajax/offline/test_refetchManifest.html
new file mode 100644
index 000000000..a7205b73f
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/test_refetchManifest.html
@@ -0,0 +1,88 @@
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
+<head>
+<title>refetch manifest test</title>
+
+<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()
+{
+ OfflineTest.teardownAndFinish();
+}
+
+function failAndFinish(e)
+{
+ OfflineTest.ok(false, "Unexpected event: " + e.type);
+ finish();
+}
+
+function manifestUpdated()
+{
+ // 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.
+
+ // 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);
+ applicationCache.onnoupdate = failAndFinish;
+ applicationCache.oncached = failAndFinish;
+
+ gGotChecking = false;
+ gGotDownloading = false;
+
+ // The changing versions give out a new version each second,
+ // make sure it has time to grab a new version, and for the
+ // 1-second cache timeout to pass.
+ 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.
+ OfflineTest.setSJSState("changingManifest.sjs", "2");
+}
+
+function cached()
+{
+ OfflineTest.ok(true, "Got the expected cached event.");
+ finish();
+}
+
+function gotError()
+{
+ OfflineTest.ok(true, "Got the expected error event.");
+
+ // Now this update will be rescheduled, and it should succeed.
+ applicationCache.onerror = failAndFinish;
+ applicationCache.oncached = cached;
+}
+
+if (OfflineTest.setup()) {
+ applicationCache.onerror = gotError;
+ applicationCache.onnoupdate = failAndFinish;
+
+ applicationCache.ondownloading = replaceManifest;
+ applicationCache.oncached = failAndFinish;
+}
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+
+</head>
+
+<body>
+
+</body>
+</html>