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
.upload
.onabort = function() { log("upload.onabort") }
35 xhr
.upload
.onerror = function() { log("upload.onerror") }
36 xhr
.upload
.onload = function() { log("upload.onload") }
37 xhr
.upload
.onloadstart = function() { log("upload.onloadstart") }
38 xhr
.upload
.onprogress = function() { log("upload.onprogress") }
39 xhr
.open("POST", "http://localhost:7/", true); // A port that will likely refuse the connection.
40 xhr
.setRequestHeader("Content-Type", "text/plain");
44 function doneMissing()
46 if (xhr
.responseText
.length
)
47 alert("FAIL: Response is not empty, " + xhr
.responseText
);
49 logMissing
= document
.getElementById('console').innerHTML
;
50 document
.getElementById('console').innerHTML
= "";
52 if (logMissing
== logExisting
)
55 log("FAIL. Responding server:");
56 document
.getElementById('console').innerHTML
+= logExisting
;
57 log("Non-existent server:");
58 document
.getElementById('console').innerHTML
+= logMissing
;
60 if (window
.testRunner
)
61 testRunner
.notifyDone();
64 xhr
= new XMLHttpRequest
;
65 xhr
.onreadystatechange = function() { log("onreadystatechange " + xhr
.readyState
) }
66 xhr
.onload = function() { log("onload") }
67 xhr
.onloadstart = function() { log("onloadstart") }
68 xhr
.onprogress = function() { log("onprogress") }
69 xhr
.onerror = function() { log("onerror"); setTimeout(doneExisting
, 100); }
70 xhr
.upload
.onabort = function() { log("upload.onabort") }
71 xhr
.upload
.onerror = function() { log("upload.onerror") }
72 xhr
.upload
.onload = function() { log("upload.onload") }
73 xhr
.upload
.onloadstart = function() { log("upload.onloadstart") }
74 xhr
.upload
.onprogress = function() { log("upload.onprogress") }
75 xhr
.open("POST", "http://localhost:8000/xmlhttprequest/resources/reply.xml", true);
76 xhr
.setRequestHeader("Content-Type", "text/plain");