849bba7d9d1d9041fe51510188dab67a8c9d4efc
[WebKit-https.git] / LayoutTests / http / tests / websocket / tests / send-after-close-on-unload.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <link rel="stylesheet" href="../../../js-test-resources/js-test-style.css">
5 <script src="../../../js-test-resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <div id="description"></div>
9 <div id="console"></div>
10 <script type="text/javascript">
11 description("Test if Web Socket opened in iframe, referred in parent document is, and try to send() returns false.");
12
13 window.jsTestIsAsync = true;
14
15 var frameDiv;
16 var closedSocket;
17 document.childWebSocket = null;
18
19 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/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-reference-in-parent.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     shouldBe("document.childWebSocket.readyState", "3");
37     finishJSTest();
38 };
39
40 document.iframeReady = function()
41 {
42     shouldBeNonNull("document.childWebSocket");
43     debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
44     document.body.removeChild(frameDiv);
45     shouldBeFalse("document.childWebSocket.send('send to closed socket')");
46 };
47
48 var successfullyParsed = true;
49 </script>
50 <script src="../../../js-test-resources/js-test-post.js"></script>
51 </body>
52 </html>