summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2019-07-03 15:55:46 +0200
committerPierre Ossman <ossman@cendio.se>2019-07-03 15:56:25 +0200
commit60acf3cd3cedbaf20671d2e2decf6117acb64faf (patch)
treef62e97f715cc9b500a31144c9f9c9ec517a3a7c9 /tests
parentb46fab5608c9199f5336ed3a851e59b084dde842 (diff)
downloadwebsockify-60acf3cd3cedbaf20671d2e2decf6117acb64faf.tar.gz
Use direct javascript in test files
Avoid relying on our own modules as we are about to split things up.
Diffstat (limited to 'tests')
-rw-r--r--tests/echo.html54
-rw-r--r--tests/latency.html67
-rw-r--r--tests/load.html66
-rw-r--r--tests/plain_echo.html59
-rw-r--r--tests/simple.html36
5 files changed, 124 insertions, 158 deletions
diff --git a/tests/echo.html b/tests/echo.html
index 8cc7ecb..0e300b5 100644
--- a/tests/echo.html
+++ b/tests/echo.html
@@ -2,16 +2,6 @@
<head>
<title>WebSockets Echo Test</title>
- <script src="include/util.js"></script>
- <script src="include/webutil.js"></script>
- <script src="include/websock.js"></script>
- <!-- Uncomment to activate firebug lite -->
- <!--
- <script type='text/javascript'
- src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
- -->
-
-
</head>
<body>
@@ -36,7 +26,7 @@
function message(str) {
console.log(str);
- cell = $D('messages');
+ cell = document.getElementById('messages');
cell.innerHTML += msg_cnt + ": " + str + "\n";
cell.scrollTop = cell.scrollHeight;
msg_cnt++;
@@ -51,20 +41,21 @@
function send_msg() {
var str = "Message #" + send_cnt;
- ws.send_string(str);
+ var encoder = new TextEncoder();
+ ws.send(encoder.encode(str));
message("Sent message: '" + str + "'");
send_cnt++;
}
function update_stats() {
- $D('sent').innerHTML = sent;
- $D('received').innerHTML = received;
- $D('errors').innerHTML = errors;
+ document.getElementById('sent').innerHTML = sent;
+ document.getElementById('received').innerHTML = received;
+ document.getElementById('errors').innerHTML = errors;
}
function connect() {
- var host = $D('host').value,
- port = $D('port').value,
+ var host = document.getElementById('host').value,
+ port = document.getElementById('port').value,
scheme = "ws://", uri;
console.log(">> connect");
@@ -77,28 +68,29 @@
ws.close();
}
- if ($D('encrypt').checked) {
+ if (document.getElementById('encrypt').checked) {
scheme = "wss://";
}
uri = scheme + host + ":" + port;
message("connecting to " + uri);
- ws = new Websock();
- ws.open(uri);
+ ws = new WebSocket(uri);
+ ws.binaryType = 'arraybuffer';
- ws.on('message', function(e) {
+ ws.addEventListener('message', function(e) {
//console.log(">> WebSockets.onmessage");
- var str = ws.rQshiftStr();
+ var decoder = new TextDecoder('UTF-8');
+ var str = decoder.decode(e.data);
message("Received message '" + str + "'");
//console.log("<< WebSockets.onmessage");
});
- ws.on('open', function(e) {
+ ws.addEventListener('open', function(e) {
console.log(">> WebSockets.onopen");
echo_ref = setInterval(send_msg, echoDelay);
console.log("<< WebSockets.onopen");
});
- ws.on('close', function(e) {
+ ws.addEventListener('close', function(e) {
console.log(">> WebSockets.onclose");
if (echo_ref) {
clearInterval(echo_ref);
@@ -106,7 +98,7 @@
}
console.log("<< WebSockets.onclose");
});
- ws.on('error', function(e) {
+ ws.addEventListener('error', function(e) {
console.log(">> WebSockets.onerror");
if (echo_ref) {
clearInterval(echo_ref);
@@ -115,8 +107,8 @@
console.log("<< WebSockets.onerror");
});
- $D('connectButton').value = "Stop";
- $D('connectButton').onclick = disconnect;
+ document.getElementById('connectButton').value = "Stop";
+ document.getElementById('connectButton').onclick = disconnect;
console.log("<< connect");
}
@@ -130,8 +122,8 @@
clearInterval(echo_ref);
}
- $D('connectButton').value = "Start";
- $D('connectButton').onclick = connect;
+ document.getElementById('connectButton').value = "Start";
+ document.getElementById('connectButton').onclick = connect;
console.log("<< disconnect");
}
@@ -139,8 +131,8 @@
window.onload = function() {
console.log("onload");
var url = document.location.href;
- $D('host').value = (url.match(/host=([^&#]*)/) || ['',window.location.hostname])[1];
- $D('port').value = (url.match(/port=([^&#]*)/) || ['',window.location.port])[1];
+ document.getElementById('host').value = (url.match(/host=([^&#]*)/) || ['',window.location.hostname])[1];
+ document.getElementById('port').value = (url.match(/port=([^&#]*)/) || ['',window.location.port])[1];
}
</script>
diff --git a/tests/latency.html b/tests/latency.html
index 90136a3..9904a02 100644
--- a/tests/latency.html
+++ b/tests/latency.html
@@ -2,16 +2,6 @@
<head>
<title>WebSockets Latency Test</title>
- <script src="include/util.js"></script>
- <script src="include/webutil.js"></script>
- <script src="include/websock.js"></script>
- <!-- Uncomment to activate firebug lite -->
- <!--
- <script type='text/javascript'
- src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
- -->
-
-
</head>
<body>
@@ -73,7 +63,7 @@
function message(str) {
console.log(str);
- cell = $D('messages');
+ cell = document.getElementById('messages');
msg_cnt++;
cell.innerHTML += msg_cnt + ": " + str + "\n";
cell.scrollTop = cell.scrollHeight;
@@ -90,7 +80,7 @@
now = (new Date()).getTime(); // Early as possible
- arr = ws.rQshiftBytes(ws.rQlen());
+ arr = new Uint8Array(data);
first = String.fromCharCode(arr[0]);
last = String.fromCharCode(arr[arr.length-1]);
@@ -156,7 +146,7 @@
timestamp = (new Date()).getTime();
arr.pushStr("^" + send_seq + ":" + timestamp + ":" + payload + "$");
send_seq ++;
- ws.send(arr);
+ ws.send(new Uint8Array(arr));
sent++;
showStats();
@@ -164,36 +154,35 @@
}
function showStats() {
- $D('sent').innerHTML = sent;
- $D('received').innerHTML = received;
- $D('laverage').innerHTML = laverage.toFixed(2);
- $D('lrunning').innerHTML = lrunning.toFixed(2);
- $D('lmin').innerHTML = lmin.toFixed(2);
- $D('lmax').innerHTML = lmax.toFixed(2);
+ document.getElementById('sent').innerHTML = sent;
+ document.getElementById('received').innerHTML = received;
+ document.getElementById('laverage').innerHTML = laverage.toFixed(2);
+ document.getElementById('lrunning').innerHTML = lrunning.toFixed(2);
+ document.getElementById('lmin').innerHTML = lmin.toFixed(2);
+ document.getElementById('lmax').innerHTML = lmax.toFixed(2);
}
function init_ws() {
console.log(">> init_ws");
var scheme = "ws://";
- if ($D('encrypt').checked) {
+ if (document.getElementById('encrypt').checked) {
scheme = "wss://";
}
var uri = scheme + host + ":" + port;
console.log("connecting to " + uri);
- ws = new Websock();
- ws.maxBufferedAmount = 5000;
- ws.open(uri);
+ ws = new WebSocket(uri);
+ ws.binaryType = 'arraybuffer';
- ws.on('message', function() {
- recvMsg();
+ ws.addEventListener('message', function(e) {
+ recvMsg(e.data);
});
- ws.on('open', function() {
+ ws.addEventListener('open', function() {
send_ref = setTimeout(sendMsg, sendDelay);
});
- ws.on('close', function(e) {
+ ws.addEventListener('close', function(e) {
disconnect();
});
- ws.on('error', function(e) {
+ ws.addEventListener('error', function(e) {
message("Websock error: " + e);
disconnect();
});
@@ -203,10 +192,10 @@
function connect() {
console.log(">> connect");
- host = $D('host').value;
- port = $D('port').value;
- payload_size = parseInt($D('payload_size').value, 10);
- sendDelay = parseInt($D('sendDelay').value, 10);
+ host = document.getElementById('host').value;
+ port = document.getElementById('port').value;
+ payload_size = parseInt(document.getElementById('payload_size').value, 10);
+ sendDelay = parseInt(document.getElementById('sendDelay').value, 10);
if ((!host) || (!port)) {
console.log("must set host and port");
@@ -235,8 +224,8 @@
lmin = 999999999;
lmax = 0;
- $D('connectButton').value = "Stop";
- $D('connectButton').onclick = disconnect;
+ document.getElementById('connectButton').value = "Stop";
+ document.getElementById('connectButton').onclick = disconnect;
console.log("<< connect");
}
@@ -254,8 +243,8 @@
recv_seq = 0;
send_seq = 0;
- $D('connectButton').value = "Start";
- $D('connectButton').onclick = connect;
+ document.getElementById('connectButton').value = "Start";
+ document.getElementById('connectButton').onclick = connect;
console.log("<< disconnect");
}
@@ -263,9 +252,9 @@
window.onload = function() {
console.log("onload");
var url = document.location.href;
- $D('host').value = (url.match(/host=([^&#]*)/) || ['',window.location.hostname])[1];
- $D('port').value = (url.match(/port=([^&#]*)/) || ['',window.location.port])[1];
- $D('payload_size').value = payload_size;
+ document.getElementById('host').value = (url.match(/host=([^&#]*)/) || ['',window.location.hostname])[1];
+ document.getElementById('port').value = (url.match(/port=([^&#]*)/) || ['',window.location.port])[1];
+ document.getElementById('payload_size').value = payload_size;
}
</script>
diff --git a/tests/load.html b/tests/load.html
index 11a6927..cb55041 100644
--- a/tests/load.html
+++ b/tests/load.html
@@ -2,16 +2,6 @@
<head>
<title>WebSockets Load Test</title>
- <script src="include/util.js"></script>
- <script src="include/webutil.js"></script>
- <script src="include/websock.js"></script>
- <!-- Uncomment to activate firebug lite -->
- <!--
- <script type='text/javascript'
- src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
- -->
-
-
</head>
<body>
@@ -47,7 +37,7 @@
function error(str) {
console.error(str);
- cell = $D('error');
+ cell = document.getElementById('error');
cell.innerHTML += errors + ": " + str + "\n";
cell.scrollTop = cell.scrollHeight;
}
@@ -74,8 +64,8 @@
function check_respond(data) {
//console.log(">> check_respond");
var first, last, str, length, chksum, nums, arr;
- first = String.fromCharCode(data.shift());
- last = String.fromCharCode(data.pop());
+ first = String.fromCharCode(data[0]);
+ last = String.fromCharCode(data[data.length-1]);
if (first != "^") {
errors++;
@@ -87,9 +77,11 @@
error("Packet missing end char '$'");
return;
}
- arr = data.map(function(num) {
- return String.fromCharCode(num);
- } ).join('').split(':');
+ text = ''
+ for (var i = 1; i < data.length-1; i++) {
+ text += String.fromCharCode(data[i]);
+ }
+ arr = text.split(':');
seq = arr[0];
length = arr[1];
chksum = arr[2];
@@ -137,44 +129,44 @@
var nums = numlist.join('');
arr.pushStr("^" + send_seq + ":" + length + ":" + chksum + ":" + nums + "$")
send_seq ++;
- ws.send(arr);
+ ws.send(new Uint8Array(arr));
sent++;
}
function update_stats() {
- $D('sent').innerHTML = sent;
- $D('received').innerHTML = received;
- $D('errors').innerHTML = errors;
+ document.getElementById('sent').innerHTML = sent;
+ document.getElementById('received').innerHTML = received;
+ document.getElementById('errors').innerHTML = errors;
}
function init_ws() {
console.log(">> init_ws");
var scheme = "ws://";
- if ($D('encrypt').checked) {
+ if (document.getElementById('encrypt').checked) {
scheme = "wss://";
}
var uri = scheme + host + ":" + port;
console.log("connecting to " + uri);
- ws = new Websock();
- ws.open(uri);
+ ws = new WebSocket(uri);
+ ws.binaryType = 'arraybuffer';
- ws.on('message', function() {
+ ws.addEventListener('message', function(e) {
//console.log(">> WebSockets.onmessage");
- arr = ws.rQshiftBytes(ws.rQlen());
+ arr = new Uint8Array(e.data);
check_respond(arr);
//console.log("<< WebSockets.onmessage");
});
- ws.on('open', function() {
+ ws.addEventListener('open', function() {
console.log(">> WebSockets.onopen");
send_ref = setInterval(send, sendDelay);
console.log("<< WebSockets.onopen");
});
- ws.on('close', function(e) {
+ ws.addEventListener('close', function(e) {
console.log(">> WebSockets.onclose");
clearInterval(send_ref);
console.log("<< WebSockets.onclose");
});
- ws.on('error', function(e) {
+ ws.addEventListener('error', function(e) {
console.log(">> WebSockets.onerror");
console.log(" " + e);
console.log("<< WebSockets.onerror");
@@ -185,9 +177,9 @@
function connect() {
console.log(">> connect");
- host = $D('host').value;
- port = $D('port').value;
- sendDelay = parseInt($D('sendDelay').value, 10);
+ host = document.getElementById('host').value;
+ port = document.getElementById('port').value;
+ sendDelay = parseInt(document.getElementById('sendDelay').value, 10);
if ((!host) || (!port)) {
console.log("must set host and port");
return;
@@ -199,8 +191,8 @@
init_ws();
update_ref = setInterval(update_stats, 1);
- $D('connectButton').value = "Stop";
- $D('connectButton').onclick = disconnect;
+ document.getElementById('connectButton').value = "Stop";
+ document.getElementById('connectButton').onclick = disconnect;
console.log("<< connect");
}
@@ -215,16 +207,16 @@
recv_seq = 0;
send_seq = 0;
- $D('connectButton').value = "Start";
- $D('connectButton').onclick = connect;
+ document.getElementById('connectButton').value = "Start";
+ document.getElementById('connectButton').onclick = connect;
console.log("<< disconnect");
}
window.onload = function() {
console.log("onload");
var url = document.location.href;
- $D('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1];
- $D('port').value = (url.match(/port=([^&#]*)/) || ['',''])[1];
+ document.getElementById('host').value = (url.match(/host=([^&#]*)/) || ['',window.location.hostname])[1];
+ document.getElementById('port').value = (url.match(/port=([^&#]*)/) || ['',window.location.port])[1];
}
</script>
diff --git a/tests/plain_echo.html b/tests/plain_echo.html
index 6d9a560..be35e54 100644
--- a/tests/plain_echo.html
+++ b/tests/plain_echo.html
@@ -2,15 +2,6 @@
<head>
<title>WebSockets Echo Test</title>
- <script src="include/util.js"></script>
- <script src="include/webutil.js"></script>
- <!-- Uncomment to activate firebug lite -->
- <!--
- <script type='text/javascript'
- src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
- -->
-
-
</head>
<body>
@@ -35,7 +26,7 @@
function message(str) {
console.log(str);
- cell = $D('messages');
+ cell = document.getElementById('messages');
cell.innerHTML += msg_cnt + ": " + str + "\n";
cell.scrollTop = cell.scrollHeight;
msg_cnt++;
@@ -54,15 +45,16 @@
return;
}
var str = "Message #" + send_cnt, arr = [];
- ws.send(str);
+ var encoder = new TextEncoder();
+ ws.send(encoder.encode(str));
message("Sent message: '" + str + "'");
send_cnt++;
}
function update_stats() {
- $D('sent').innerHTML = sent;
- $D('received').innerHTML = received;
- $D('errors').innerHTML = errors;
+ document.getElementById('sent').innerHTML = sent;
+ document.getElementById('received').innerHTML = received;
+ document.getElementById('errors').innerHTML = errors;
}
function init_ws() {
@@ -71,8 +63,8 @@
}
function connect() {
- var host = $D('host').value,
- port = $D('port').value,
+ var host = document.getElementById('host').value,
+ port = document.getElementById('port').value,
scheme = "ws://", uri;
console.log(">> connect");
@@ -85,42 +77,45 @@
ws.close();
}
- if ($D('encrypt').checked) {
+ if (document.getElementById('encrypt').checked) {
scheme = "wss://";
}
uri = scheme + host + ":" + port;
message("connecting to " + uri);
ws = new WebSocket(uri);
+ ws.binaryType = 'arraybuffer';
- ws.onmessage = function(e) {
+ ws.addEventListener('message', function(e) {
//console.log(">> WebSockets.onmessage");
- message("Received message '" + e.data + "'");
+ var decoder = new TextDecoder('UTF-8');
+ var str = decoder.decode(e.data);
+ message("Received message '" + str + "'");
//console.log("<< WebSockets.onmessage");
- };
- ws.onopen = function(e) {
+ });
+ ws.addEventListener('open', function(e) {
console.log(">> WebSockets.onopen");
echo_ref = setInterval(send_msg, echoDelay);
console.log("<< WebSockets.onopen");
- };
- ws.onclose = function(e) {
+ });
+ ws.addEventListener('close', function(e) {
console.log(">> WebSockets.onclose");
if (echo_ref) {
clearInterval(echo_ref);
echo_ref = null;
}
console.log("<< WebSockets.onclose");
- };
- ws.onerror = function(e) {
+ });
+ ws.addEventListener('error', function(e) {
console.log(">> WebSockets.onerror");
if (echo_ref) {
clearInterval(echo_ref);
echo_ref = null;
}
console.log("<< WebSockets.onerror");
- };
+ });
- $D('connectButton').value = "Stop";
- $D('connectButton').onclick = disconnect;
+ document.getElementById('connectButton').value = "Stop";
+ document.getElementById('connectButton').onclick = disconnect;
console.log("<< connect");
}
@@ -134,16 +129,16 @@
clearInterval(echo_ref);
}
- $D('connectButton').value = "Start";
- $D('connectButton').onclick = connect;
+ document.getElementById('connectButton').value = "Start";
+ document.getElementById('connectButton').onclick = connect;
console.log("<< disconnect");
}
window.onload = function() {
console.log("onload");
var url = document.location.href;
- $D('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1];
- $D('port').value = (url.match(/port=([^&#]*)/) || ['',''])[1];
+ document.getElementById('host').value = (url.match(/host=([^&#]*)/) || ['',window.location.hostname])[1];
+ document.getElementById('port').value = (url.match(/port=([^&#]*)/) || ['',window.location.port])[1];
}
</script>
diff --git a/tests/simple.html b/tests/simple.html
index 1a20cc4..8f6a73f 100644
--- a/tests/simple.html
+++ b/tests/simple.html
@@ -2,8 +2,6 @@
<head>
<title>Websock Simple Client</title>
- <script src="include/util.js"></script>
- <script src="include/websock.js"></script>
</head>
<body>
@@ -20,8 +18,8 @@
<script>
- var $D = function(id) { return document.getElementById(id); },
- ws = null, msgs = $D('messages');
+ var document.getElementById = function(id) { return document.getElementById(id); },
+ ws = null, msgs = document.getElementById('messages');
function msg(str) {
msgs.innerHTML += str + "\n";
@@ -29,38 +27,38 @@
}
function connect() {
- var uri = $D('target').value;
- ws = new Websock()
+ var uri = document.getElementById('target').value;
msg("connecting to: " + uri);
- ws.open(uri);
- ws.on('open', function () {
+ ws = new WebSocket(uri);
+ ws.binaryType = 'arraybuffer';
+ ws.addEventListener('open', function () {
msg("Connected");
});
- ws.on('message', function () {
- msg("Received: " + ws.rQshiftStr());
+ ws.addEventListener('message', function (e) {
+ msg("Received: " + e.data);
});
- ws.on('close', function () {
+ ws.addEventListener('close', function () {
disconnect();
msg("Disconnected");
});
- $D('connectButton').value = "Disconnect";
- $D('connectButton').onclick = disconnect;
- $D('sendButton').disabled = false;
+ document.getElementById('connectButton').value = "Disconnect";
+ document.getElementById('connectButton').onclick = disconnect;
+ document.getElementById('sendButton').disabled = false;
}
function disconnect() {
if (ws) { ws.close(); }
ws = null;
- $D('connectButton').value = "Connect";
- $D('connectButton').onclick = connect;
- $D('sendButton').disabled = true;
+ document.getElementById('connectButton').value = "Connect";
+ document.getElementById('connectButton').onclick = connect;
+ document.getElementById('sendButton').disabled = true;
}
function send() {
- msg("Sending: " + $D('sendText').value);
- ws.send_string($D('sendText').value);
+ msg("Sending: " + document.getElementById('sendText').value);
+ ws.send_string(document.getElementById('sendText').value);
};
</script>