2011-07-05 Yuta Kitamura <yutak@chromium.org>
[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 <link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
5 <script src="../../../../js-test-resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <div id="description"></div>
9 <div id="console"></div>
10 <script type="text/javascript">
11 description("Make sure WebSocket object acts as EventTarget.");
12
13 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hixie76/simple");
14 ws.close(); // That is not a test with a WebSocket server, prevent logging an error to console.
15 var open_event_handled = false;
16 var message_event_handled = false;
17 var close_event_handled = false;
18 function openListener() {
19     open_event_handled = true;
20 };
21 function messageListener() {
22     message_event_handled = true;
23 };
24 function closeListener() {
25     close_event_handled = true;
26 }
27 ws.addEventListener('open', openListener, false);
28 ws.addEventListener('message', messageListener, false);
29 ws.addEventListener('close', closeListener, false);
30
31 shouldBe("open_event_handled", "false");
32 shouldBe("message_event_handled", "false");
33 shouldBe("close_event_handled", "false");
34
35 var evt = document.createEvent("Events");
36 evt.initEvent("open", true, false);
37 ws.dispatchEvent(evt);
38 shouldBe("open_event_handled", "true");
39
40 open_event_handled = false;
41 ws.removeEventListener('open', openListener);
42 ws.dispatchEvent(evt);
43 shouldBe("open_event_handled", "false");
44
45 evt = document.createEvent("MessageEvent");
46 evt.initEvent("message", true, false);
47 ws.dispatchEvent(evt);
48 shouldBe("message_event_handled", "true");
49
50 message_event_handled = false;
51 ws.removeEventListener('message', messageListener);
52 ws.dispatchEvent(evt);
53 shouldBe("message_event_handled", "false");
54
55 evt = document.createEvent("Events");
56 evt.initEvent("close", true, false);
57 ws.dispatchEvent(evt);
58 shouldBe("close_event_handled", "true");
59
60 close_event_handled = false;
61 ws.removeEventListener('close', closeListener);
62 ws.dispatchEvent(evt);
63 shouldBe("close_event_handled", "false");
64
65 var successfullyParsed = true;
66 </script>
67 <script src="../../../../js-test-resources/js-test-post.js"></script>
68 </body>
69 </html>