blob: 8cf14aa538e4abd43ce7f4e1a897578f5cb62a6c [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();
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}
var xhr;
var logExisting;
var logMissing;
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") }
try {
xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/reply.xml", false);
xhr.send();
} catch (ex) {
log(ex);
}
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") }
try {
xhr.open("GET", "http://localhost:7/", false); // A port that will likely refuse the connection.
xhr.send();
} catch (ex) {
log(ex);
}
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;
}
</script>
</body>
</html>