|
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>changing 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 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 |
|
9 <script type="text/javascript"> |
|
10 |
|
11 var gGotChecking = false; |
|
12 var gGotDownloading = false; |
|
13 |
|
14 var g1SecUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Sec.sjs"; |
|
15 var g1HourUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Hour.sjs"; |
|
16 |
|
17 var gCacheContents = null; |
|
18 |
|
19 function finish() |
|
20 { |
|
21 OfflineTest.teardownAndFinish(); |
|
22 } |
|
23 |
|
24 function manifestUpdatedAgain() |
|
25 { |
|
26 OfflineTest.ok(gGotChecking, "Should get a checking event on the second update"); |
|
27 OfflineTest.ok(gGotDownloading, "Should get a downloading event on the second update"); |
|
28 |
|
29 // The second manifest has no NETWORK entry, but we are still |
|
30 // associated with the first version of the manifest, so we should |
|
31 // be able to access the whitelisted entry. |
|
32 try { |
|
33 var xhr = new XMLHttpRequest(); |
|
34 xhr.open("GET", "onwhitelist.html", false); |
|
35 xhr.send(); |
|
36 OfflineTest.ok(true, "Fetched from the initial cache's whitelist."); |
|
37 } catch (e) { |
|
38 OfflineTest.ok(false, "Failed to fetch from the initial cache's whitelist."); |
|
39 } |
|
40 |
|
41 // Get the initial contents of the first two files. |
|
42 fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]); |
|
43 fetcher.fetch(function(contents) { |
|
44 // Make sure the contents of the 1-second-expiration file have changed, |
|
45 // but that the 1-hour-expiration has not. |
|
46 OfflineTest.isnot(gCacheContents[g1SecUrl], contents[g1SecUrl], "1-second expiration should have changed"); |
|
47 OfflineTest.is(gCacheContents[g1HourUrl], contents[g1HourUrl], "1-hour expiration should not have changed"); |
|
48 |
|
49 finish(); |
|
50 }); |
|
51 } |
|
52 |
|
53 function failAndFinish(e) { |
|
54 OfflineTest.ok(false, "Unexpected event: " + e.type); |
|
55 finish(); |
|
56 } |
|
57 |
|
58 function manifestUpdated() |
|
59 { |
|
60 OfflineTest.ok(gGotChecking, "Should get a checking event"); |
|
61 OfflineTest.ok(gGotDownloading, "Should get a downloading event"); |
|
62 |
|
63 // Replace this manifest with a new one. |
|
64 OfflineTest.setSJSState("changingManifest.sjs", "2"); |
|
65 |
|
66 // Get the initial contents of the first two files. |
|
67 fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]); |
|
68 fetcher.fetch(function(contents) { |
|
69 gCacheContents = contents; |
|
70 |
|
71 // Now make sure applicationCache.update() does what we expect. |
|
72 applicationCache.onchecking = function() { |
|
73 OfflineTest.is(applicationCache.status, applicationCache.CHECKING, |
|
74 "CHECKING state during update"); |
|
75 gGotChecking = true; |
|
76 }; |
|
77 applicationCache.ondownloading = function() { |
|
78 OfflineTest.is(applicationCache.status, applicationCache.DOWNLOADING, |
|
79 "DOWNLOADING state during update"); |
|
80 gGotDownloading = true; |
|
81 }; |
|
82 |
|
83 applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain); |
|
84 applicationCache.onnoupdate = failAndFinish; |
|
85 applicationCache.oncached = failAndFinish; |
|
86 |
|
87 gGotChecking = false; |
|
88 gGotDownloading = false; |
|
89 |
|
90 // The changing versions give out a new version each second, |
|
91 // make sure it has time to grab a new version, and for the |
|
92 // 1-second cache timeout to pass. |
|
93 window.setTimeout("applicationCache.update()", 5000); |
|
94 }); |
|
95 } |
|
96 |
|
97 if (OfflineTest.setup()) { |
|
98 applicationCache.onerror = failAndFinish; |
|
99 applicationCache.onnoupdate = failAndFinish; |
|
100 |
|
101 applicationCache.onchecking = function() { gGotChecking = true; }; |
|
102 applicationCache.ondownloading = function() { gGotDownloading = true; }; |
|
103 applicationCache.oncached = OfflineTest.priv(manifestUpdated); |
|
104 } |
|
105 |
|
106 SimpleTest.waitForExplicitFinish(); |
|
107 |
|
108 </script> |
|
109 |
|
110 </head> |
|
111 |
|
112 <body> |
|
113 |
|
114 </body> |
|
115 </html> |