dom/tests/mochitest/ajax/offline/test_updatingManifest.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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

mercurial