[Mac][Win][WK2] Switch to RFC 6455 protocol for WebSockets
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / hixie76 / close-on-unload.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
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 type="text/javascript">
10 description("Test if Web Socket is closed on unload");
11
12 window.jsTestIsAsync = true;
13 if (window.layoutTestController)
14     layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 1);
15
16 var frameDiv;
17 var closedSocket;
18
19 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hixie76/close-on-unload");
20 ws.onopen = function()
21 {
22     debug("PASS ws on master document is ready.");
23     frameDiv = document.createElement("iframe");
24     frameDiv.src = "resources/close-on-unload-iframe.html";
25     document.body.appendChild(frameDiv);
26     debug("PASS insert a iframe, where open ws called 'socket1'");
27 };
28 ws.onmessage = function(evt)
29 {
30     closedSocket = evt.data;
31     ws.close();
32 };
33 ws.onclose = function()
34 {
35     shouldBe("closedSocket", '"socket1"');
36     finishJSTest();
37 };
38
39 document.iframeReady = function()
40 {
41     debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
42     document.body.removeChild(frameDiv);
43 }; 
44
45 </script>
46 <script src="../../../../js-test-resources/js-test-post.js"></script>
47 </body>
48 </html>