blob: d26af41762075ffc3304c958bc8268789803e036 [file] [log] [blame]
<html xmlns="http://www.w3.org/1999/xhtml"
manifest="/resources/network-simulator.php?test=appcache-non-html&amp;path=/appcache/resources/non-html.manifest">
<head><title/></head>
<body>
<p>Test that non-HTML main resources work with application cache correctly.</p>
<p>Should say SUCCESS:</p>
<div id="result"></div>
<script type="text/javascript">
if (window.testRunner) {
testRunner.dumpAsText()
testRunner.waitUntilDone();
}
function log(message)
{
document.getElementById("result").innerHTML += message + "&lt;br/>";
}
function setNetworkEnabled(state)
{
var req = new XMLHttpRequest;
req.open("GET", "/resources/network-simulator.php?test=appcache-non-html&amp;command=" + (state ? "connect" : "disconnect"), false);
req.send("");
}
function createFrame()
{
var ifr = document.createElement("iframe");
ifr.setAttribute("src", "/resources/network-simulator.php?test=appcache-non-html&amp;path=/appcache/resources/abe.png");
ifr.onload = frameCreated;
document.body.appendChild(ifr);
}
function cached()
{
var hadError = false;
applicationCache.removeEventListener('noupdate', cached, false);
applicationCache.removeEventListener('cached', cached, false);
setNetworkEnabled(false);
// Load a resource that does not exist in the cache.
try {
var req = new XMLHttpRequest();
req.open("GET", "/resources/network-simulator.php?test=appcache-non-html&amp;path=/appcache/resources/not-in-cache.txt", false);
req.send();
} catch (e) {
if (e.code == DOMException.NETWORK_ERR)
hadError = true;
}
if (!hadError) {
document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception"
return;
}
// Load a resource that exists in the cache.
try {
var req = new XMLHttpRequest();
req.open("GET", "/resources/network-simulator.php?test=appcache-non-html&amp;path=/appcache/resources/simple.txt", false);
req.send();
} catch (e) {
document.getElementById('result').innerHTML = "FAILURE: Could not load data from cache"
return;
}
if (req.responseText != 'Hello, World!') {
document.getElementById('result').innerHTML = "FAILURE: Did not get correct data from cached resource"
return;
}
createFrame();
}
function frameCreated()
{
setNetworkEnabled(true);
if (frames[0].document.documentElement.innerHTML.match(/abe\.png/))
log("SUCCESS")
else
log("FAIL: Frame.onload was called, but the image doesn't seem to be loaded.");
if (window.testRunner) {
applicationCache.onerror = null;
testRunner.notifyDone();
}
}
function error()
{
// The simulator was in a wrong state, reset it.
setNetworkEnabled(true);
window.location.reload();
}
applicationCache.addEventListener('cached', cached, false);
applicationCache.addEventListener('noupdate', cached, false);
applicationCache.onerror = error;
</script>
</body>
</html>