2010-03-12 13:53:36 -08:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs">
|
2008-11-05 16:01:06 -08:00
|
|
|
<head>
|
|
|
|
<title>Offline mode test</title>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The test loads a manifest and cache it.
|
|
|
|
* Then tests if all works in online mode
|
|
|
|
* as expected. Then switches firefox to offline
|
|
|
|
* mode and tries the page load still works as
|
|
|
|
* expected, i.e. all items from the cache load.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var gImplicitWindow = null;
|
|
|
|
var gCompleteTimeout = null;
|
|
|
|
var gGotExplicitVersion = 0;
|
|
|
|
var gGotImplicitVersion = 0;
|
|
|
|
var gGotDynamicVersion = 0;
|
|
|
|
var gGotOnError = false;
|
|
|
|
|
|
|
|
// test
|
|
|
|
|
|
|
|
function manifestUpdated()
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
applicationCache.mozAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html");
|
|
|
|
OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html", dynamicAdded);
|
2008-11-05 16:01:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function dynamicAdded()
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html";
|
2008-11-05 16:01:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called by the dynamically added iframe on load
|
|
|
|
function notwhitelistOnLoad()
|
|
|
|
{
|
|
|
|
gGotDynamicVersion = 1;
|
2010-03-12 13:53:36 -08:00
|
|
|
aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs";
|
2008-11-05 16:01:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called by the explicit iframe on load
|
|
|
|
function frameLoad(version)
|
|
|
|
{
|
|
|
|
gGotExplicitVersion = version;
|
2010-03-12 13:53:36 -08:00
|
|
|
gImplicitWindow = window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html");
|
2008-11-05 16:01:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called by the implicit window on load
|
|
|
|
function implicitLoaded(aWindow, errorOccured)
|
|
|
|
{
|
|
|
|
aWindow.close();
|
|
|
|
|
|
|
|
gGotImplicitVersion = 1;
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", implicitAdded);
|
2008-11-05 16:01:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function implicitAdded()
|
|
|
|
{
|
|
|
|
OfflineTest.priv(finalize)();
|
|
|
|
}
|
|
|
|
|
|
|
|
function finalize()
|
|
|
|
{
|
|
|
|
window.clearTimeout(gCompleteTimeout);
|
|
|
|
|
|
|
|
var ioserv = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService);
|
|
|
|
|
|
|
|
if (!ioserv.offline)
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html", true);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", true);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
OfflineTest.is(gGotExplicitVersion, 1, "Explicit entry loaded");
|
|
|
|
OfflineTest.is(gGotImplicitVersion, 1, "Implicit entry loaded");
|
|
|
|
OfflineTest.is(gGotDynamicVersion, 1, "Dynamic entry loaded");
|
|
|
|
|
|
|
|
gGotExplicitVersion = 0;
|
|
|
|
gGotImplicitVersion = 0;
|
|
|
|
gGotDynamicVersion = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Delete HTTP cache to ensure we are going from offline cache
|
|
|
|
var sessionServ = Cc["@mozilla.org/network/cache-service;1"]
|
|
|
|
.getService(Ci.nsICacheService);
|
|
|
|
cacheSession = sessionServ.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, Ci.nsICache.STREAM_BASED);
|
|
|
|
function doomHTTPCacheEntry(entryKey) {
|
|
|
|
entry = cacheSession.openCacheEntry(entryKey, Ci.nsICache.ACCESS_WRITE, false)
|
|
|
|
entry.doom();
|
|
|
|
}
|
2010-03-12 13:53:36 -08:00
|
|
|
doomHTTPCacheEntry("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html");
|
|
|
|
doomHTTPCacheEntry("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs");
|
|
|
|
doomHTTPCacheEntry("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html");
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
|
|
|
|
ioserv.offline = true;
|
|
|
|
|
|
|
|
gCompleteTimeout = window.setTimeout(OfflineTest.priv(finalize), 10000);
|
|
|
|
|
|
|
|
// remove error handling. in offline mode
|
|
|
|
// is correct to get error message
|
|
|
|
applicationCache.onerror = function() {gGotOnError = true;}
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
aFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/notonwhitelist.html";
|
2008-11-05 16:01:06 -08:00
|
|
|
// Starts the chain all over again but in offline mode.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gImplicitWindow.close();
|
|
|
|
|
|
|
|
ioserv.offline = false;
|
|
|
|
|
|
|
|
OfflineTest.is(gGotExplicitVersion, 1, "Explicit entry loaded");
|
2008-11-21 11:02:25 -08:00
|
|
|
OfflineTest.is(gGotImplicitVersion, 1, "Bug 461325 - Implicit entry loaded");
|
2008-11-05 16:01:06 -08:00
|
|
|
OfflineTest.is(gGotDynamicVersion, 1, "Dynamic entry loaded");
|
2008-11-05 16:01:07 -08:00
|
|
|
OfflineTest.ok(gGotOnError, "Got onerror event invoked by implicit page load in offline mode");
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
OfflineTest.teardown();
|
|
|
|
OfflineTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
if (OfflineTest.setup()) {
|
|
|
|
applicationCache.onerror = OfflineTest.failEvent;
|
|
|
|
applicationCache.onupdateready = OfflineTest.failEvent;
|
|
|
|
applicationCache.oncached = OfflineTest.priv(manifestUpdated);
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<iframe name="aFrame" src=""></iframe>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|