9825c077ed6ec69a6d36e6a6f1a77e5c3bff2d30
[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 if (window.testRunner)
13     testRunner.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 1);
14
15 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hixie76/simple");
16 ws.close(); // That is not a test with a WebSocket server, prevent logging an error to console.
17 var open_event_handled = false;
18 var message_event_handled = false;
19 var close_event_handled = false;
20 function openListener() {
21     open_event_handled = true;
22 };
23 function messageListener() {
24     message_event_handled = true;
25 };
26 function closeListener() {
27     close_event_handled = true;
28 }
29 ws.addEventListener('open', openListener, false);
30 ws.addEventListener('message', messageListener, false);
31 ws.addEventListener('close', closeListener, false);
32
33 shouldBe("open_event_handled", "false");
34 shouldBe("message_event_handled", "false");
35 shouldBe("close_event_handled", "false");
36
37 var evt = document.createEvent("Events");
38 evt.initEvent("open", true, false);
39 ws.dispatchEvent(evt);
40 shouldBe("open_event_handled", "true");
41
42 open_event_handled = false;
43 ws.removeEventListener('open', openListener);
44 ws.dispatchEvent(evt);
45 shouldBe("open_event_handled", "false");
46
47 evt = document.createEvent("MessageEvent");
48 evt.initEvent("message", true, false);
49 ws.dispatchEvent(evt);
50 shouldBe("message_event_handled", "true");
51
52 message_event_handled = false;
53 ws.removeEventListener('message', messageListener);
54 ws.dispatchEvent(evt);
55 shouldBe("message_event_handled", "false");
56
57 evt = document.createEvent("Events");
58 evt.initEvent("close", true, false);
59 ws.dispatchEvent(evt);
60 shouldBe("close_event_handled", "true");
61
62 close_event_handled = false;
63 ws.removeEventListener('close', closeListener);
64 ws.dispatchEvent(evt);
65 shouldBe("close_event_handled", "false");
66
67 </script>
68 <script src="../../../../js-test-resources/js-test-post.js"></script>
69 </body>
70 </html>