Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / simple-cross-origin-denied-events-sync.html
blob7e606b4aeab81c97ee4d30bc21ee72ae182e095d
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();
9 function log(message)
11 document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
14 var xhr;
15 var logExisting;
16 var logMissing;
18 xhr = new XMLHttpRequest;
19 xhr.onreadystatechange = function() { log("onreadystatechange " + xhr.readyState) }
20 xhr.onload = function() { log("onload") }
21 xhr.onloadstart = function() { log("onloadstart") }
22 xhr.onprogress = function() { log("onprogress") }
23 xhr.onerror = function() { log("onerror") }
24 try {
25 xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/reply.xml", false);
26 xhr.send();
27 } catch (ex) {
28 log("Exception thrown: " + ex.name);
31 if (xhr.responseText.length)
32 alert("FAIL: Response is not empty, " + xhr.responseText);
34 logExisting = document.getElementById('console').innerHTML;
35 document.getElementById('console').innerHTML = "";
37 xhr = new XMLHttpRequest;
38 xhr.onreadystatechange = function() { log("onreadystatechange " + xhr.readyState) }
39 xhr.onload = function() { log("onload") }
40 xhr.onloadstart = function() { log("onloadstart") }
41 xhr.onprogress = function() { log("onprogress") }
42 xhr.onerror = function() { log("onerror") }
43 try {
44 xhr.open("GET", "http://localhost:7/", false); // A port that will likely refuse the connection.
45 xhr.send();
46 } catch (ex) {
47 log("Exception thrown: " + ex.name);
50 if (xhr.responseText.length)
51 alert("FAIL: Response is not empty, " + xhr.responseText);
53 logMissing = document.getElementById('console').innerHTML;
54 document.getElementById('console').innerHTML = "";
56 if (logMissing == logExisting)
57 log("PASS");
58 else {
59 log("FAIL. Responding server:");
60 document.getElementById('console').innerHTML += logExisting;
61 log("Non-existent server:");
62 document.getElementById('console').innerHTML += logMissing;
64 </script>
65 </body>
66 </html>