blob: ad9d5ee3d01d549ec076dc533a861fe51fc8a2e1 [file] [log] [blame]
<html>
<body>
<p>Test that a simple cross-origin request to a server that responds (but does not permit cross-origin requests) is indistinguishable from one that does not exist. Should say PASS:</p>
<pre id='console'></pre>
<script type="text/javascript">
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}
var xhr;
var logExisting;
var logMissing;
function doneExisting()
{
if (xhr.responseText.length)
alert("FAIL: Response is not empty, " + xhr.responseText);
logExisting = document.getElementById('console').innerHTML;
document.getElementById('console').innerHTML = "";
xhr = new XMLHttpRequest;
xhr.onreadystatechange = function() { log("onreadystatechange " + xhr.readyState) }
xhr.onload = function() { log("onload") }
xhr.onloadstart = function() { log("onloadstart") }
xhr.onprogress = function() { log("onprogress") }
xhr.onerror = function() { log("onerror"); setTimeout(doneMissing, 100); }
xhr.open("GET", "http://localhost:7/", true); // A port that will likely refuse the connection.
xhr.send();
}
function doneMissing()
{
if (xhr.responseText.length)
alert("FAIL: Response is not empty, " + xhr.responseText);
logMissing = document.getElementById('console').innerHTML;
document.getElementById('console').innerHTML = "";
if (logMissing == logExisting)
log("PASS");
else {
log("FAIL. Responding server:");
document.getElementById('console').innerHTML += logExisting;
log("Non-existent server:");
document.getElementById('console').innerHTML += logMissing;
}
if (window.testRunner)
testRunner.notifyDone();
}
xhr = new XMLHttpRequest;
xhr.onreadystatechange = function() { log("onreadystatechange " + xhr.readyState) }
xhr.onload = function() { log("onload") }
xhr.onloadstart = function() { log("onloadstart") }
xhr.onprogress = function() { log("onprogress") }
xhr.onerror = function() { log("onerror"); setTimeout(doneExisting, 100); }
xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/reply.xml", true);
xhr.send();
</script>
</body>
</html>