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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial