dom/tests/mochitest/ajax/offline/test_offlineMode.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.

     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>
     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  * 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  */
    19 var gImplicitWindow = null;
    20 var gCompleteTimeout = null;
    21 var gGotExplicitVersion = 0;
    22 var gGotImplicitVersion = 0;
    23 var gGotDynamicVersion = 0;
    24 var gGotOnError = false;
    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 }
    33 // test
    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 }
    41 function dynamicAdded()
    42 {
    43   aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html";
    44 }
    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 }
    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 }
    60 // Called by the implicit window on load
    61 function implicitLoaded(aWindow, errorOccured)
    62 {
    63   aWindow.close();
    65   gGotImplicitVersion = 1;
    66   OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", implicitAdded);
    67 }
    69 function implicitAdded()
    70 {
    71   OfflineTest.priv(finalize)();
    72 }
    74 function finalize()
    75 {
    76   window.clearTimeout(gCompleteTimeout);
    78   var ioserv = Cc["@mozilla.org/network/io-service;1"]
    79       .getService(Ci.nsIIOService);
    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");
    87     gGotExplicitVersion = 0;
    88     gGotImplicitVersion = 0;
    89     gGotDynamicVersion = 0;
    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();
   102     ioserv.offline = false;
   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");
   109     OfflineTest.teardownAndFinish();
   110   }
   111 }
   113 function goOffline()
   114 {
   115   var listener = {
   116     onCacheEntryDoomed: function (status) {
   117       OfflineTest.priv(goOfflineContinue)();
   118     }
   119   };
   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 }
   130 function goOfflineContinue()
   131 {
   132   var ioserv = Cc["@mozilla.org/network/io-service;1"]
   133       .getService(Ci.nsIIOService);
   135   ioserv.offline = true;
   137   gCompleteTimeout = window.setTimeout(OfflineTest.priv(finalize), 10000);
   139   // remove error handling. in offline mode
   140   // is correct to get error message
   141   applicationCache.onerror = function() {gGotOnError = true;}
   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 }
   147 SimpleTest.waitForExplicitFinish();
   149 if (OfflineTest.setup()) {
   150   applicationCache.onerror = OfflineTest.failEvent;
   151   applicationCache.onupdateready = OfflineTest.failEvent;
   152   applicationCache.oncached = OfflineTest.priv(manifestUpdated);
   153 }
   155 </script>
   157 </head>
   159 <body>
   161 <iframe name="aFrame" src=""></iframe>
   163 </body>
   164 </html>

mercurial