|
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 * This test loads manifest and checks presence of all items. |
|
13 * Then it modifies the manifest and updates the cache again. |
|
14 * Then test presence of items according to the spec and also |
|
15 * if the cache associated with the document is still the old |
|
16 * one. Then again modifies the manifest, checks items and finally |
|
17 * swaps cache for this document, reloads and checks document state. |
|
18 */ |
|
19 |
|
20 const NAMESPACE_BYPASS = SpecialPowers.Ci.nsIApplicationCacheNamespace.NAMESPACE_BYPASS; |
|
21 const NAMESPACE_FALLBACK = SpecialPowers.Ci.nsIApplicationCacheNamespace.NAMESPACE_FALLBACK; |
|
22 |
|
23 var gStep = 0; |
|
24 var gGotFrameVersion = 0; |
|
25 var gCallOnUpdatingFrameLoad = null; |
|
26 |
|
27 // Helpers |
|
28 |
|
29 function reloadLocations(frames) |
|
30 { |
|
31 for (frame in frames) |
|
32 frames[frame].location.reload(); |
|
33 } |
|
34 |
|
35 function waitForLocations(frames, doneFunc) |
|
36 { |
|
37 frame = frames.shift(); |
|
38 if (frame) |
|
39 // toString() might cause problems when this test will |
|
40 // completely be changed to test IDN behavior. |
|
41 OfflineTest.waitForAdd(frame, function() |
|
42 { |
|
43 waitForLocations(frames, doneFunc); |
|
44 } |
|
45 ); |
|
46 else |
|
47 { |
|
48 doneFunc(); |
|
49 } |
|
50 } |
|
51 |
|
52 function checkFallbackAndWhitelisting(key, fallback, onwhitelist) |
|
53 { |
|
54 // Get matching namespace for the key |
|
55 var matchingNamespace = OfflineTest.getActiveCache() |
|
56 .getMatchingNamespace(key); |
|
57 |
|
58 // If we are not expecting the key is to be on white list or |
|
59 // has been assigned a fallback check there is not any matching |
|
60 // namespace found and exit |
|
61 if (!fallback && !onwhitelist) { |
|
62 is(matchingNamespace, null, "No namespace found for "+key); |
|
63 return; |
|
64 } |
|
65 |
|
66 // We expect this entry is on the white list or has a fallback |
|
67 // entry assigned, check we found a matching namespace |
|
68 ok(matchingNamespace, "We have a namespace for "+key); |
|
69 if (!matchingNamespace) |
|
70 return; |
|
71 |
|
72 // We expect the key be assigned a fallback URI, check the namespace |
|
73 // type is of fallback type |
|
74 OfflineTest.is(!!(matchingNamespace.itemType & NAMESPACE_FALLBACK), !!fallback, |
|
75 (fallback ? "Namespace type is fallback for " : "Namespace type is not fallback for ")+key); |
|
76 |
|
77 // We expect the key be assigned a fallback URI, check the URI is |
|
78 // equal to expected one |
|
79 OfflineTest.is(matchingNamespace.data, fallback, |
|
80 (fallback ? "Expected correct fallback for " : "No fallback for ")+key); |
|
81 |
|
82 // We expect the key be on the white list, check the namespace type |
|
83 // is of bypass type |
|
84 OfflineTest.is(!!(matchingNamespace.itemType & NAMESPACE_BYPASS), onwhitelist, |
|
85 (onwhitelist ? "On white list " : "Not on white list ")+key); |
|
86 } |
|
87 |
|
88 // Events |
|
89 |
|
90 function frameLoad(version) |
|
91 { |
|
92 gGotFrameVersion = version; |
|
93 if (gCallOnUpdatingFrameLoad) |
|
94 { |
|
95 var call = gCallOnUpdatingFrameLoad; |
|
96 gCallOnUpdatingFrameLoad = null; |
|
97 SimpleTest.executeSoon(OfflineTest.priv(call)); |
|
98 } |
|
99 } |
|
100 |
|
101 function whitelistOnLoad(version) |
|
102 { |
|
103 // Whitelisting is not tested by this test... |
|
104 } |
|
105 |
|
106 |
|
107 // Start of the test function chain |
|
108 // ================================ |
|
109 |
|
110 function manifestCached() |
|
111 { |
|
112 OfflineTest.is(gStep, 0, "Got manifestCached in step 0, gStep=" + gStep); |
|
113 |
|
114 reloadLocations([fallbackFrame1, fallbackFrame2]); |
|
115 waitForLocations( |
|
116 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html"], |
|
117 fallbackLoaded |
|
118 ); |
|
119 } |
|
120 |
|
121 function fallbackLoaded() |
|
122 { |
|
123 dump("in fallbackLoaded\n"); |
|
124 applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"); |
|
125 OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", |
|
126 dynamicLoaded); |
|
127 } |
|
128 |
|
129 function dynamicLoaded() |
|
130 { |
|
131 window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html"); |
|
132 // window.applicationCache.noupdate invokes implicitLoaded() |
|
133 } |
|
134 |
|
135 function implicitLoaded(aWindow, errorOccured) |
|
136 { |
|
137 aWindow.close(); |
|
138 |
|
139 OfflineTest.ok(!errorOccured, "No error on new implicit page manifest update"); |
|
140 |
|
141 OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", |
|
142 implicitCached); |
|
143 } |
|
144 |
|
145 function implicitCached() |
|
146 { |
|
147 // Checking first version of the manifest + another implict page caching |
|
148 |
|
149 // Whitelist entries |
|
150 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true); |
|
151 |
|
152 // Fallback URI selection check |
|
153 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html", |
|
154 "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false); |
|
155 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html", |
|
156 "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false); |
|
157 |
|
158 // Cache object status |
|
159 OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.IDLE, |
|
160 "we have associated application cache (1)"); |
|
161 |
|
162 OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1"); |
|
163 |
|
164 var entries = [ |
|
165 // Explicit entries |
|
166 ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false], |
|
167 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], |
|
168 |
|
169 // Fallback entries |
|
170 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", true], |
|
171 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false], |
|
172 |
|
173 // Whitelist entries |
|
174 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false], |
|
175 |
|
176 // Implicit entries |
|
177 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true], |
|
178 |
|
179 // Dynamic entries |
|
180 ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true] |
|
181 ]; |
|
182 OfflineTest.checkCacheEntries( |
|
183 entries, |
|
184 function() { |
|
185 ++gStep; |
|
186 |
|
187 OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "second"); |
|
188 |
|
189 applicationCache.update(); |
|
190 // Invokes manifestUpdated() |
|
191 }); |
|
192 } |
|
193 |
|
194 function manifestUpdated() |
|
195 { |
|
196 OfflineTest.ok(gStep == 1 || gStep == 2, "Got manifestUpdated in step 1 or 2, gStep=" + gStep); |
|
197 |
|
198 switch (gStep) |
|
199 { |
|
200 case 1: |
|
201 // Processing second version of the manifest. |
|
202 |
|
203 // Whitelist entries |
|
204 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", false); |
|
205 |
|
206 // Fallback URI selection check |
|
207 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html", |
|
208 "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false); |
|
209 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html", |
|
210 "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false); |
|
211 |
|
212 // Cache object status |
|
213 OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY, |
|
214 "we have associated application cache and update is pending (2)"); |
|
215 |
|
216 var entries = [ |
|
217 // Explicit entries |
|
218 ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", true], |
|
219 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], |
|
220 |
|
221 // Fallback entries |
|
222 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", true], |
|
223 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", true], |
|
224 |
|
225 // Whitelist entries |
|
226 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false], |
|
227 |
|
228 // Implicit entries |
|
229 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true], |
|
230 |
|
231 // Dynamic entries |
|
232 ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true] |
|
233 ]; |
|
234 OfflineTest.checkCacheEntries( |
|
235 entries, |
|
236 function() { |
|
237 ++gStep; |
|
238 |
|
239 OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "third"); |
|
240 OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", "second"); |
|
241 |
|
242 gGotFrameVersion = 0; |
|
243 updatingFrame.location.reload(); |
|
244 // Since the frame is offline-cached, reload of it invokes update |
|
245 }); |
|
246 |
|
247 break; |
|
248 |
|
249 case 2: |
|
250 // Processing third version of the manifest. |
|
251 |
|
252 // Whitelist entries |
|
253 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true); |
|
254 |
|
255 // Fallback URI selection check |
|
256 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html", |
|
257 "", false); |
|
258 checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html", |
|
259 "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false); |
|
260 |
|
261 // Cache object status |
|
262 OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY, |
|
263 "we have associated application cache and update is pending (3)"); |
|
264 |
|
265 OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1 because cache was not swapped"); |
|
266 |
|
267 var entries = [ |
|
268 // Explicit entries |
|
269 ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false], |
|
270 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], |
|
271 |
|
272 // Fallback entries |
|
273 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false], |
|
274 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", true], |
|
275 |
|
276 // Whitelist entries |
|
277 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false], |
|
278 |
|
279 // Implicit entries |
|
280 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true], |
|
281 |
|
282 // Dynamic entries |
|
283 ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true] |
|
284 ]; |
|
285 OfflineTest.checkCacheEntries( |
|
286 entries, |
|
287 function() { |
|
288 ++gStep; |
|
289 |
|
290 applicationCache.onnoupdate = OfflineTest.priv(manifestNoUpdate); |
|
291 applicationCache.update(); |
|
292 // Invokes manifestNoUpdate() |
|
293 }); |
|
294 |
|
295 break; |
|
296 } |
|
297 } |
|
298 |
|
299 function manifestNoUpdate() |
|
300 { |
|
301 applicationCache.onnoupdate = null; |
|
302 |
|
303 OfflineTest.ok(gStep == 3, "Got manifestNoUpdate in step 3, gStep=" + gStep); |
|
304 ++gStep; |
|
305 |
|
306 OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY, |
|
307 "we have associated application cache and update is pending (4)"); |
|
308 applicationCache.swapCache(); |
|
309 OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.IDLE, |
|
310 "we have associated application cache (4)"); |
|
311 |
|
312 gGotFrameVersion = 0; |
|
313 gCallOnUpdatingFrameLoad = checkNewVersionOfIFrame; |
|
314 updatingFrame.location.reload(); |
|
315 } |
|
316 |
|
317 function checkNewVersionOfIFrame() |
|
318 { |
|
319 OfflineTest.is(gGotFrameVersion, 2, "IFrame version 2"); |
|
320 |
|
321 OfflineTest.teardownAndFinish(); |
|
322 } |
|
323 |
|
324 // End of the test function chain |
|
325 // ============================== |
|
326 |
|
327 SimpleTest.waitForExplicitFinish(); |
|
328 |
|
329 if (OfflineTest.setup()) { |
|
330 applicationCache.onerror = OfflineTest.failEvent; |
|
331 applicationCache.onupdateready = OfflineTest.priv(manifestUpdated); |
|
332 applicationCache.oncached = OfflineTest.priv(manifestCached); |
|
333 } |
|
334 |
|
335 </script> |
|
336 |
|
337 </head> |
|
338 |
|
339 <body> |
|
340 <iframe name="updatingFrame" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs"></iframe> |
|
341 <iframe name="fallbackFrame1" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html"></iframe> |
|
342 <iframe name="fallbackFrame2" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html"></iframe> |
|
343 <iframe name="whitelistFrame" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html"></iframe> |
|
344 </body> |
|
345 </html> |