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/simpleManifest.cacheManifest">
|
2008-01-16 13:54:33 -08:00
|
|
|
<head>
|
|
|
|
<title>simple manifest 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>
|
2008-11-05 16:01:06 -08:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
2008-01-16 13:54:33 -08:00
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var gGotChecking = false;
|
|
|
|
var gGotDownloading = false;
|
|
|
|
|
2009-01-25 22:50:44 -08:00
|
|
|
ok(applicationCache.mozItems.length == 0,
|
|
|
|
"applicationCache.mozItems should be available and empty before associating with a cache.");
|
2008-11-04 10:59:13 -08:00
|
|
|
|
2008-01-16 13:54:33 -08:00
|
|
|
function addFinished()
|
|
|
|
{
|
|
|
|
// Check that the entry was added successfully
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
|
2008-01-16 13:54:33 -08:00
|
|
|
true);
|
|
|
|
|
2009-01-25 22:50:44 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozLength == 1, "applicationCache should have one dynamic entry (deprecated API)");
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozItem(0) == "http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
|
2008-11-04 10:59:13 -08:00
|
|
|
"applicationCache's dynamic entry should be the one we expect (deprecated API)");
|
|
|
|
|
2009-01-25 22:50:44 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozItems.length == 1, "applicationCache should have one dynamic entry");
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozItems[0] == "http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
|
2008-01-16 13:54:33 -08:00
|
|
|
"applicationCache's dynamic entry should be the one we expect");
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozHasItem("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"),
|
2009-01-25 22:50:44 -08:00
|
|
|
"applicationCache.mozHasItem() should see the dynamic entry");
|
2008-11-04 10:59:13 -08:00
|
|
|
|
2008-01-16 13:54:33 -08:00
|
|
|
// Now test that removes work
|
2010-03-12 13:53:36 -08:00
|
|
|
applicationCache.mozRemove("http://mochi.test:8888/tests/SimpleTest/EventUtils.js");
|
2008-01-16 13:54:33 -08:00
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
|
2008-01-16 13:54:33 -08:00
|
|
|
false);
|
2009-01-25 22:50:44 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozLength == 0,
|
2008-11-04 10:59:13 -08:00
|
|
|
"applicationCache should have no dynamic entries (deprecated API)");
|
2009-01-25 22:50:44 -08:00
|
|
|
OfflineTest.ok(applicationCache.mozItems.length == 0,
|
2008-01-16 13:54:33 -08:00
|
|
|
"applicationCache should have no dynamic entries");
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.ok(!applicationCache.mozHasItem("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"),
|
2009-01-25 22:50:44 -08:00
|
|
|
"applicationCache.mozHasItem() should not see the removed dynamic entry");
|
2008-01-16 13:54:33 -08:00
|
|
|
|
|
|
|
// We're done
|
|
|
|
|
|
|
|
OfflineTest.teardown();
|
|
|
|
|
|
|
|
OfflineTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function manifestUpdated()
|
|
|
|
{
|
|
|
|
OfflineTest.ok(gGotChecking, "Should get a checking event");
|
|
|
|
OfflineTest.ok(gGotDownloading, "Should get a downloading event");
|
|
|
|
|
|
|
|
// The manifest itself should be in the cache
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest", true);
|
2008-01-16 13:54:33 -08:00
|
|
|
|
|
|
|
// The document that requested the manifest should be in the cache
|
|
|
|
OfflineTest.checkCache(window.location.href, true);
|
|
|
|
|
|
|
|
// The entries from the manifest should be in the cache
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", true);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/MochiKit/packed.js", true);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true);
|
2008-01-16 13:54:33 -08:00
|
|
|
|
|
|
|
// The bad entries from the manifest should not be in the cache
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("https://mochi.test:8888/MochiKit/packed.js", false);
|
2008-01-16 13:54:33 -08:00
|
|
|
OfflineTest.checkCache("bad:/uri/invalid", false);
|
|
|
|
|
2008-11-04 02:20:27 -08:00
|
|
|
OfflineTest.is(applicationCache.status, 1, "Cache status should be 1 (CACHED)");
|
|
|
|
|
|
|
|
try {
|
|
|
|
applicationCache.swapCache();
|
|
|
|
OfflineTest.ok(false, "application.swapCache() should fail after initial update.");
|
|
|
|
} catch(ex) {
|
|
|
|
OfflineTest.ok(true, "application.swapCache() should fail after initial update.");
|
|
|
|
}
|
2008-01-16 13:54:33 -08:00
|
|
|
|
2008-08-26 16:09:02 -07:00
|
|
|
// XXX: make sure that the previous version went away after the swapCache().
|
2008-08-19 22:53:20 -07:00
|
|
|
|
2008-08-26 16:09:02 -07:00
|
|
|
// Now add a file using the applicationCache API
|
2010-03-12 13:53:36 -08:00
|
|
|
applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js");
|
2008-08-24 23:11:31 -07:00
|
|
|
|
2008-08-26 16:09:02 -07:00
|
|
|
// Wait for the add() to be downloaded
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
|
2008-08-26 16:09:02 -07:00
|
|
|
OfflineTest.priv(addFinished));
|
2008-01-16 13:54:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OfflineTest.setup()) {
|
2008-05-08 17:10:49 -07:00
|
|
|
OfflineTest.ok(applicationCache instanceof EventTarget,
|
|
|
|
"applicationCache should be an event target");
|
|
|
|
|
2008-01-16 13:54:33 -08:00
|
|
|
applicationCache.onerror = OfflineTest.failEvent;
|
|
|
|
|
2008-05-08 17:10:49 -07:00
|
|
|
applicationCache.addEventListener("checking", function() {
|
2009-03-04 13:37:29 -08:00
|
|
|
// We should get the "checking" event during an initial update,
|
|
|
|
// but until we are associated it will not affect applicationCache.status
|
|
|
|
OfflineTest.is(applicationCache.status, applicationCache.UNCACHED,
|
|
|
|
"CHECKING state during initial update");
|
2008-05-08 17:09:26 -07:00
|
|
|
gGotChecking = true;
|
2008-05-08 17:10:49 -07:00
|
|
|
}, true);
|
2008-05-08 17:09:26 -07:00
|
|
|
applicationCache.ondownloading = function() {
|
2009-03-04 13:37:29 -08:00
|
|
|
// We should get the "downloading" event during an initial update,
|
|
|
|
// but until we are associated it will not affect applicationCache.status
|
|
|
|
OfflineTest.is(applicationCache.status, applicationCache.UNCACHED,
|
|
|
|
"DOWNLOADING state during initial update")
|
2008-05-08 17:09:26 -07:00
|
|
|
gGotDownloading = true; };
|
2008-01-16 13:54:33 -08:00
|
|
|
applicationCache.oncached = OfflineTest.priv(manifestUpdated);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|