gecko/dom/tests/mochitest/ajax/offline/test_fallback.html

136 lines
4.7 KiB
HTML
Raw Normal View History

<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/fallback.cacheManifest">
<head>
<title>Fallback entry 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">
/**
* This tests that we fall back to the correct fallback entries when loading
* from fallback namespaces listed in the manifest. The test is performed twice
* to make sure that no cache entries are created for the nonexistent items."
* That would lead to a failure to fallback, as there would always be an entry
* in the application cache.
*/
var gManifestUpdated = false;
var gStep = 1;
var gChildLoad = false;
var gTopWindow = null;
var gCompleteTimeout = null;
function manifestUpdated()
{
gManifestUpdated = true;
fallbackFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html";
// Invokes load of fallback.html
}
function onFallbackLoad(fallbackIdentification)
{
switch (gStep)
{
case 001:
OfflineTest.ok(!gChildLoad, "offline child not load before cache update");
gChildLoad = true;
// no break
case 101:
OfflineTest.is(fallbackIdentification, 1, "fallback for namespace1/ in step " + gStep);
fallbackFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub-non-existing.html";
// Invokes load of fallback.html
break;
case 002:
case 102:
OfflineTest.is(fallbackIdentification, 1, "fallback for namespace1/, sub namespace in name of the frame in step " + gStep);
fallbackFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html";
// Invokes load of fallback2.html
break;
case 003:
case 103:
OfflineTest.is(fallbackIdentification, 2, "fallback for namespace1/sub/ in step " + gStep);
fallbackFrame.location = "HTTP://LOCALHOST:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html";
// Invokes load of fallback2.html
break;
case 004:
case 104:
OfflineTest.is(fallbackIdentification, 2, "fallback for namespace1/sub/ in step " + gStep);
// Try opening a non-existing page as a top level document. It must
// fall to fallbackTop.html that identifies it self as '100'.
gCompleteTimeout = window.setTimeout(function() {
OfflineTest.ok(false, "Fallback page displayed for top level document");
finalize();
}, 3000);
gTopWindow = window.open("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace2/non-existing.html");
// Invokes load of fallbackTop.html
break;
case 005:
// Try all over again. This checks there are no entries for non-existing
// pages created/leaked. That would prevent fallback load.
gStep = 100;
fallbackFrame.location = "http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html";
// Invokes load of fallback1.html, again, from the start
// no break
case 105:
OfflineTest.is(fallbackIdentification, 100, "fallback for namespace2/, invoked by a top level document " + gStep);
gTopWindow.close();
gTopWindow = null;
window.clearTimeout(gCompleteTimeout);
gCompleteTimeout = null;
break;
}
if (gStep == 105) {
finalize();
}
++gStep;
}
function finalize()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub-non-existing.html", false);
OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html", false);
OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html", false);
OfflineTest.checkCache("http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace2/non-existing.html", false);
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="fallbackFrame" src="http://localhost:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html"></iframe>
</body>
</html>