9d1d05805cf98106ff5f9ca7ac70092a97738422
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hixie76 / websocket-event-target.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../../../js-test-resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <div id="description"></div>
8 <div id="console"></div>
9 <script type="text/javascript">
10 description("Make sure WebSocket object acts as EventTarget.");
11
12 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hixie76/simple");
13 ws.close(); // That is not a test with a WebSocket server, prevent logging an error to console.
14 var open_event_handled = false;
15 var message_event_handled = false;
16 var close_event_handled = false;
17 function openListener() {
18     open_event_handled = true;
19 };
20 function messageListener() {
21     message_event_handled = true;
22 };
23 function closeListener() {
24     close_event_handled = true;
25 }
26 ws.addEventListener('open', openListener, false);
27 ws.addEventListener('message', messageListener, false);
28 ws.addEventListener('close', closeListener, false);
29
30 shouldBe("open_event_handled", "false");
31 shouldBe("message_event_handled", "false");
32 shouldBe("close_event_handled", "false");
33
34 var evt = document.createEvent("Events");
35 evt.initEvent("open", true, false);
36 ws.dispatchEvent(evt);
37 shouldBe("open_event_handled", "true");
38
39 open_event_handled = false;
40 ws.removeEventListener('open', openListener);
41 ws.dispatchEvent(evt);
42 shouldBe("open_event_handled", "false");
43
44 evt = document.createEvent("MessageEvent");
45 evt.initEvent("message", true, false);
46 ws.dispatchEvent(evt);
47 shouldBe("message_event_handled", "true");
48
49 message_event_handled = false;
50 ws.removeEventListener('message', messageListener);
51 ws.dispatchEvent(evt);
52 shouldBe("message_event_handled", "false");
53
54 evt = document.createEvent("Events");
55 evt.initEvent("close", true, false);
56 ws.dispatchEvent(evt);
57 shouldBe("close_event_handled", "true");
58
59 close_event_handled = false;
60 ws.removeEventListener('close', closeListener);
61 ws.dispatchEvent(evt);
62 shouldBe("close_event_handled", "false");
63
64 </script>
65 <script src="../../../../js-test-resources/js-test-post.js"></script>
66 </body>
67 </html>