| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="/js-test-resources/js-test-pre.js"></script> | 4 <script src="/js-test-resources/js-test-pre.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <div id="description"></div> | 7 <div id="description"></div> |
| 8 <div id="console"></div> | 8 <div id="console"></div> |
| 9 <script type="text/javascript"> | 9 <script type="text/javascript"> |
| 10 description("Test if Web Socket is closed on unload"); | 10 description("Test if Web Socket is closed on unload"); |
| 11 | 11 |
| 12 window.jsTestIsAsync = true; | 12 window.jsTestIsAsync = true; |
| 13 | 13 |
| 14 var frameDiv; | 14 var frameDiv; |
| 15 var closedSocket; | 15 var closedSocket; |
| 16 var closeCode; |
| 16 | 17 |
| 17 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload
"); | 18 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/close-on-unload
"); |
| 18 ws.onopen = function() | 19 ws.onopen = function() |
| 19 { | 20 { |
| 20 debug("PASS ws on master document is ready."); | 21 debug("PASS ws on master document is ready."); |
| 21 frameDiv = document.createElement("iframe"); | 22 frameDiv = document.createElement("iframe"); |
| 22 frameDiv.src = "resources/close-on-unload-iframe.html"; | 23 frameDiv.src = "resources/close-on-unload-iframe.html"; |
| 23 document.body.appendChild(frameDiv); | 24 document.body.appendChild(frameDiv); |
| 24 debug("PASS insert a iframe, where open ws called 'socket1'"); | 25 debug("PASS insert a iframe, where open ws called 'socket1'"); |
| 25 }; | 26 }; |
| 26 ws.onmessage = function(evt) | 27 ws.onmessage = function(evt) |
| 27 { | 28 { |
| 28 closedSocket = evt.data; | 29 var messageData = JSON.parse(evt.data); |
| 30 closedSocket = messageData.message; |
| 31 closeCode = messageData.closeCode; |
| 29 ws.close(); | 32 ws.close(); |
| 30 }; | 33 }; |
| 31 ws.onclose = function() | 34 ws.onclose = function() |
| 32 { | 35 { |
| 33 shouldBe("closedSocket", '"socket1"'); | 36 shouldBe("closedSocket", '"socket1"'); |
| 37 shouldBe("closeCode", '"1001"'); |
| 34 finishJSTest(); | 38 finishJSTest(); |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 document.iframeReady = function() | 41 document.iframeReady = function() |
| 38 { | 42 { |
| 39 debug("PASS 'socket1' is sent to the server. unload the iframe. expect recei
ving 'socket1' on ws..."); | 43 debug("PASS 'socket1' is sent to the server. unload the iframe. expect recei
ving 'socket1' on ws..."); |
| 40 document.body.removeChild(frameDiv); | 44 document.body.removeChild(frameDiv); |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 </script> | 47 </script> |
| 44 <script src="/js-test-resources/js-test-post.js"></script> | 48 <script src="/js-test-resources/js-test-post.js"></script> |
| 45 </body> | 49 </body> |
| 46 </html> | 50 </html> |
| OLD | NEW |