OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="/js-test-resources/js-test.js"></script> | 4 <script src="/js-test-resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <div id="description"></div> | |
8 <div id="console"></div> | |
9 <script type="text/javascript"> | 7 <script type="text/javascript"> |
10 description("WebSocket: Object's toString method should be called only once."); | 8 description("WebSocket: Object's toString method should be called only once."); |
11 | 9 |
12 window.jsTestIsAsync = true; | 10 window.jsTestIsAsync = true; |
13 | 11 |
14 | |
15 var testObj = new function() { | 12 var testObj = new function() { |
16 this.callCounter = 0; | 13 this.callCounter = 0; |
17 this.toString = function() { | 14 this.toString = function() { |
18 this.callCounter++; | 15 this.callCounter++; |
| 16 return "Goodbye"; |
19 }; | 17 }; |
20 } | 18 } |
21 | 19 |
22 var url = "ws://127.0.0.1:8880/"; | 20 var ws = new WebSocket("ws://127.0.0.1:8880/echo"); |
23 var ws = new WebSocket(url); | |
24 var closeEvent; | |
25 | |
26 | 21 |
27 ws.onopen = function() | 22 ws.onopen = function() |
28 { | 23 { |
29 ws.send(testObj); | 24 ws.send(testObj); |
30 }; | 25 }; |
31 | 26 |
| 27 ws.onmessage = function(event) |
| 28 { |
| 29 shouldBeEqualToString("event.data", "Goodbye"); |
| 30 }; |
| 31 |
32 ws.onclose = function(event) | 32 ws.onclose = function(event) |
33 { | 33 { |
34 closeEvent = event; | |
35 shouldEvaluateTo("testObj.callCounter", 1); | 34 shouldEvaluateTo("testObj.callCounter", 1); |
| 35 |
| 36 window.closeEvent = event; |
36 shouldBeTrue("closeEvent.wasClean"); | 37 shouldBeTrue("closeEvent.wasClean"); |
| 38 |
37 finishJSTest(); | 39 finishJSTest(); |
38 }; | 40 }; |
39 | |
40 </script> | 41 </script> |
41 </body> | 42 </body> |
42 </html> | 43 </html> |
OLD | NEW |