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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/ajax/offline/test_refetchManifest.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
     1.5 +<head>
     1.6 +<title>refetch manifest test</title>
     1.7 +
     1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
    1.10 +
    1.11 +<script type="text/javascript">
    1.12 +
    1.13 +function finish()
    1.14 +{
    1.15 +  OfflineTest.teardownAndFinish();
    1.16 +}
    1.17 +
    1.18 +function failAndFinish(e)
    1.19 +{
    1.20 +  OfflineTest.ok(false, "Unexpected event: " + e.type);
    1.21 +  finish();
    1.22 +}
    1.23 +
    1.24 +function manifestUpdated()
    1.25 +{
    1.26 +  // Replace this manifest with a new one.
    1.27 +
    1.28 +  // XXX: After this put, we will no longer have Cache-Control:
    1.29 +  // no-cache on the manifest, so future updates will just use the
    1.30 +  // cached manifest.
    1.31 +
    1.32 +  // Get the initial contents of the first two files.
    1.33 +  fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
    1.34 +  fetcher.fetch(function(contents) {
    1.35 +    gCacheContents = contents;
    1.36 +
    1.37 +    // Now make sure applicationCache.update() does what we expect.
    1.38 +    applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
    1.39 +    applicationCache.onnoupdate = failAndFinish;
    1.40 +    applicationCache.oncached = failAndFinish;
    1.41 +
    1.42 +    gGotChecking = false;
    1.43 +    gGotDownloading = false;
    1.44 +
    1.45 +    // The changing versions give out a new version each second,
    1.46 +    // make sure it has time to grab a new version, and for the
    1.47 +    // 1-second cache timeout to pass.
    1.48 +    window.setTimeout("applicationCache.update()", 5000);
    1.49 +  });
    1.50 +}
    1.51 +
    1.52 +function replaceManifest()
    1.53 +{
    1.54 +  // If we replace the manifest after a downloading event, the update
    1.55 +  // should fail when it revalidates the manifest at the end of the update.
    1.56 +  OfflineTest.setSJSState("changingManifest.sjs", "2");
    1.57 +}
    1.58 +
    1.59 +function cached()
    1.60 +{
    1.61 +  OfflineTest.ok(true, "Got the expected cached event.");
    1.62 +  finish();
    1.63 +}
    1.64 +
    1.65 +function gotError()
    1.66 +{
    1.67 +  OfflineTest.ok(true, "Got the expected error event.");
    1.68 +
    1.69 +  // Now this update will be rescheduled, and it should succeed.
    1.70 +  applicationCache.onerror = failAndFinish;
    1.71 +  applicationCache.oncached = cached;
    1.72 +}
    1.73 +
    1.74 +if (OfflineTest.setup()) {
    1.75 +  applicationCache.onerror = gotError;
    1.76 +  applicationCache.onnoupdate = failAndFinish;
    1.77 +
    1.78 +  applicationCache.ondownloading = replaceManifest;
    1.79 +  applicationCache.oncached = failAndFinish;
    1.80 +}
    1.81 +
    1.82 +SimpleTest.waitForExplicitFinish();
    1.83 +
    1.84 +</script>
    1.85 +
    1.86 +</head>
    1.87 +
    1.88 +<body>
    1.89 +
    1.90 +</body>
    1.91 +</html>

mercurial