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