| OLD | NEW |
| 1 <html> | 1 <!DOCTYPE HTML> |
| 2 <body> | 2 <script src="/js-test-resources/js-test.js"></script> |
| 3 <p>Test that basic EventSource cross-origin requests fail until they are allowed
by the Access-Control-Allow-Origin header. Should print a series of PASS messag
es followed by DONE.</p> | 3 <script src="script-tests/eventsource-cors-basic.js"></script> |
| 4 <div id="result"></div> | |
| 5 <script> | |
| 6 function log(msg) { | |
| 7 document.getElementById("result").innerHTML += msg + "<br>"; | |
| 8 } | |
| 9 | |
| 10 if (window.testRunner) { | |
| 11 testRunner.dumpAsText(); | |
| 12 testRunner.waitUntilDone(); | |
| 13 } | |
| 14 | |
| 15 function end() { | |
| 16 if (window.testRunner) | |
| 17 testRunner.notifyDone(); | |
| 18 } | |
| 19 | |
| 20 var count = 1; | |
| 21 var base_url = location.href.substr(0, location.href.lastIndexOf('/')).replace("
127.0.0.1", "localhost"); | |
| 22 | |
| 23 function create_es() { | |
| 24 try { | |
| 25 var es = new EventSource(base_url + "/resources/es-cors-basic.php?count=
" + count); | |
| 26 } | |
| 27 catch (ex) { | |
| 28 log("FAIL: EventSource constructor threw exception: " + ex); | |
| 29 end(); | |
| 30 return; | |
| 31 } | |
| 32 | |
| 33 if (es.withCredentials) { | |
| 34 log("FAIL: withCredentials is true"); | |
| 35 es.close(); | |
| 36 end(); | |
| 37 } | |
| 38 | |
| 39 es.onerror = function () { | |
| 40 if (es.readyState == es.CLOSED) { | |
| 41 if (count != 3 && count != 4) { | |
| 42 log("PASS: got error event and readyState is CLOSED"); | |
| 43 count++; | |
| 44 setTimeout(create_es); | |
| 45 } | |
| 46 else { | |
| 47 log("FAIL: got unexpected error event"); | |
| 48 end(); | |
| 49 } | |
| 50 } | |
| 51 else if (count != 4) { | |
| 52 log("FAIL: got error event but readyState is not CLOSED"); | |
| 53 es.close(); | |
| 54 end(); | |
| 55 } | |
| 56 }; | |
| 57 | |
| 58 es.onmessage = function (evt) { | |
| 59 if (evt.origin != location.origin && !evt.origin.indexOf("http://localho
st")) { | |
| 60 if (count == 3 && evt.data == "DATA1" && evt.lastEventId == "77") { | |
| 61 log("PASS: got cross-origin message event with data \"DATA1\" an
d lastEventId \"77\""); | |
| 62 count++; | |
| 63 return; | |
| 64 } | |
| 65 if (count == 4 && evt.data == "DATA2") { | |
| 66 log("PASS: got cross-origin message event with data \"DATA2\""); | |
| 67 log("DONE"); | |
| 68 } | |
| 69 else | |
| 70 log("FAIL: got unexpected cross-origin message event"); | |
| 71 } | |
| 72 else | |
| 73 log("FAIL: got message event from same or unexpected origin"); | |
| 74 | |
| 75 es.close(); | |
| 76 end(); | |
| 77 }; | |
| 78 } | |
| 79 create_es(); | |
| 80 </script> | |
| 81 </body> | |
| 82 </html> | |
| OLD | NEW |