3 <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>
4 <pre id='console'
></pre>
5 <script type=
"text/javascript">
6 if (window
.testRunner
) {
7 testRunner
.dumpAsText();
8 testRunner
.waitUntilDone();
13 document
.getElementById('console').appendChild(document
.createTextNode(message
+ "\n"));
20 function doneExisting()
22 if (xhr
.responseText
.length
)
23 alert("FAIL: Response is not empty, " + xhr
.responseText
);
25 logExisting
= document
.getElementById('console').innerHTML
;
26 document
.getElementById('console').innerHTML
= "";
28 xhr
= new XMLHttpRequest
;
29 xhr
.onreadystatechange = function() { log("onreadystatechange " + xhr
.readyState
) }
30 xhr
.onload = function() { log("onload") }
31 xhr
.onloadstart = function() { log("onloadstart") }
32 xhr
.onprogress = function() { log("onprogress") }
33 xhr
.onerror = function() { log("onerror"); setTimeout(doneMissing
, 100); }
34 xhr
.open("GET", "http://localhost:7/", true); // A port that will likely refuse the connection.
38 function doneMissing()
40 if (xhr
.responseText
.length
)
41 alert("FAIL: Response is not empty, " + xhr
.responseText
);
43 logMissing
= document
.getElementById('console').innerHTML
;
44 document
.getElementById('console').innerHTML
= "";
46 if (logMissing
== logExisting
)
49 log("FAIL. Responding server:");
50 document
.getElementById('console').innerHTML
+= logExisting
;
51 log("Non-existent server:");
52 document
.getElementById('console').innerHTML
+= logMissing
;
54 if (window
.testRunner
)
55 testRunner
.notifyDone();
58 xhr
= new XMLHttpRequest
;
59 xhr
.onreadystatechange = function() { log("onreadystatechange " + xhr
.readyState
) }
60 xhr
.onload = function() { log("onload") }
61 xhr
.onloadstart = function() { log("onloadstart") }
62 xhr
.onprogress = function() { log("onprogress") }
63 xhr
.onerror = function() { log("onerror"); setTimeout(doneExisting
, 100); }
64 xhr
.open("GET", "http://localhost:8000/xmlhttprequest/resources/reply.xml", true);