gecko/dom/tests/mochitest/ajax/offline/test_refetchManifest.html

91 lines
2.4 KiB
HTML

<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="/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()
{
OfflineTest.teardown();
OfflineTest.finish();
}
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>