blob: e8798d29020d820ed614727d272924a547498c05 [file] [log] [blame]
commit-queue@webkit.org2df44222012-12-19 00:19:42 +00001<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>
6function log(msg) {
7 document.getElementById("result").innerHTML += msg + "<br>";
8}
9
10if (window.testRunner) {
11 testRunner.dumpAsText();
12 testRunner.waitUntilDone();
13}
14
15function end() {
16 if (window.testRunner)
17 testRunner.notifyDone();
18}
19
20var count = 0;
21var hosts = ["http://127.0.0.1:12345/event-stream", "http://localhost:54321/event-stream"];
22
23function 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}
52create_es();
53</script>
54</body>
55</html>