--HG--
extra : rebase_source : 8d700930e3856b464e138782c501d3c4d617be2a
This commit is contained in:
Olli Pettay 2010-06-18 00:30:13 +03:00
Родитель 272d0c5018
Коммит 5ebfe4dd97
4 изменённых файлов: 119 добавлений и 2 удалений

Просмотреть файл

@ -396,6 +396,8 @@ _TEST_FILES2 = \
test_bug571390.xul \
test_websocket_hello.html \
file_websocket_hello_wsh.py \
test_ws_basic_tests.html \
file_ws_basic_tests_wsh.py \
$(NULL)
# This test fails on the Mac for some reason

Просмотреть файл

@ -0,0 +1,26 @@
from mod_pywebsocket import msgutil
def web_socket_do_extra_handshake(request):
if (request.ws_protocol == 'error'):
raise ValueError('Error')
pass
def web_socket_transfer_data(request):
while True:
line = msgutil.receive_message(request)
if line == 'protocol':
msgutil.send_message(request, request.ws_protocol)
continue
if line == 'resource':
msgutil.send_message(request, request.ws_resource)
continue
if line == 'origin':
msgutil.send_message(request, request.ws_origin)
continue
msgutil.send_message(request, line)
if line == 'end':
return

Просмотреть файл

@ -26,11 +26,11 @@ function testWebSocket () {
ws.onclose = function(e) {
}
ws.onerror = function(e) {
is(false, "onerror called!");
ok(false, "onerror called!");
SimpleTest.finish();
}
ws.onmessage = function(e) {
is(e.data, "Hello world!");
is(e.data, "Hello world!", "Wrong data");
ws.close();
SimpleTest.finish();
}

Просмотреть файл

@ -0,0 +1,89 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Basic websocket test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="testWebSocket()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=472529">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var ws;
var params = ["protocol", "resource", "origin", "end"];
var results = ["test", "/tests/content/base/test/file_ws_basic_tests", "http://mochi.test:8888", "end"];
function testWebSocket () {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_ws_basic_tests", "test");
ws.onopen = function(e) {
for (var i = 0; i < params.length; ++i) {
document.getElementById('log').textContent += "sending " + params[i] + "\n";
ws.send(params[i]);
}
}
ws.onclose = function(e) {
is(results.length, 0, "All the messages should have been processed!");
SimpleTest.finish();
}
ws.onerror = function(e) {
ok(false, "onerror called!");
SimpleTest.finish();
}
ws.onmessage = function(e) {
document.getElementById('log').textContent += "\n" + e.data;
is(e.data, results[0], "Unexpected message");
results.shift();
}
}
function testWebSocket2() {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_ws_basic_tests", "test");
var testCount = 1000; // Send lots of messages
var messageCount = 0;
var testMessage = "test message";
ws.onopen = function(e) {
for (var i = 0; i < testCount; ++i) {
ws.send(testMessage);
}
ws.send("end");
}
ws.onclose = function(e) {
is(messageCount, testCount, "Didn't receive all the messages!");
testWebSocket3();
}
ws.onerror = function(e) {
ok(false, "onerror called!");
SimpleTest.finish();
}
ws.onmessage = function(e) {
is(e.data, testMessage, "Wrong message");
++messageCount;
document.getElementById('log').textContent = messageCount;
if (messageCount == testCount) {
this.onmessage = null;
}
}
}
SimpleTest.waitForExplicitFinish();
</script>
<pre id="log">
</pre>
</pre>
<div>
</div>
</body>
</html>