2009-12-04 Yuzo Fujishima <yuzo@google.com>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Dec 2009 00:31:31 +0000 (00:31 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Dec 2009 00:31:31 +0000 (00:31 +0000)
        Reviewed by Alexey Proskuryakov.

        Add test for web socket send.

        https://bugs.webkit.org/show_bug.cgi?id=31337

        * websocket/tests/script-tests/send.js: Added.
        (endTest):
        (ws.onopen):
        (ws.onmessage.ws.onmessage):
        (ws.onmessage):
        (ws.onclose):
        (timeOutCallback):
        * websocket/tests/send-expected.txt: Added.
        * websocket/tests/send.html: Added.
        * websocket/tests/send_wsh.py: Added.

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

LayoutTests/ChangeLog
LayoutTests/websocket/tests/script-tests/send.js [new file with mode: 0644]
LayoutTests/websocket/tests/send-expected.txt [new file with mode: 0644]
LayoutTests/websocket/tests/send.html [new file with mode: 0644]
LayoutTests/websocket/tests/send_wsh.py [new file with mode: 0644]

index 6f2c99fab876d9a98819579396d5ec9b6f8013da..55c6326630abb7ebca5fed737089bc9cf62bbddb 100644 (file)
@@ -1,3 +1,22 @@
+2009-12-04  Yuzo Fujishima  <yuzo@google.com>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Add test for web socket send.
+
+        https://bugs.webkit.org/show_bug.cgi?id=31337
+
+        * websocket/tests/script-tests/send.js: Added.
+        (endTest):
+        (ws.onopen):
+        (ws.onmessage.ws.onmessage):
+        (ws.onmessage):
+        (ws.onclose):
+        (timeOutCallback):
+        * websocket/tests/send-expected.txt: Added.
+        * websocket/tests/send.html: Added.
+        * websocket/tests/send_wsh.py: Added.
+
 2009-12-04  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Dan Bernstein.
diff --git a/LayoutTests/websocket/tests/script-tests/send.js b/LayoutTests/websocket/tests/script-tests/send.js
new file mode 100644 (file)
index 0000000..8ca82e3
--- /dev/null
@@ -0,0 +1,54 @@
+description("Web Socket send test");
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+function endTest()
+{
+    isSuccessfullyParsed();
+    clearTimeout(timeoutID);
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/send");
+
+var FIRST_MESSAGE_TO_SEND = "This is the first message to send to the server.";
+var SECOND_MESSAGE_TO_SEND = "This is the second.";
+// data needs to be global to be accessbile from shouldBe().
+var data = "";
+
+ws.onopen = function()
+{
+    debug("Connected.");
+    ws.send(FIRST_MESSAGE_TO_SEND);
+};
+
+ws.onmessage = function(messageEvent)
+{
+    // The server should echo back the first message.
+    data = messageEvent.data;
+    shouldBe("data", "FIRST_MESSAGE_TO_SEND");
+    ws.onmessage = function(messageEvent) {
+        // The server should echo back the second message.
+        data = messageEvent.data;
+        shouldBe("data", "SECOND_MESSAGE_TO_SEND");
+    };
+    ws.send(SECOND_MESSAGE_TO_SEND);
+};
+
+ws.onclose = function()
+{
+    debug("Closed.");
+    endTest();
+};
+
+function timeOutCallback()
+{
+    testFailed("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+var successfullyParsed = true;
diff --git a/LayoutTests/websocket/tests/send-expected.txt b/LayoutTests/websocket/tests/send-expected.txt
new file mode 100644 (file)
index 0000000..cb3c7f5
--- /dev/null
@@ -0,0 +1,12 @@
+Web Socket send test
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+PASS data is FIRST_MESSAGE_TO_SEND
+PASS data is SECOND_MESSAGE_TO_SEND
+Closed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/websocket/tests/send.html b/LayoutTests/websocket/tests/send.html
new file mode 100644 (file)
index 0000000..c6c0366
--- /dev/null
@@ -0,0 +1,13 @@
+<!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 src="script-tests/send.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/websocket/tests/send_wsh.py b/LayoutTests/websocket/tests/send_wsh.py
new file mode 100644 (file)
index 0000000..25104b3
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright (C) 2009 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+#     * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    # Receive and echo back messages twice.
+    for unused in range(2):
+        message = msgutil.receive_message(request)
+        msgutil.send_message(request, message)