- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / eventsource / eventsource-cors-no-server.html
1 <html>
2 <body>
3 <p>Test that EventSource tries to reconnect if there's no server response when making cross-origin requests. Should print a series of PASS messages followed by DONE.</p>
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 = 0;
21 var hosts = ["http://127.0.0.1:12345/event-stream", "http://localhost:54321/event-stream"];
22
23 function create_es() {
24     try {
25         var es = new EventSource(hosts[count]);
26     }
27     catch (ex) {
28         log("FAIL: EventSource constructor threw exception: " + ex);
29         end();
30         return;
31     }
32
33     es.onerror = function () {
34         if (es.readyState == es.CONNECTING) {
35             log("PASS: got error event and readyState is CONNECTING");
36             es.close();
37             end();
38             return;
39         }
40
41         if (es.readyState == es.CLOSED)
42             log("FAIL: got error event but readyState is CLOSED");
43
44         if (++count == hosts.length) {
45             log("DONE");
46             end();
47         }
48         else
49             setTimeout(create_es);
50     };
51 }
52 create_es();
53 </script>
54 </body>
55 </html>