summaryrefslogtreecommitdiff
path: root/dom/tests/mochitest/ajax/offline/test_refetchManifest.html
blob: a7205b73f9d4ca56003dcc6279411b3a8fd17c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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>