2010-06-18 13:48:42 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
|
|
|
|
<title>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">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tests:
|
|
|
|
* 1. client tries to connect to a http scheme location;
|
2010-06-27 14:09:29 -07:00
|
|
|
* 2. assure serialization of the connections;
|
2010-06-18 13:48:42 -07:00
|
|
|
* 3. client tries to connect to an non-existent ws server;
|
|
|
|
* 4. client tries to connect using a relative url;
|
|
|
|
* 5. client uses an invalid protocol value;
|
2010-06-27 14:09:29 -07:00
|
|
|
* 6. counter and encoding check;
|
|
|
|
* 7. client calls close() and the server keeps sending messages and it doesn't
|
|
|
|
* send the close frame;
|
|
|
|
* 8. client calls close() and the server sends the close frame in
|
2010-06-18 13:48:42 -07:00
|
|
|
* acknowledgement;
|
2010-06-27 14:09:29 -07:00
|
|
|
* 9. client closes the connection before the ws connection is established;
|
|
|
|
* 10. client sends a message before the ws connection is established;
|
2010-06-18 13:48:42 -07:00
|
|
|
* 11. a simple hello echo;
|
|
|
|
* 12. client sends a message with bad bytes;
|
|
|
|
* 13. server sends an invalid message;
|
|
|
|
* 14. server sends the close frame, it doesn't close the tcp connection and
|
|
|
|
* it keeps sending normal ws messages;
|
|
|
|
* 15. server closes the tcp connection, but it doesn't send the close frame;
|
|
|
|
* 16. client calls close() and tries to send a message;
|
2010-06-27 14:09:29 -07:00
|
|
|
* 17. see bug 572975 - all event listeners set
|
|
|
|
* 18. client tries to connect to an http resource;
|
|
|
|
* 19. server closes the tcp connection before establishing the ws connection;
|
|
|
|
* 20. see bug 572975 - only on error and onclose event listeners set
|
|
|
|
* 21. see bug 572975 - same as test 17, but delete strong event listeners when
|
|
|
|
* receiving the message event;
|
|
|
|
* 22. server takes too long to establish the ws connection;
|
2010-06-18 13:48:42 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
var first_test = 1;
|
2010-06-27 14:09:29 -07:00
|
|
|
var last_test = 22;
|
2010-06-18 13:48:42 -07:00
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
var current_test = first_test;
|
2010-06-18 13:48:42 -07:00
|
|
|
|
|
|
|
var timeoutToAbortTest = 60000;
|
2010-06-27 14:09:29 -07:00
|
|
|
var timeoutToOpenWS = 25000;
|
2010-06-18 13:48:42 -07:00
|
|
|
var all_ws = [];
|
|
|
|
|
|
|
|
function shouldNotOpen(e)
|
|
|
|
{
|
|
|
|
var ws = e.target;
|
|
|
|
ok(false, "onopen shouldn't be called on test " + ws._testNumber + "!");
|
|
|
|
}
|
|
|
|
|
|
|
|
function shouldNotReceiveCloseEvent(e)
|
|
|
|
{
|
|
|
|
var ws = e.target;
|
2010-07-09 15:58:52 -07:00
|
|
|
var extendedErrorInfo = "";
|
|
|
|
if (!ws._testNumber) {
|
2010-07-11 16:21:18 -07:00
|
|
|
extendedErrorInfo += "\nws members:\n";
|
2010-07-09 15:58:52 -07:00
|
|
|
for (var i in ws) {
|
|
|
|
extendedErrorInfo += (i + ": " + ws[i] + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
extendedErrorInfo += "\ne members:\n";
|
|
|
|
for (var i in e) {
|
|
|
|
extendedErrorInfo += (i + ": " + e[i] + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(false, "onclose shouldn't be called on test " + ws._testNumber + "!" + extendedErrorInfo);
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function shouldCloseCleanly(e)
|
|
|
|
{
|
|
|
|
var ws = e.target;
|
2010-06-27 14:09:29 -07:00
|
|
|
ok(e.wasClean, "the ws connection in test " + ws._testNumber + " should be closed cleanly");
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function shouldCloseNotCleanly(e)
|
|
|
|
{
|
|
|
|
var ws = e.target;
|
2010-06-27 14:09:29 -07:00
|
|
|
ok(!e.wasClean, "the ws connection in test " + ws._testNumber + " shouldn't be closed cleanly");
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function CreateTestWS(ws_location, ws_protocol)
|
|
|
|
{
|
|
|
|
var ws;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (ws_protocol == undefined) {
|
|
|
|
ws = new WebSocket(ws_location);
|
|
|
|
} else {
|
|
|
|
ws = new WebSocket(ws_location, ws_protocol);
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:47:53 -07:00
|
|
|
|
|
|
|
ws._testNumber = current_test;
|
|
|
|
ws._receivedCloseEvent = false;
|
|
|
|
ok(true, "added testNumber: " + ws._testNumber +"\n");
|
|
|
|
|
2010-06-18 13:48:42 -07:00
|
|
|
ws.onerror = function(e)
|
|
|
|
{
|
|
|
|
ok(false, "onerror called on test " + e.target._testNumber + "!");
|
|
|
|
};
|
|
|
|
ws.addEventListener("close", function(e)
|
|
|
|
{
|
2010-07-01 09:35:57 -07:00
|
|
|
ws._receivedCloseEvent = true;
|
2010-06-18 13:48:42 -07:00
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
current_test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
all_ws.push(ws);
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
function forcegc()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
Components.utils.forceGC();
|
|
|
|
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
wu.garbageCollect();
|
|
|
|
setTimeout(function()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
wu.garbageCollect();
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
|
2010-06-18 13:48:42 -07:00
|
|
|
function doTest(number)
|
|
|
|
{
|
|
|
|
if (doTest.timeoutId !== null) {
|
|
|
|
clearTimeout(doTest.timeoutId);
|
|
|
|
doTest.timeoutId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (number > last_test) {
|
2010-06-19 04:20:31 -07:00
|
|
|
setTimeout(finishWSTest, 30000); // wait for the close events be dispatched
|
2010-06-18 13:48:42 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$("feedback").innerHTML = "executing test: " + number + " of " + last_test + " tests.";
|
|
|
|
|
|
|
|
var fnTest = eval("test" + number + "");
|
|
|
|
|
|
|
|
if (fnTest._started === true) {
|
|
|
|
doTest(number + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doTest.timeoutId = setTimeout(function()
|
|
|
|
{
|
|
|
|
ok(false, "test " + number + " took too long to finish!");
|
|
|
|
doTest(number + 1);
|
|
|
|
}, timeoutToAbortTest);
|
|
|
|
|
|
|
|
fnTest._started = true;
|
|
|
|
fnTest();
|
|
|
|
}
|
|
|
|
doTest.timeoutId = null;
|
|
|
|
|
|
|
|
function test1()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var ws = CreateTestWS("http://mochi.test:8888/tests/content/base/test/file_websocket");
|
|
|
|
ok(false, "test1 failed");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "test1 failed");
|
|
|
|
}
|
|
|
|
doTest(2);
|
|
|
|
}
|
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
// this test expects that the serialization list to connect to the proxy
|
|
|
|
// is empty
|
2010-06-18 13:48:42 -07:00
|
|
|
function test2()
|
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
var ws1 = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 2.1");
|
|
|
|
current_test--; // CreateTestWS incremented this
|
|
|
|
var ws2 = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 2.2");
|
|
|
|
|
|
|
|
var ws2CanConnect = false;
|
|
|
|
|
|
|
|
// the server will delay ws1 for 5 seconds
|
|
|
|
|
|
|
|
ws1.onopen = function()
|
|
|
|
{
|
|
|
|
ws2CanConnect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ws2.onopen = function()
|
|
|
|
{
|
|
|
|
ok(ws2CanConnect, "shouldn't connect yet in test 2!");
|
|
|
|
doTest(3);
|
|
|
|
}
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test3()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://this.websocket.server.probably.does.not.exist");
|
|
|
|
ws.onopen = shouldNotOpen;
|
2010-07-01 09:35:57 -07:00
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseNotCleanly(e);
|
|
|
|
doTest(4);
|
|
|
|
};
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test4()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var ws = CreateTestWS("file_websocket");
|
2010-06-27 14:09:29 -07:00
|
|
|
ok(false, "test 4 failed");
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2010-06-27 14:09:29 -07:00
|
|
|
ok(true, "test 4 failed");
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
doTest(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test5()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "");
|
|
|
|
ok(false, "couldn't accept an empty string in the protocol parameter");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "couldn't accept an empty string in the protocol parameter");
|
|
|
|
}
|
|
|
|
current_test--; // CreateTestWS incremented this
|
|
|
|
try {
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "\n");
|
|
|
|
ok(false, "couldn't accept any not printable ASCII character in the protocol parameter");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "couldn't accept any not printable ASCII character in the protocol parameter");
|
|
|
|
}
|
|
|
|
doTest(6);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test6()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 6");
|
2010-06-27 14:09:29 -07:00
|
|
|
var counter = 1;
|
|
|
|
ws.onopen = function()
|
|
|
|
{
|
|
|
|
ws.send(counter);
|
|
|
|
}
|
|
|
|
ws.onmessage = function(e)
|
|
|
|
{
|
|
|
|
if (counter == 5) {
|
|
|
|
ok(e.data == "あいうえお");
|
|
|
|
ws.close();
|
|
|
|
doTest(7);
|
|
|
|
} else {
|
|
|
|
ok(e.data == counter+1, "bad counter");
|
|
|
|
counter += 2;
|
|
|
|
ws.send(counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ws.onclose = shouldCloseCleanly;
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test7()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 7");
|
|
|
|
ws.onopen = function()
|
|
|
|
{
|
|
|
|
ws.close();
|
|
|
|
}
|
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
shouldCloseNotCleanly(e);
|
2010-06-18 13:48:42 -07:00
|
|
|
doTest(8);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test8()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 8");
|
2010-06-27 14:09:29 -07:00
|
|
|
ws.onopen = function()
|
|
|
|
{
|
|
|
|
ws.close();
|
|
|
|
}
|
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseCleanly(e);
|
|
|
|
doTest(9);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test9()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 9");
|
2010-06-18 13:48:42 -07:00
|
|
|
ws.onopen = shouldNotOpen;
|
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseNotCleanly(e);
|
2010-06-27 14:09:29 -07:00
|
|
|
doTest(10);
|
2010-06-18 13:48:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
ws.close();
|
|
|
|
}
|
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
function test10()
|
2010-06-18 13:48:42 -07:00
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 10");
|
2010-06-18 13:48:42 -07:00
|
|
|
ws.onclose = shouldCloseCleanly;
|
|
|
|
|
|
|
|
try {
|
|
|
|
ws.send("client data");
|
|
|
|
ok(false, "Couldn't send data before connecting!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "Couldn't send data before connecting!");
|
|
|
|
}
|
2010-06-27 14:09:29 -07:00
|
|
|
ws.onopen = function()
|
2010-06-18 13:48:42 -07:00
|
|
|
{
|
|
|
|
doTest(11);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test11()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 11");
|
|
|
|
ok(ws.readyState == 0, "bad readyState in test 11!");
|
|
|
|
ws.onopen = function()
|
|
|
|
{
|
|
|
|
ok(ws.readyState == 1, "bad readyState in test 11!");
|
|
|
|
ws.send("client data");
|
|
|
|
}
|
|
|
|
ws.onmessage = function(e)
|
|
|
|
{
|
|
|
|
ok(e.data == "server data", "bad received message in test 11!");
|
|
|
|
ws.close();
|
|
|
|
ok(ws.readyState == 2, "bad readyState in test 11!");
|
|
|
|
}
|
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
ok(ws.readyState == 3, "bad readyState in test 11!");
|
|
|
|
shouldCloseCleanly(e);
|
|
|
|
doTest(12);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test12()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 12");
|
|
|
|
ws.onopen = function()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// send an unpaired surrogate
|
|
|
|
ws.send(String.fromCharCode(0xD800));
|
|
|
|
ok(false, "couldn't send an unpaired surrogate!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "couldn't send an unpaired surrogate!");
|
|
|
|
}
|
|
|
|
ws.close();
|
2010-06-19 09:25:00 -07:00
|
|
|
doTest(13);
|
2010-06-18 13:48:42 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test13()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 13");
|
|
|
|
ws._timesCalledOnError = 0;
|
|
|
|
ws.onerror = function()
|
|
|
|
{
|
|
|
|
ws._timesCalledOnError++;
|
|
|
|
if (ws._timesCalledOnError == 2) {
|
2010-06-27 14:09:29 -07:00
|
|
|
ok(true, "test 13 succeeded");
|
2010-06-18 13:48:42 -07:00
|
|
|
doTest(14);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ws.onclose = shouldCloseCleanly;
|
|
|
|
}
|
|
|
|
|
|
|
|
function test14()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 14");
|
|
|
|
ws.onmessage = function()
|
|
|
|
{
|
|
|
|
ok(false, "shouldn't received message after the server sent the close frame");
|
|
|
|
}
|
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseCleanly(e);
|
2010-06-19 05:13:18 -07:00
|
|
|
doTest(15);
|
2010-06-18 13:48:42 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test15()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 15");
|
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseNotCleanly(e);
|
|
|
|
doTest(16);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test16()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 16");
|
|
|
|
ws.onopen = function()
|
|
|
|
{
|
|
|
|
ws.close();
|
|
|
|
ok(!ws.send("client data"), "shouldn't send message after calling close()");
|
|
|
|
doTest(17);
|
|
|
|
}
|
|
|
|
ws.onmessage = function()
|
|
|
|
{
|
|
|
|
ok(false, "shouldn't send message after calling close()");
|
|
|
|
}
|
|
|
|
ws.onclose = shouldCloseCleanly;
|
|
|
|
}
|
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
var status_test17 = "not started";
|
|
|
|
|
|
|
|
window._test17 = function()
|
2010-06-18 13:48:42 -07:00
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 17");
|
2010-07-12 19:31:20 -07:00
|
|
|
local_ws._testNumber = "local17";
|
2010-07-01 09:35:57 -07:00
|
|
|
current_test++;
|
2010-06-27 14:09:29 -07:00
|
|
|
|
|
|
|
status_test17 = "started";
|
|
|
|
|
|
|
|
local_ws.onopen = function(e)
|
2010-06-18 13:48:42 -07:00
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
status_test17 = "opened";
|
|
|
|
e.target.send("client data");
|
|
|
|
forcegc();
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onerror = function()
|
2010-06-18 13:48:42 -07:00
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
ok(false, "onerror called on test " + e.target._testNumber + "!");
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onmessage = function(e)
|
|
|
|
{
|
|
|
|
ok(e.data == "server data", "Bad message in test 17");
|
|
|
|
status_test17 = "got message";
|
|
|
|
forcegc();
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
ok(status_test17 == "got message", "Didn't got message in test 17!");
|
|
|
|
shouldCloseCleanly(e);
|
|
|
|
status_test17 = "closed";
|
|
|
|
forcegc();
|
2010-06-18 13:48:42 -07:00
|
|
|
doTest(18);
|
2010-06-27 14:09:29 -07:00
|
|
|
forcegc();
|
2010-06-18 13:48:42 -07:00
|
|
|
};
|
2010-06-27 14:09:29 -07:00
|
|
|
|
|
|
|
local_ws = null;
|
|
|
|
window._test17 = null;
|
|
|
|
forcegc();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test17()
|
|
|
|
{
|
|
|
|
window._test17();
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
// The tests that expects that their websockets neither open nor close MUST
|
|
|
|
// be in the end of the tests, i.e. HERE, in order to prevent blocking the other
|
|
|
|
// tests.
|
|
|
|
|
2010-06-18 13:48:42 -07:00
|
|
|
function test18()
|
|
|
|
{
|
2010-06-27 14:09:29 -07:00
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket_http_resource.txt");
|
|
|
|
ws.onopen = shouldNotOpen;
|
2010-07-01 09:35:57 -07:00
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseNotCleanly(e);
|
|
|
|
doTest(19);
|
|
|
|
};
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test19()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 19");
|
|
|
|
ws.onopen = shouldNotOpen;
|
2010-07-01 09:35:57 -07:00
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseNotCleanly(e);
|
|
|
|
doTest(20);
|
|
|
|
};
|
2010-06-18 13:48:42 -07:00
|
|
|
}
|
|
|
|
|
2010-06-27 14:09:29 -07:00
|
|
|
window._test20 = function()
|
|
|
|
{
|
|
|
|
var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 20");
|
2010-07-12 19:31:20 -07:00
|
|
|
local_ws._testNumber = "local20";
|
2010-07-01 09:35:57 -07:00
|
|
|
current_test++;
|
2010-06-27 14:09:29 -07:00
|
|
|
|
|
|
|
local_ws.onerror = function()
|
|
|
|
{
|
|
|
|
ok(false, "onerror called on test " + e.target._testNumber + "!");
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onclose = shouldNotReceiveCloseEvent;
|
|
|
|
|
|
|
|
local_ws = null;
|
|
|
|
window._test20 = null;
|
|
|
|
forcegc();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test20()
|
|
|
|
{
|
|
|
|
window._test20();
|
|
|
|
doTest(21);
|
|
|
|
}
|
|
|
|
|
|
|
|
var timeoutTest21;
|
|
|
|
|
|
|
|
window._test21 = function()
|
|
|
|
{
|
|
|
|
var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 21");
|
2010-07-01 09:35:57 -07:00
|
|
|
current_test++;
|
2010-06-27 14:09:29 -07:00
|
|
|
|
|
|
|
local_ws.onopen = function(e)
|
|
|
|
{
|
|
|
|
e.target.send("client data");
|
|
|
|
timeoutTest21 = setTimeout(function()
|
|
|
|
{
|
|
|
|
ok(false, "Didn't received message on test 21!");
|
|
|
|
}, 15000);
|
|
|
|
forcegc();
|
|
|
|
e.target.onopen = null;
|
|
|
|
forcegc();
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onerror = function()
|
|
|
|
{
|
|
|
|
ok(false, "onerror called on test " + e.target._testNumber + "!");
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onmessage = function(e)
|
|
|
|
{
|
|
|
|
clearTimeout(timeoutTest21);
|
|
|
|
ok(e.data == "server data", "Bad message in test 21");
|
|
|
|
forcegc();
|
|
|
|
e.target.onmessage = null;
|
|
|
|
forcegc();
|
|
|
|
};
|
|
|
|
|
|
|
|
local_ws.onclose = shouldNotReceiveCloseEvent;
|
|
|
|
|
|
|
|
local_ws = null;
|
|
|
|
window._test21 = null;
|
|
|
|
forcegc();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test21()
|
|
|
|
{
|
|
|
|
window._test21();
|
|
|
|
doTest(22);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test22()
|
|
|
|
{
|
|
|
|
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test 22");
|
|
|
|
ws.onopen = shouldNotOpen;
|
2010-07-01 09:35:57 -07:00
|
|
|
ws.onclose = function(e)
|
|
|
|
{
|
|
|
|
shouldCloseNotCleanly(e);
|
|
|
|
doTest(23);
|
|
|
|
};
|
2010-06-27 14:09:29 -07:00
|
|
|
}
|
|
|
|
|
2010-06-18 13:48:42 -07:00
|
|
|
function finishWSTest()
|
|
|
|
{
|
|
|
|
for (i = 0; i < all_ws.length; ++i) {
|
2010-07-01 09:35:57 -07:00
|
|
|
if (all_ws[i] != shouldNotReceiveCloseEvent &&
|
|
|
|
!all_ws[i]._receivedCloseEvent) {
|
2010-06-18 13:48:42 -07:00
|
|
|
ok(false, "didn't called close on test " + all_ws[i]._testNumber + "!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testWebSocket ()
|
|
|
|
{
|
|
|
|
doTest(first_test);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<div id="feedback">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|