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

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:aa777885e00f
1 <html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
2 <head>
3 <title>refetch manifest test</title>
4
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
7
8 <script type="text/javascript">
9
10 function finish()
11 {
12 OfflineTest.teardownAndFinish();
13 }
14
15 function failAndFinish(e)
16 {
17 OfflineTest.ok(false, "Unexpected event: " + e.type);
18 finish();
19 }
20
21 function manifestUpdated()
22 {
23 // Replace this manifest with a new one.
24
25 // XXX: After this put, we will no longer have Cache-Control:
26 // no-cache on the manifest, so future updates will just use the
27 // cached manifest.
28
29 // Get the initial contents of the first two files.
30 fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
31 fetcher.fetch(function(contents) {
32 gCacheContents = contents;
33
34 // Now make sure applicationCache.update() does what we expect.
35 applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
36 applicationCache.onnoupdate = failAndFinish;
37 applicationCache.oncached = failAndFinish;
38
39 gGotChecking = false;
40 gGotDownloading = false;
41
42 // The changing versions give out a new version each second,
43 // make sure it has time to grab a new version, and for the
44 // 1-second cache timeout to pass.
45 window.setTimeout("applicationCache.update()", 5000);
46 });
47 }
48
49 function replaceManifest()
50 {
51 // If we replace the manifest after a downloading event, the update
52 // should fail when it revalidates the manifest at the end of the update.
53 OfflineTest.setSJSState("changingManifest.sjs", "2");
54 }
55
56 function cached()
57 {
58 OfflineTest.ok(true, "Got the expected cached event.");
59 finish();
60 }
61
62 function gotError()
63 {
64 OfflineTest.ok(true, "Got the expected error event.");
65
66 // Now this update will be rescheduled, and it should succeed.
67 applicationCache.onerror = failAndFinish;
68 applicationCache.oncached = cached;
69 }
70
71 if (OfflineTest.setup()) {
72 applicationCache.onerror = gotError;
73 applicationCache.onnoupdate = failAndFinish;
74
75 applicationCache.ondownloading = replaceManifest;
76 applicationCache.oncached = failAndFinish;
77 }
78
79 SimpleTest.waitForExplicitFinish();
80
81 </script>
82
83 </head>
84
85 <body>
86
87 </body>
88 </html>

mercurial