2010-02-03 Fumitoshi Ukai <ukai@chromium.org>
[WebKit-https.git] / LayoutTests / websocket / tests / close-on-unload.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
5 <script src="../../fast/js/resources/js-test-pre.js"></script>
6 <script src="../../fast/js/resources/js-test-post-function.js"></script>
7 </head>
8 <body>
9 <div id="description"></div>
10 <div id="console"></div>
11 <script type="text/javascript">
12 description("Test if Web Socket is closed on unload");
13
14 if (window.layoutTestController)
15     layoutTestController.waitUntilDone();
16
17 var frameDiv;
18 var closedSocket;
19
20 function endTest()
21 {
22     shouldBe("closedSocket", '"socket1"');
23     isSuccessfullyParsed();
24     if (window.layoutTestController)
25         layoutTestController.notifyDone();
26 };
27
28 var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/close-on-unload");
29 ws.onopen = function()
30 {
31     debug("PASS ws on master document is ready.");
32     frameDiv = document.createElement("iframe");
33     frameDiv.src = "resources/close-on-unload-iframe.html";
34     document.body.appendChild(frameDiv);
35     debug("PASS insert a iframe, where open ws called 'socket1'");
36 };
37 ws.onmessage = function(evt)
38 {
39     closedSocket = evt.data;
40     ws.close();
41 };
42 ws.onclose = function()
43 {
44     endTest();
45 };
46
47 document.iframeReady = function()
48 {
49     debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
50     document.body.removeChild(frameDiv);
51 }; 
52
53 var successfullyParsed = true;
54 </script>
55
56 </body>
57 </html>