2010-02-04 Fumitoshi Ukai <ukai@chromium.org>
authorukai@chromium.org <ukai@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Feb 2010 06:15:22 +0000 (06:15 +0000)
committerukai@chromium.org <ukai@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Feb 2010 06:15:22 +0000 (06:15 +0000)
        Reviewed by Alexey Proskuryakov.

        should not crash when document opened websocket is unloaded
        https://bugs.webkit.org/show_bug.cgi?id=34562

        * websocket/tests/close-on-unload-and-force-gc-expected.txt: Added.
        * websocket/tests/close-on-unload-and-force-gc.html: Added.
        * websocket/tests/close-on-unload-reference-in-parent-expected.txt: Added.
        * websocket/tests/close-on-unload-reference-in-parent.html: Added.
        * websocket/tests/resources/close-on-unload-iframe-reference-in-parent.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@54406 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/websocket/tests/close-on-unload-and-force-gc-expected.txt [new file with mode: 0644]
LayoutTests/websocket/tests/close-on-unload-and-force-gc.html [new file with mode: 0644]
LayoutTests/websocket/tests/close-on-unload-reference-in-parent-expected.txt [new file with mode: 0644]
LayoutTests/websocket/tests/close-on-unload-reference-in-parent.html [new file with mode: 0644]
LayoutTests/websocket/tests/resources/close-on-unload-iframe-reference-in-parent.html [new file with mode: 0644]

index 0a84996..3c9b790 100644 (file)
@@ -1,5 +1,18 @@
 2010-02-04  Fumitoshi Ukai  <ukai@chromium.org>
 
+        Reviewed by Alexey Proskuryakov.
+
+        should not crash when document opened websocket is unloaded
+        https://bugs.webkit.org/show_bug.cgi?id=34562
+
+        * websocket/tests/close-on-unload-and-force-gc-expected.txt: Added.
+        * websocket/tests/close-on-unload-and-force-gc.html: Added.
+        * websocket/tests/close-on-unload-reference-in-parent-expected.txt: Added.
+        * websocket/tests/close-on-unload-reference-in-parent.html: Added.
+        * websocket/tests/resources/close-on-unload-iframe-reference-in-parent.html: Added.
+
+2010-02-04  Fumitoshi Ukai  <ukai@chromium.org>
+
         Reviewed by Shinichiro Hamaji.
 
         websocket/tests/close-on-unload.html failed on Mac Tiger
diff --git a/LayoutTests/websocket/tests/close-on-unload-and-force-gc-expected.txt b/LayoutTests/websocket/tests/close-on-unload-and-force-gc-expected.txt
new file mode 100644 (file)
index 0000000..6a347a4
--- /dev/null
@@ -0,0 +1,12 @@
+Test if Web Socket is closed on unload and not crashed if garbage collected
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS 'socket1' is sent to the server. unload the iframe and force garbage collection. expect receiving 'socket1' on ws and no crash...
+PASS closedSocket is "socket1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/websocket/tests/close-on-unload-and-force-gc.html b/LayoutTests/websocket/tests/close-on-unload-and-force-gc.html
new file mode 100644 (file)
index 0000000..d88deba
--- /dev/null
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../fast/js/resources/js-test-post-function.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket is closed on unload and not crashed if garbage collected");
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+function gc()
+{
+    if (window.GCController)
+        return GCController.collect();
+
+    for (var i = 0; i < 10000; i++) { // > force garbage collection (FF requires about 9K allocations before a collect)
+        var s = new String("abc");
+    }
+};
+
+var frameDiv;
+var closedSocket;
+
+function endTest()
+{
+    shouldBe("closedSocket", '"socket1"');
+    isSuccessfullyParsed();
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+};
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    endTest();
+};
+
+document.iframeReady = function()
+{
+    debug("PASS 'socket1' is sent to the server. unload the iframe and force garbage collection. expect receiving 'socket1' on ws and no crash...");
+    document.body.removeChild(frameDiv);
+    gc();
+};
+
+var successfullyParsed = true;
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/websocket/tests/close-on-unload-reference-in-parent-expected.txt b/LayoutTests/websocket/tests/close-on-unload-reference-in-parent-expected.txt
new file mode 100644 (file)
index 0000000..68b7281
--- /dev/null
@@ -0,0 +1,14 @@
+Test if Web Socket opened in iframe but referred in parent document is closed on unloading the frame.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws on master document is ready.
+PASS insert a iframe, where open ws called 'socket1'
+PASS document.childWebSocket is non-null.
+PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...
+PASS closedSocket is "socket1"
+PASS document.childWebSocket.readyState is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/websocket/tests/close-on-unload-reference-in-parent.html b/LayoutTests/websocket/tests/close-on-unload-reference-in-parent.html
new file mode 100644 (file)
index 0000000..cc0510b
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../fast/js/resources/js-test-post-function.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+description("Test if Web Socket opened in iframe but referred in parent document is closed on unloading the frame.");
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+var frameDiv;
+var closedSocket;
+document.childWebSocket = null;
+
+function endTest()
+{
+    shouldBe("closedSocket", '"socket1"');
+    shouldBe("document.childWebSocket.readyState", "2");
+    isSuccessfullyParsed();
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+};
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/close-on-unload");
+ws.onopen = function()
+{
+    debug("PASS ws on master document is ready.");
+    frameDiv = document.createElement("iframe");
+    frameDiv.src = "resources/close-on-unload-iframe-reference-in-parent.html";
+    document.body.appendChild(frameDiv);
+    debug("PASS insert a iframe, where open ws called 'socket1'");
+};
+ws.onmessage = function(evt)
+{
+    closedSocket = evt.data;
+    ws.close();
+};
+ws.onclose = function()
+{
+    endTest();
+};
+
+document.iframeReady = function()
+{
+    shouldBeNonNull("document.childWebSocket");
+    debug("PASS 'socket1' is sent to the server. unload the iframe. expect receiving 'socket1' on ws...");
+    document.body.removeChild(frameDiv);
+};
+
+var successfullyParsed = true;
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/websocket/tests/resources/close-on-unload-iframe-reference-in-parent.html b/LayoutTests/websocket/tests/resources/close-on-unload-iframe-reference-in-parent.html
new file mode 100644 (file)
index 0000000..d230e25
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../../fast/js/resources/js-test-post-function.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/javascript">
+parent.document.childWebSocket = new WebSocket("ws://127.0.0.1:8880/websocket/tests/close-on-unload");
+
+parent.document.childWebSocket.onopen = function()
+{
+    // send "socket1" to server, so that "socket1" will be broadcasted to web sockets connected to close-on-unload when this web socket is closed.
+    parent.document.childWebSocket.send("socket1");
+};
+parent.document.childWebSocket.onmessage = function(evt)
+{
+    // "socket1" is received by server, so ready to unload this document.
+    parent.document.iframeReady(evt.data);
+};
+</script>
+</body>
+</html>