1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/ajax/offline/test_updatingManifest.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,345 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs"> 1.5 +<head> 1.6 +<title>Cache update test</title> 1.7 + 1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 +<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script> 1.10 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 + 1.12 +<script class="testbody" type="text/javascript"> 1.13 + 1.14 +/** 1.15 + * This test loads manifest and checks presence of all items. 1.16 + * Then it modifies the manifest and updates the cache again. 1.17 + * Then test presence of items according to the spec and also 1.18 + * if the cache associated with the document is still the old 1.19 + * one. Then again modifies the manifest, checks items and finally 1.20 + * swaps cache for this document, reloads and checks document state. 1.21 + */ 1.22 + 1.23 +const NAMESPACE_BYPASS = SpecialPowers.Ci.nsIApplicationCacheNamespace.NAMESPACE_BYPASS; 1.24 +const NAMESPACE_FALLBACK = SpecialPowers.Ci.nsIApplicationCacheNamespace.NAMESPACE_FALLBACK; 1.25 + 1.26 +var gStep = 0; 1.27 +var gGotFrameVersion = 0; 1.28 +var gCallOnUpdatingFrameLoad = null; 1.29 + 1.30 +// Helpers 1.31 + 1.32 +function reloadLocations(frames) 1.33 +{ 1.34 + for (frame in frames) 1.35 + frames[frame].location.reload(); 1.36 +} 1.37 + 1.38 +function waitForLocations(frames, doneFunc) 1.39 +{ 1.40 + frame = frames.shift(); 1.41 + if (frame) 1.42 + // toString() might cause problems when this test will 1.43 + // completely be changed to test IDN behavior. 1.44 + OfflineTest.waitForAdd(frame, function() 1.45 + { 1.46 + waitForLocations(frames, doneFunc); 1.47 + } 1.48 + ); 1.49 + else 1.50 + { 1.51 + doneFunc(); 1.52 + } 1.53 +} 1.54 + 1.55 +function checkFallbackAndWhitelisting(key, fallback, onwhitelist) 1.56 +{ 1.57 + // Get matching namespace for the key 1.58 + var matchingNamespace = OfflineTest.getActiveCache() 1.59 + .getMatchingNamespace(key); 1.60 + 1.61 + // If we are not expecting the key is to be on white list or 1.62 + // has been assigned a fallback check there is not any matching 1.63 + // namespace found and exit 1.64 + if (!fallback && !onwhitelist) { 1.65 + is(matchingNamespace, null, "No namespace found for "+key); 1.66 + return; 1.67 + } 1.68 + 1.69 + // We expect this entry is on the white list or has a fallback 1.70 + // entry assigned, check we found a matching namespace 1.71 + ok(matchingNamespace, "We have a namespace for "+key); 1.72 + if (!matchingNamespace) 1.73 + return; 1.74 + 1.75 + // We expect the key be assigned a fallback URI, check the namespace 1.76 + // type is of fallback type 1.77 + OfflineTest.is(!!(matchingNamespace.itemType & NAMESPACE_FALLBACK), !!fallback, 1.78 + (fallback ? "Namespace type is fallback for " : "Namespace type is not fallback for ")+key); 1.79 + 1.80 + // We expect the key be assigned a fallback URI, check the URI is 1.81 + // equal to expected one 1.82 + OfflineTest.is(matchingNamespace.data, fallback, 1.83 + (fallback ? "Expected correct fallback for " : "No fallback for ")+key); 1.84 + 1.85 + // We expect the key be on the white list, check the namespace type 1.86 + // is of bypass type 1.87 + OfflineTest.is(!!(matchingNamespace.itemType & NAMESPACE_BYPASS), onwhitelist, 1.88 + (onwhitelist ? "On white list " : "Not on white list ")+key); 1.89 +} 1.90 + 1.91 +// Events 1.92 + 1.93 +function frameLoad(version) 1.94 +{ 1.95 + gGotFrameVersion = version; 1.96 + if (gCallOnUpdatingFrameLoad) 1.97 + { 1.98 + var call = gCallOnUpdatingFrameLoad; 1.99 + gCallOnUpdatingFrameLoad = null; 1.100 + SimpleTest.executeSoon(OfflineTest.priv(call)); 1.101 + } 1.102 +} 1.103 + 1.104 +function whitelistOnLoad(version) 1.105 +{ 1.106 + // Whitelisting is not tested by this test... 1.107 +} 1.108 + 1.109 + 1.110 +// Start of the test function chain 1.111 +// ================================ 1.112 + 1.113 +function manifestCached() 1.114 +{ 1.115 + OfflineTest.is(gStep, 0, "Got manifestCached in step 0, gStep=" + gStep); 1.116 + 1.117 + reloadLocations([fallbackFrame1, fallbackFrame2]); 1.118 + waitForLocations( 1.119 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html"], 1.120 + fallbackLoaded 1.121 + ); 1.122 +} 1.123 + 1.124 +function fallbackLoaded() 1.125 +{ 1.126 + dump("in fallbackLoaded\n"); 1.127 + applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"); 1.128 + OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", 1.129 + dynamicLoaded); 1.130 +} 1.131 + 1.132 +function dynamicLoaded() 1.133 +{ 1.134 + window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html"); 1.135 + // window.applicationCache.noupdate invokes implicitLoaded() 1.136 +} 1.137 + 1.138 +function implicitLoaded(aWindow, errorOccured) 1.139 +{ 1.140 + aWindow.close(); 1.141 + 1.142 + OfflineTest.ok(!errorOccured, "No error on new implicit page manifest update"); 1.143 + 1.144 + OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", 1.145 + implicitCached); 1.146 +} 1.147 + 1.148 +function implicitCached() 1.149 +{ 1.150 + // Checking first version of the manifest + another implict page caching 1.151 + 1.152 + // Whitelist entries 1.153 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true); 1.154 + 1.155 + // Fallback URI selection check 1.156 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html", 1.157 + "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false); 1.158 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html", 1.159 + "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false); 1.160 + 1.161 + // Cache object status 1.162 + OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.IDLE, 1.163 + "we have associated application cache (1)"); 1.164 + 1.165 + OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1"); 1.166 + 1.167 + var entries = [ 1.168 + // Explicit entries 1.169 + ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false], 1.170 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], 1.171 + 1.172 + // Fallback entries 1.173 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", true], 1.174 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false], 1.175 + 1.176 + // Whitelist entries 1.177 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false], 1.178 + 1.179 + // Implicit entries 1.180 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true], 1.181 + 1.182 + // Dynamic entries 1.183 + ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true] 1.184 + ]; 1.185 + OfflineTest.checkCacheEntries( 1.186 + entries, 1.187 + function() { 1.188 + ++gStep; 1.189 + 1.190 + OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "second"); 1.191 + 1.192 + applicationCache.update(); 1.193 + // Invokes manifestUpdated() 1.194 + }); 1.195 +} 1.196 + 1.197 +function manifestUpdated() 1.198 +{ 1.199 + OfflineTest.ok(gStep == 1 || gStep == 2, "Got manifestUpdated in step 1 or 2, gStep=" + gStep); 1.200 + 1.201 + switch (gStep) 1.202 + { 1.203 + case 1: 1.204 + // Processing second version of the manifest. 1.205 + 1.206 + // Whitelist entries 1.207 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", false); 1.208 + 1.209 + // Fallback URI selection check 1.210 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html", 1.211 + "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false); 1.212 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html", 1.213 + "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false); 1.214 + 1.215 + // Cache object status 1.216 + OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY, 1.217 + "we have associated application cache and update is pending (2)"); 1.218 + 1.219 + var entries = [ 1.220 + // Explicit entries 1.221 + ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", true], 1.222 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], 1.223 + 1.224 + // Fallback entries 1.225 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", true], 1.226 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", true], 1.227 + 1.228 + // Whitelist entries 1.229 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false], 1.230 + 1.231 + // Implicit entries 1.232 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true], 1.233 + 1.234 + // Dynamic entries 1.235 + ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true] 1.236 + ]; 1.237 + OfflineTest.checkCacheEntries( 1.238 + entries, 1.239 + function() { 1.240 + ++gStep; 1.241 + 1.242 + OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "third"); 1.243 + OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", "second"); 1.244 + 1.245 + gGotFrameVersion = 0; 1.246 + updatingFrame.location.reload(); 1.247 + // Since the frame is offline-cached, reload of it invokes update 1.248 + }); 1.249 + 1.250 + break; 1.251 + 1.252 + case 2: 1.253 + // Processing third version of the manifest. 1.254 + 1.255 + // Whitelist entries 1.256 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true); 1.257 + 1.258 + // Fallback URI selection check 1.259 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html", 1.260 + "", false); 1.261 + checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html", 1.262 + "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false); 1.263 + 1.264 + // Cache object status 1.265 + OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY, 1.266 + "we have associated application cache and update is pending (3)"); 1.267 + 1.268 + OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1 because cache was not swapped"); 1.269 + 1.270 + var entries = [ 1.271 + // Explicit entries 1.272 + ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false], 1.273 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], 1.274 + 1.275 + // Fallback entries 1.276 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false], 1.277 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", true], 1.278 + 1.279 + // Whitelist entries 1.280 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false], 1.281 + 1.282 + // Implicit entries 1.283 + ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true], 1.284 + 1.285 + // Dynamic entries 1.286 + ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true] 1.287 + ]; 1.288 + OfflineTest.checkCacheEntries( 1.289 + entries, 1.290 + function() { 1.291 + ++gStep; 1.292 + 1.293 + applicationCache.onnoupdate = OfflineTest.priv(manifestNoUpdate); 1.294 + applicationCache.update(); 1.295 + // Invokes manifestNoUpdate() 1.296 + }); 1.297 + 1.298 + break; 1.299 + } 1.300 +} 1.301 + 1.302 +function manifestNoUpdate() 1.303 +{ 1.304 + applicationCache.onnoupdate = null; 1.305 + 1.306 + OfflineTest.ok(gStep == 3, "Got manifestNoUpdate in step 3, gStep=" + gStep); 1.307 + ++gStep; 1.308 + 1.309 + OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY, 1.310 + "we have associated application cache and update is pending (4)"); 1.311 + applicationCache.swapCache(); 1.312 + OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.IDLE, 1.313 + "we have associated application cache (4)"); 1.314 + 1.315 + gGotFrameVersion = 0; 1.316 + gCallOnUpdatingFrameLoad = checkNewVersionOfIFrame; 1.317 + updatingFrame.location.reload(); 1.318 +} 1.319 + 1.320 +function checkNewVersionOfIFrame() 1.321 +{ 1.322 + OfflineTest.is(gGotFrameVersion, 2, "IFrame version 2"); 1.323 + 1.324 + OfflineTest.teardownAndFinish(); 1.325 +} 1.326 + 1.327 +// End of the test function chain 1.328 +// ============================== 1.329 + 1.330 +SimpleTest.waitForExplicitFinish(); 1.331 + 1.332 +if (OfflineTest.setup()) { 1.333 + applicationCache.onerror = OfflineTest.failEvent; 1.334 + applicationCache.onupdateready = OfflineTest.priv(manifestUpdated); 1.335 + applicationCache.oncached = OfflineTest.priv(manifestCached); 1.336 +} 1.337 + 1.338 +</script> 1.339 + 1.340 +</head> 1.341 + 1.342 +<body> 1.343 + <iframe name="updatingFrame" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs"></iframe> 1.344 + <iframe name="fallbackFrame1" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html"></iframe> 1.345 + <iframe name="fallbackFrame2" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html"></iframe> 1.346 + <iframe name="whitelistFrame" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html"></iframe> 1.347 +</body> 1.348 +</html>