|
1 <html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs"> |
|
2 <head> |
|
3 <title>Cache update 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 class="testbody" type="text/javascript"> |
|
10 |
|
11 /* |
|
12 * The test is checking nsIOfflineCacheUpdateService.checkForUpdate API: |
|
13 * - cache a manifest |
|
14 * - check for an update of it, expected is "no update avail" |
|
15 * - modify the manifest on the server |
|
16 * - check for an update again, expected is "update avail" |
|
17 * - check for an update ones again, expected is "update avail" (secondary check to probe |
|
18 * we didn't screw state of the manifest in the current cache with the first check) |
|
19 * - cache the modified manifest, new version is now in the cache |
|
20 * - last check for an update, expected is "no update avail" again |
|
21 */ |
|
22 |
|
23 SimpleTest.waitForExplicitFinish(); |
|
24 |
|
25 var manifest = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs"; |
|
26 var manifestURI = Cc["@mozilla.org/network/io-service;1"] |
|
27 .getService(Ci.nsIIOService) |
|
28 .newURI(manifest, null, null); |
|
29 var updateService = Cc['@mozilla.org/offlinecacheupdate-service;1'] |
|
30 .getService(Ci.nsIOfflineCacheUpdateService); |
|
31 |
|
32 function manifestCached() |
|
33 { |
|
34 // Run first check for an update |
|
35 updateService.checkForUpdate(manifestURI, 0, false, { |
|
36 observe: function(subject, topic, data) { |
|
37 OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail"); |
|
38 |
|
39 // Change the manifest content |
|
40 OfflineTest.setSJSState(manifest, "second"); |
|
41 |
|
42 // Check we now get notification on update ready |
|
43 updateService.checkForUpdate(manifestURI, 0, false, { |
|
44 observe: function(subject, topic, data) { |
|
45 OfflineTest.is(topic, "offline-cache-update-available", "Update avail (1)"); |
|
46 |
|
47 // Do the check again. We must get the same result. Double check is here |
|
48 // to make sure we don't overwrite any data in the cache by the check it self. |
|
49 updateService.checkForUpdate(manifestURI, 0, false, { |
|
50 observe: function(subject, topic, data) { |
|
51 OfflineTest.is(topic, "offline-cache-update-available", "Update avail (2)"); |
|
52 |
|
53 // Update the manifest, invokes manifestUpdated() |
|
54 applicationCache.onupdateready = OfflineTest.priv(manifestUpdated); |
|
55 applicationCache.update(); |
|
56 } |
|
57 }); |
|
58 } |
|
59 }); |
|
60 } |
|
61 }); |
|
62 } |
|
63 |
|
64 function manifestUpdated() |
|
65 { |
|
66 // Check for an update after manifest has been updated |
|
67 updateService.checkForUpdate(manifestURI, 0, false, { |
|
68 observe: function(subject, topic, data) { |
|
69 OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail (2)"); |
|
70 |
|
71 OfflineTest.teardownAndFinish(); |
|
72 } |
|
73 }); |
|
74 } |
|
75 |
|
76 if (OfflineTest.setup()) { |
|
77 applicationCache.onerror = OfflineTest.failEvent; |
|
78 applicationCache.oncached = OfflineTest.priv(manifestCached); |
|
79 } |
|
80 |
|
81 </script> |
|
82 </head> |
|
83 <body> |
|
84 </body> |
|
85 </html> |