Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / simple-cross-origin-denied-events.html
blobad9d5ee3d01d549ec076dc533a861fe51fc8a2e1
1 <html>
2 <body>
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();
11 function log(message)
13 document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
16 var xhr;
17 var logExisting;
18 var logMissing;
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.
35 xhr.send();
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)
47 log("PASS");
48 else {
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);
65 xhr.send();
67 </script>
68 </body>
69 </html>