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/changingManifest.sjs">
|
2008-04-08 22:22:32 -07:00
|
|
|
<head>
|
|
|
|
<title>changing 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-04-08 22:22:32 -07:00
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var gGotChecking = false;
|
|
|
|
var gGotDownloading = false;
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
var g1SecUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Sec.sjs";
|
|
|
|
var g1HourUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Hour.sjs";
|
2008-04-08 22:22:32 -07:00
|
|
|
|
|
|
|
var gCacheContents = null;
|
|
|
|
|
2008-11-05 16:01:07 -08:00
|
|
|
function finish()
|
|
|
|
{
|
|
|
|
OfflineTest.teardown();
|
|
|
|
OfflineTest.finish();
|
|
|
|
}
|
|
|
|
|
2008-04-08 22:22:32 -07:00
|
|
|
function manifestUpdatedAgain()
|
|
|
|
{
|
|
|
|
OfflineTest.ok(gGotChecking, "Should get a checking event on the second update");
|
|
|
|
OfflineTest.ok(gGotDownloading, "Should get a downloading event on the second update");
|
|
|
|
|
2009-02-09 22:40:40 -08:00
|
|
|
// The second manifest has no NETWORK entry, but we are still
|
|
|
|
// associated with the first version of the manifest, so we should
|
|
|
|
// be able to access the whitelisted entry.
|
|
|
|
try {
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("GET", "onwhitelist.html", false);
|
|
|
|
xhr.send();
|
|
|
|
OfflineTest.ok(true, "Fetched from the initial cache's whitelist.");
|
|
|
|
} catch (e) {
|
|
|
|
OfflineTest.ok(false, "Failed to fetch from the initial cache's whitelist.");
|
|
|
|
}
|
|
|
|
|
2008-04-08 22:22:32 -07:00
|
|
|
// Get the initial contents of the first two files.
|
|
|
|
fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
|
|
|
|
fetcher.fetch(function(contents) {
|
|
|
|
// Make sure the contents of the 1-second-expiration file have changed,
|
|
|
|
// but that the 1-hour-expiration has not.
|
|
|
|
OfflineTest.isnot(gCacheContents[g1SecUrl], contents[g1SecUrl], "1-second expiration should have changed");
|
|
|
|
OfflineTest.is(gCacheContents[g1HourUrl], contents[g1HourUrl], "1-hour expiration should not have changed");
|
|
|
|
|
2008-11-05 16:01:07 -08:00
|
|
|
finish();
|
2008-04-08 22:22:32 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function failAndFinish(e) {
|
|
|
|
OfflineTest.ok(false, "Unexpected event: " + e.type);
|
2008-11-05 16:01:07 -08:00
|
|
|
finish();
|
2008-04-08 22:22:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function manifestUpdated()
|
|
|
|
{
|
|
|
|
OfflineTest.ok(gGotChecking, "Should get a checking event");
|
|
|
|
OfflineTest.ok(gGotDownloading, "Should get a downloading event");
|
|
|
|
|
2008-11-05 16:01:07 -08:00
|
|
|
// Replace this manifest with a new one.
|
2009-02-18 05:31:30 -08:00
|
|
|
OfflineTest.setSJSState("changingManifest.sjs", "2");
|
2008-11-05 16:01:07 -08:00
|
|
|
|
2008-04-08 22:22:32 -07:00
|
|
|
// Get the initial contents of the first two files.
|
|
|
|
fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
|
|
|
|
fetcher.fetch(function(contents) {
|
|
|
|
gCacheContents = contents;
|
|
|
|
|
2008-11-05 16:01:07 -08:00
|
|
|
// Now make sure applicationCache.update() does what we expect.
|
2009-03-04 13:37:29 -08:00
|
|
|
applicationCache.onchecking = function() {
|
|
|
|
OfflineTest.is(applicationCache.status, applicationCache.CHECKING,
|
|
|
|
"CHECKING state during update");
|
|
|
|
gGotChecking = true;
|
|
|
|
};
|
|
|
|
applicationCache.ondownloading = function() {
|
|
|
|
OfflineTest.is(applicationCache.status, applicationCache.DOWNLOADING,
|
|
|
|
"DOWNLOADING state during update");
|
|
|
|
gGotDownloading = true;
|
|
|
|
};
|
|
|
|
|
2008-08-26 16:09:02 -07:00
|
|
|
applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
|
2008-04-08 22:22:32 -07:00
|
|
|
applicationCache.onnoupdate = failAndFinish;
|
2008-08-26 16:09:02 -07:00
|
|
|
applicationCache.oncached = failAndFinish;
|
2008-04-08 22:22:32 -07:00
|
|
|
|
|
|
|
gGotChecking = false;
|
|
|
|
gGotDownloading = false;
|
|
|
|
|
|
|
|
// The changing versions give out a new version each second,
|
|
|
|
// make sure it has time to grab a new version, and for the
|
|
|
|
// 1-second cache timeout to pass.
|
|
|
|
window.setTimeout("applicationCache.update()", 5000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OfflineTest.setup()) {
|
|
|
|
applicationCache.onerror = failAndFinish;
|
|
|
|
applicationCache.onnoupdate = failAndFinish;
|
|
|
|
|
|
|
|
applicationCache.onchecking = function() { gGotChecking = true; };
|
|
|
|
applicationCache.ondownloading = function() { gGotDownloading = true; };
|
|
|
|
applicationCache.oncached = OfflineTest.priv(manifestUpdated);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|