blob: a23885f08bf48c65b7034c729bffc0dfdf41592d [file] [log] [blame]
James Graham2120f702012-10-27 09:13:401<!DOCTYPE html>
2<html>
3 <head>
4 <title>EventSource: reconnection</title>
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 </head>
8 <body>
9 <div id="log"></div>
10 <script>
James Graham2120f702012-10-27 09:13:4011 function doReconn(url, title) {
12 var test = async_test(document.title + " " + title)
13 test.step(function() {
14 var source = new EventSource(url)
15 source.onmessage = test.step_func(function(e) {
16 assert_equals(e.data, "data")
17 source.close()
18 test.done()
19 })
20 })
21 }
22
James Graham234a6722013-09-17 17:54:3823 doReconn("resources/status-reconnect.py?status=200",
James Graham2120f702012-10-27 09:13:4024 "200")
25
26
27 var t = async_test(document.title + ", test reconnection events", { timeout: 9000 });
28 t.step(function() {
29 var opened = false, reconnected = false,
James Graham234a6722013-09-17 17:54:3830 source = new EventSource("resources/status-reconnect.py?status=200&ok_first&id=2");
James Graham2120f702012-10-27 09:13:4031
32 source.onerror = t.step_func(function(e) {
33 assert_equals(e.type, 'error');
34 assert_equals(source.readyState, source.CONNECTING, "readyState");
35 assert_true(opened, "connection is opened earlier");
36
37 reconnected = true;
38 });
39
40 source.onmessage = t.step_func(function(e) {
41 if (!opened) {
42 opened = true;
43 assert_false(reconnected, "have reconnected before first message");
44 assert_equals(e.data, "ok");
45 }
46 else {
47 assert_true(reconnected, "Got reconnection event");
48 assert_equals(e.data, "data");
49 source.close()
50 t.done()
51 }
52 });
53 });
54
55 </script>
56 </body>
57</html>
58