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>Cache update 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 test loads manifest and checks presence of all items.
|
|
|
|
* Then it modifies the manifest and updates the cache again.
|
|
|
|
* Then test presence of items according to the spec and also
|
|
|
|
* if the cache associated with the document is still the old
|
|
|
|
* one. Then again modifies the manifest, checks items and finally
|
|
|
|
* swaps cache for this document, reloads and checks document state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const NAMESPACE_BYPASS = Components.interfaces.nsIApplicationCacheNamespace.NAMESPACE_BYPASS;
|
|
|
|
const NAMESPACE_FALLBACK = Components.interfaces.nsIApplicationCacheNamespace.NAMESPACE_FALLBACK;
|
|
|
|
|
|
|
|
var gStep = 0;
|
|
|
|
var gGotFrameVersion = 0;
|
|
|
|
var gCallOnUpdatingFrameLoad = null;
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
|
|
|
|
function reloadLocations(frames)
|
|
|
|
{
|
|
|
|
for (frame in frames)
|
|
|
|
frames[frame].location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function waitForLocations(frames, doneFunc)
|
|
|
|
{
|
|
|
|
frame = frames.shift();
|
|
|
|
if (frame)
|
|
|
|
// toString() might cause problems when this test will
|
|
|
|
// completely be changed to test IDN behavior.
|
|
|
|
OfflineTest.waitForAdd(frame.location.toString(), function()
|
|
|
|
{
|
|
|
|
waitForLocations(frames, doneFunc);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
doneFunc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkFallbackAndWhitelisting(key, fallback, onwhitelist)
|
|
|
|
{
|
|
|
|
// Get matching namespace for the key
|
|
|
|
var matchingNamespace = OfflineTest.getActiveCache()
|
|
|
|
.getMatchingNamespace(key);
|
|
|
|
|
|
|
|
// If we are not expecting the key is to be on white list or
|
|
|
|
// has been assigned a fallback check there is not any matching
|
|
|
|
// namespace found and exit
|
|
|
|
if (!fallback && !onwhitelist) {
|
|
|
|
is(matchingNamespace, null, "No namespace found for "+key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We expect this entry is on the white list or has a fallback
|
|
|
|
// entry assigned, check we found a matching namespace
|
|
|
|
ok(matchingNamespace, "We have a namespace for "+key);
|
|
|
|
if (!matchingNamespace)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We expect the key be assigned a fallback URI, check the namespace
|
|
|
|
// type is of fallback type
|
|
|
|
OfflineTest.is(!!(matchingNamespace.itemType & NAMESPACE_FALLBACK), !!fallback,
|
|
|
|
(fallback ? "Namespace type is fallback for " : "Namespace type is not fallback for ")+key);
|
|
|
|
|
|
|
|
// We expect the key be assigned a fallback URI, check the URI is
|
|
|
|
// equal to expected one
|
|
|
|
OfflineTest.is(matchingNamespace.data, fallback,
|
|
|
|
(fallback ? "Expected correct fallback for " : "No fallback for ")+key);
|
|
|
|
|
|
|
|
// We expect the key be on the white list, check the namespace type
|
|
|
|
// is of bypass type
|
|
|
|
OfflineTest.is(!!(matchingNamespace.itemType & NAMESPACE_BYPASS), onwhitelist,
|
|
|
|
(onwhitelist ? "On white list " : "Not on white list ")+key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Events
|
|
|
|
|
|
|
|
function frameLoad(version)
|
|
|
|
{
|
|
|
|
gGotFrameVersion = version;
|
|
|
|
if (gCallOnUpdatingFrameLoad)
|
|
|
|
{
|
|
|
|
var call = gCallOnUpdatingFrameLoad;
|
|
|
|
gCallOnUpdatingFrameLoad = null;
|
|
|
|
OfflineTest.priv(call)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function whitelistOnLoad(version)
|
|
|
|
{
|
|
|
|
// Whitelisting is not tested by this test...
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Start of the test function chain
|
|
|
|
// ================================
|
|
|
|
|
|
|
|
function manifestCached()
|
|
|
|
{
|
|
|
|
OfflineTest.is(gStep, 0);
|
|
|
|
|
|
|
|
reloadLocations([fallbackFrame1, fallbackFrame2]);
|
|
|
|
waitForLocations([fallbackFrame1, fallbackFrame2],
|
|
|
|
fallbackLoaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fallbackLoaded()
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js");
|
|
|
|
OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
|
2008-11-05 16:01:06 -08:00
|
|
|
dynamicLoaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dynamicLoaded()
|
|
|
|
{
|
2010-03-12 13:53:36 -08:00
|
|
|
window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html");
|
2008-11-05 16:01:06 -08:00
|
|
|
// window.onload invokes implicitLoaded()
|
|
|
|
}
|
|
|
|
|
|
|
|
function implicitLoaded(aWindow, errorOccured)
|
|
|
|
{
|
|
|
|
aWindow.close();
|
|
|
|
|
|
|
|
OfflineTest.ok(!errorOccured, "No error on new implicit page manifest update");
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.waitForAdd("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html",
|
2008-11-05 16:01:06 -08:00
|
|
|
implicitCached);
|
|
|
|
}
|
|
|
|
|
|
|
|
function implicitCached()
|
|
|
|
{
|
|
|
|
// Checking first version of the manifest + another implict page caching
|
|
|
|
|
|
|
|
// Explicit entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false);
|
|
|
|
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-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Fallback entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", true);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Whitelist entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false);
|
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Implicit entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Dynamic entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Fallback URI selection check
|
2010-03-12 13:53:36 -08:00
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html",
|
|
|
|
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false);
|
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html",
|
|
|
|
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Cache object status
|
|
|
|
OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.IDLE,
|
|
|
|
"we have associated application cache (1)");
|
|
|
|
|
|
|
|
OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1");
|
|
|
|
|
|
|
|
++gStep;
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "second");
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
applicationCache.update();
|
|
|
|
// Invokes manifestUpdated()
|
|
|
|
}
|
|
|
|
|
|
|
|
function manifestUpdated()
|
|
|
|
{
|
|
|
|
OfflineTest.ok(gStep == 1 || gStep == 2);
|
|
|
|
|
|
|
|
switch (gStep)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
// Processing second version of the manifest.
|
|
|
|
|
|
|
|
// Explicit entries
|
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-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Fallback entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", true);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Whitelist entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false);
|
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", false);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Implicit entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Dynamic entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Fallback URI selection check
|
2010-03-12 13:53:36 -08:00
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html",
|
|
|
|
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false);
|
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html",
|
|
|
|
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Cache object status
|
|
|
|
OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.UPDATEREADY,
|
|
|
|
"we have associated application cache and update is pending (2)");
|
|
|
|
|
|
|
|
++gStep;
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs", "third");
|
|
|
|
OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", "second");
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
gGotFrameVersion = 0;
|
|
|
|
gCallOnUpdatingFrameLoad = function() {applicationCache.update();};
|
|
|
|
updatingFrame.location.reload();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// Processing third version of the manifest.
|
|
|
|
|
|
|
|
// Explicit entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false);
|
|
|
|
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-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Fallback entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html", false);
|
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Whitelist entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", false);
|
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html", "", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Implicit entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Dynamic entries
|
2010-03-12 13:53:36 -08:00
|
|
|
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", true);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Fallback URI selection check
|
2010-03-12 13:53:36 -08:00
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html",
|
2008-11-05 16:01:06 -08:00
|
|
|
"", false);
|
2010-03-12 13:53:36 -08:00
|
|
|
checkFallbackAndWhitelisting("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html",
|
|
|
|
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback2.html", false);
|
2008-11-05 16:01:06 -08:00
|
|
|
|
|
|
|
// Cache object status
|
|
|
|
OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.UPDATEREADY,
|
|
|
|
"we have associated application cache and update is pending (3)");
|
|
|
|
|
|
|
|
OfflineTest.is(gGotFrameVersion, 1, "IFrame version 1 because cache was not swapped");
|
|
|
|
|
|
|
|
++gStep;
|
|
|
|
|
|
|
|
applicationCache.onnoupdate = OfflineTest.priv(manifestNoUpdate);
|
|
|
|
applicationCache.update();
|
|
|
|
// Invokes manifestNoUpdate()
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function manifestNoUpdate()
|
|
|
|
{
|
2009-03-04 13:37:29 -08:00
|
|
|
applicationCache.onnoupdate = null;
|
|
|
|
|
2008-11-05 16:01:06 -08:00
|
|
|
OfflineTest.ok(gStep == 3);
|
|
|
|
|
|
|
|
OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.UPDATEREADY,
|
|
|
|
"we have associated application cache and update is pending (4)");
|
|
|
|
applicationCache.swapCache();
|
|
|
|
OfflineTest.is(applicationCache.status, Components.interfaces.nsIDOMOfflineResourceList.IDLE,
|
|
|
|
"we have associated application cache (4)");
|
|
|
|
|
|
|
|
gGotFrameVersion = 0;
|
|
|
|
gCallOnUpdatingFrameLoad = checkNewVersionOfIFrame;
|
|
|
|
updatingFrame.location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkNewVersionOfIFrame()
|
|
|
|
{
|
|
|
|
OfflineTest.is(gGotFrameVersion, 2, "IFrame version 2");
|
|
|
|
|
|
|
|
OfflineTest.teardown();
|
|
|
|
OfflineTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of the test function chain
|
|
|
|
// ==============================
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
if (OfflineTest.setup()) {
|
|
|
|
applicationCache.onerror = OfflineTest.failEvent;
|
|
|
|
applicationCache.onupdateready = OfflineTest.priv(manifestUpdated);
|
|
|
|
applicationCache.oncached = OfflineTest.priv(manifestCached);
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2010-03-12 13:53:36 -08:00
|
|
|
<iframe name="updatingFrame" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs"></iframe>
|
|
|
|
<iframe name="fallbackFrame1" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/opp.html"></iframe>
|
|
|
|
<iframe name="fallbackFrame2" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/opp.html"></iframe>
|
|
|
|
<iframe name="whitelistFrame" src="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/onwhitelist.html"></iframe>
|
2008-11-05 16:01:06 -08:00
|
|
|
</body>
|
|
|
|
</html>
|