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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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>
     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" />
     9 <script class="testbody" type="text/javascript">
    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  */
    20 const NAMESPACE_BYPASS = SpecialPowers.Ci.nsIApplicationCacheNamespace.NAMESPACE_BYPASS;
    21 const NAMESPACE_FALLBACK = SpecialPowers.Ci.nsIApplicationCacheNamespace.NAMESPACE_FALLBACK;
    23 var gStep = 0;
    24 var gGotFrameVersion = 0;
    25 var gCallOnUpdatingFrameLoad = null;
    27 // Helpers
    29 function reloadLocations(frames)
    30 {
    31   for (frame in frames)
    32     frames[frame].location.reload();
    33 }
    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 }
    52 function checkFallbackAndWhitelisting(key, fallback, onwhitelist)
    53 {
    54   // Get matching namespace for the key
    55   var matchingNamespace = OfflineTest.getActiveCache()
    56     .getMatchingNamespace(key);
    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   }
    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;
    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);
    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);
    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 }
    88 // Events
    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 }
   101 function whitelistOnLoad(version)
   102 {
   103   // Whitelisting is not tested by this test...
   104 }
   107 // Start of the test function chain
   108 // ================================
   110 function manifestCached()
   111 {
   112   OfflineTest.is(gStep, 0, "Got manifestCached in step 0, gStep=" + gStep);
   114   reloadLocations([fallbackFrame1, fallbackFrame2]);
   115   waitForLocations(
   116     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html"],
   117     fallbackLoaded
   118   );
   119 }
   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 }
   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 }
   135 function implicitLoaded(aWindow, errorOccured)
   136 {
   137   aWindow.close();
   139   OfflineTest.ok(!errorOccured, "No error on new implicit page manifest update");
   141   OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html",
   142       implicitCached);
   143 }
   145 function implicitCached()
   146 {
   147   // Checking first version of the manifest + another implict page caching
   149   // Whitelist entries
   150   checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true);
   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);
   158   // Cache object status
   159   OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.IDLE,
   160       "we have associated application cache (1)");
   162   OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1");
   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],
   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],
   173     // Whitelist entries
   174     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false],
   176     // Implicit entries
   177     ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true],
   179     // Dynamic entries
   180     ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true]
   181   ];
   182   OfflineTest.checkCacheEntries(
   183     entries,
   184     function() {
   185       ++gStep;
   187       OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "second");
   189       applicationCache.update();
   190       // Invokes manifestUpdated()
   191     });
   192 }
   194 function manifestUpdated()
   195 {
   196   OfflineTest.ok(gStep == 1 || gStep == 2, "Got manifestUpdated in step 1 or 2, gStep=" + gStep);
   198   switch (gStep)
   199   {
   200   case 1:
   201     // Processing second version of the manifest.
   203     // Whitelist entries
   204     checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", false);
   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);
   212     // Cache object status
   213     OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY,
   214         "we have associated application cache and update is pending (2)");
   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],
   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],
   225       // Whitelist entries
   226       ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false],
   228       // Implicit entries
   229       ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true],
   231       // Dynamic entries
   232       ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true]
   233     ];
   234     OfflineTest.checkCacheEntries(
   235       entries,
   236       function() {
   237         ++gStep;
   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");
   242         gGotFrameVersion = 0;
   243         updatingFrame.location.reload();
   244         // Since the frame is offline-cached, reload of it invokes update
   245       });
   247     break;
   249   case 2:
   250     // Processing third version of the manifest.
   252     // Whitelist entries
   253     checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true);
   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);
   261     // Cache object status
   262     OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY,
   263         "we have associated application cache and update is pending (3)");
   265     OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1 because cache was not swapped");
   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],
   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],
   276       // Whitelist entries
   277       ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false],
   279       // Implicit entries
   280       ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true],
   282       // Dynamic entries
   283       ["http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true]
   284     ];
   285     OfflineTest.checkCacheEntries(
   286       entries,
   287       function() {
   288         ++gStep;
   290         applicationCache.onnoupdate = OfflineTest.priv(manifestNoUpdate);
   291         applicationCache.update();
   292         // Invokes manifestNoUpdate()
   293       });
   295     break;
   296   }
   297 }
   299 function manifestNoUpdate()
   300 {
   301   applicationCache.onnoupdate = null;
   303   OfflineTest.ok(gStep == 3, "Got manifestNoUpdate in step 3, gStep=" + gStep);
   304   ++gStep;
   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)");
   312   gGotFrameVersion = 0;
   313   gCallOnUpdatingFrameLoad = checkNewVersionOfIFrame;
   314   updatingFrame.location.reload();
   315 }
   317 function checkNewVersionOfIFrame()
   318 {
   319   OfflineTest.is(gGotFrameVersion, 2, "IFrame version 2");
   321   OfflineTest.teardownAndFinish();
   322 }
   324 // End of the test function chain
   325 // ==============================
   327 SimpleTest.waitForExplicitFinish();
   329 if (OfflineTest.setup()) {
   330   applicationCache.onerror = OfflineTest.failEvent;
   331   applicationCache.onupdateready = OfflineTest.priv(manifestUpdated);
   332   applicationCache.oncached = OfflineTest.priv(manifestCached);
   333 }
   335 </script>
   337 </head>
   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>

mercurial