|
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>Offline mode 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 loads a manifest and cache it. |
|
13 * Then tests if all works in online mode |
|
14 * as expected. Then switches firefox to offline |
|
15 * mode and tries the page load still works as |
|
16 * expected, i.e. all items from the cache load. |
|
17 */ |
|
18 |
|
19 var gImplicitWindow = null; |
|
20 var gCompleteTimeout = null; |
|
21 var gGotExplicitVersion = 0; |
|
22 var gGotImplicitVersion = 0; |
|
23 var gGotDynamicVersion = 0; |
|
24 var gGotOnError = false; |
|
25 |
|
26 function createURI(urispec) |
|
27 { |
|
28 var ioServ = Components.classes["@mozilla.org/network/io-service;1"] |
|
29 .getService(Components.interfaces.nsIIOService); |
|
30 return ioServ.newURI(urispec, null, null); |
|
31 } |
|
32 |
|
33 // test |
|
34 |
|
35 function manifestUpdated() |
|
36 { |
|
37 applicationCache.mozAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html"); |
|
38 OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html", dynamicAdded); |
|
39 } |
|
40 |
|
41 function dynamicAdded() |
|
42 { |
|
43 aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html"; |
|
44 } |
|
45 |
|
46 // Called by the dynamically added iframe on load |
|
47 function notwhitelistOnLoad() |
|
48 { |
|
49 gGotDynamicVersion = 1; |
|
50 aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs"; |
|
51 } |
|
52 |
|
53 // Called by the explicit iframe on load |
|
54 function frameLoad(version) |
|
55 { |
|
56 gGotExplicitVersion = version; |
|
57 gImplicitWindow = window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html"); |
|
58 } |
|
59 |
|
60 // Called by the implicit window on load |
|
61 function implicitLoaded(aWindow, errorOccured) |
|
62 { |
|
63 aWindow.close(); |
|
64 |
|
65 gGotImplicitVersion = 1; |
|
66 OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", implicitAdded); |
|
67 } |
|
68 |
|
69 function implicitAdded() |
|
70 { |
|
71 OfflineTest.priv(finalize)(); |
|
72 } |
|
73 |
|
74 function finalize() |
|
75 { |
|
76 window.clearTimeout(gCompleteTimeout); |
|
77 |
|
78 var ioserv = Cc["@mozilla.org/network/io-service;1"] |
|
79 .getService(Ci.nsIIOService); |
|
80 |
|
81 if (!ioserv.offline) |
|
82 { |
|
83 OfflineTest.is(gGotExplicitVersion, 1, "Explicit entry loaded"); |
|
84 OfflineTest.is(gGotImplicitVersion, 1, "Implicit entry loaded"); |
|
85 OfflineTest.is(gGotDynamicVersion, 1, "Dynamic entry loaded"); |
|
86 |
|
87 gGotExplicitVersion = 0; |
|
88 gGotImplicitVersion = 0; |
|
89 gGotDynamicVersion = 0; |
|
90 |
|
91 var entries = [ |
|
92 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html", true], |
|
93 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", true], |
|
94 ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true] |
|
95 ]; |
|
96 OfflineTest.checkCacheEntries(entries, goOffline); |
|
97 } |
|
98 else |
|
99 { |
|
100 gImplicitWindow.close(); |
|
101 |
|
102 ioserv.offline = false; |
|
103 |
|
104 OfflineTest.is(gGotExplicitVersion, 1, "Explicit entry loaded"); |
|
105 OfflineTest.is(gGotImplicitVersion, 1, "Bug 461325 - Implicit entry loaded"); |
|
106 OfflineTest.is(gGotDynamicVersion, 1, "Dynamic entry loaded"); |
|
107 OfflineTest.ok(gGotOnError, "Got onerror event invoked by implicit page load in offline mode"); |
|
108 |
|
109 OfflineTest.teardownAndFinish(); |
|
110 } |
|
111 } |
|
112 |
|
113 function goOffline() |
|
114 { |
|
115 var listener = { |
|
116 onCacheEntryDoomed: function (status) { |
|
117 OfflineTest.priv(goOfflineContinue)(); |
|
118 } |
|
119 }; |
|
120 |
|
121 // Delete HTTP cache to ensure we are going from offline cache |
|
122 var cache = Cc["@mozilla.org/network/cache-storage-service;1"] |
|
123 .getService(Ci.nsICacheStorageService); |
|
124 var storage = cache.diskCacheStorage(LoadContextInfo.default, false); |
|
125 storage.asyncDoomURI(createURI("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html"), "", null); |
|
126 storage.asyncDoomURI(createURI("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs"), "", null); |
|
127 storage.asyncDoomURI(createURI("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html"), "", listener); |
|
128 } |
|
129 |
|
130 function goOfflineContinue() |
|
131 { |
|
132 var ioserv = Cc["@mozilla.org/network/io-service;1"] |
|
133 .getService(Ci.nsIIOService); |
|
134 |
|
135 ioserv.offline = true; |
|
136 |
|
137 gCompleteTimeout = window.setTimeout(OfflineTest.priv(finalize), 10000); |
|
138 |
|
139 // remove error handling. in offline mode |
|
140 // is correct to get error message |
|
141 applicationCache.onerror = function() {gGotOnError = true;} |
|
142 |
|
143 aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html"; |
|
144 // Starts the chain all over again but in offline mode. |
|
145 } |
|
146 |
|
147 SimpleTest.waitForExplicitFinish(); |
|
148 |
|
149 if (OfflineTest.setup()) { |
|
150 applicationCache.onerror = OfflineTest.failEvent; |
|
151 applicationCache.onupdateready = OfflineTest.failEvent; |
|
152 applicationCache.oncached = OfflineTest.priv(manifestUpdated); |
|
153 } |
|
154 |
|
155 </script> |
|
156 |
|
157 </head> |
|
158 |
|
159 <body> |
|
160 |
|
161 <iframe name="aFrame" src=""></iframe> |
|
162 |
|
163 </body> |
|
164 </html> |