OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML> |
| 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> |
| 10 description("Test that WebSocket fires error event if no WebSocket Server can be
connected."); |
| 11 |
| 12 window.jsTestIsAsync = true; |
| 13 |
| 14 function endTest() |
| 15 { |
| 16 clearTimeout(timeoutID); |
| 17 finishJSTest(); |
| 18 } |
| 19 |
| 20 var url = "ws://localhost:8888"; //here it should have no websocket server to li
sten. |
| 21 |
| 22 function doTest(index) |
| 23 { |
| 24 debug("test" + index + " Start"); |
| 25 |
| 26 var ws = new WebSocket(url); |
| 27 |
| 28 ws.onopen = function() |
| 29 { |
| 30 testFailed("Connected"); |
| 31 endTest(); |
| 32 }; |
| 33 |
| 34 ws.onmessage = function(messageEvent) |
| 35 { |
| 36 testFailed("Received Message"); |
| 37 ws.close(); |
| 38 endTest(); |
| 39 }; |
| 40 |
| 41 if (index == 0) { |
| 42 ws.onclose = function() |
| 43 { |
| 44 testPassed("onclose was called"); |
| 45 doTest(index + 1); |
| 46 }; |
| 47 ws.onerror = function() |
| 48 { |
| 49 testPassed("onerror was called"); |
| 50 }; |
| 51 } else if (index == 1) { |
| 52 ws.onclose = function() |
| 53 { |
| 54 testPassed("onclose was called"); |
| 55 ws.close(); |
| 56 doTest(index + 1); |
| 57 }; |
| 58 ws.onerror = function() |
| 59 { |
| 60 testPassed("onerror was called"); |
| 61 }; |
| 62 } else { |
| 63 ws.onclose = function() |
| 64 { |
| 65 testPassed("onclose was called"); |
| 66 endTest(); |
| 67 }; |
| 68 ws.onerror = function() |
| 69 { |
| 70 testPassed("onerror was called"); |
| 71 ws.close(); |
| 72 }; |
| 73 } |
| 74 } |
| 75 |
| 76 function timeOutCallback() |
| 77 { |
| 78 debug("Timed out..."); |
| 79 endTest(); |
| 80 } |
| 81 |
| 82 var timeoutID = setTimeout(timeOutCallback, 3000); |
| 83 |
| 84 doTest(0); |
| 85 |
| 86 </script> |
| 87 <script src="../../../../js-test-resources/js-test-post.js"></script> |
| 88 </body> |
| 89 </html> |
OLD | NEW |