Add more websocket tests
This commit is contained in:
parent
cc6a44f35d
commit
e4b49bde51
2 changed files with 43 additions and 11 deletions
|
@ -47,8 +47,8 @@
|
||||||
|
|
||||||
<script type="text/javascript" src="fake_api.js"></script>
|
<script type="text/javascript" src="fake_api.js"></script>
|
||||||
<script type="text/javascript" src="helpers_test.js"></script>
|
<script type="text/javascript" src="helpers_test.js"></script>
|
||||||
<script type="text/javascript" src="websocket_test.js"></script>
|
|
||||||
<script type="text/javascript" src="websocket-resources_test.js"></script>
|
<script type="text/javascript" src="websocket-resources_test.js"></script>
|
||||||
<script type="text/javascript" src="protocol_test.js"></script>
|
<script type="text/javascript" src="protocol_test.js"></script>
|
||||||
|
<script type="text/javascript" src="websocket_test.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -28,21 +28,36 @@ describe('TextSecureWebSocket', function() {
|
||||||
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends a keepalive once a minute', function(done) {
|
it('sends and receives', function(done) {
|
||||||
this.timeout(60000);
|
var mockServer = new MockServer('ws://localhost:8080');
|
||||||
var mockServer = new MockServer('ws://localhost:8081');
|
|
||||||
mockServer.on('connection', function(server) {
|
mockServer.on('connection', function(server) {
|
||||||
server.on('message', function(data) {
|
server.on('message', function(data) {
|
||||||
var message = textsecure.protobuf.WebSocketMessage.decode(data);
|
server.send('ack');
|
||||||
assert.strictEqual(message.type, textsecure.protobuf.WebSocketMessage.Type.REQUEST);
|
|
||||||
assert.strictEqual(message.request.verb, 'GET');
|
|
||||||
assert.strictEqual(message.request.path, '/v1/keepalive');
|
|
||||||
socket.close();
|
|
||||||
server.close();
|
server.close();
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var socket = new TextSecureWebSocket('ws://localhost:8081');
|
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
||||||
|
socket.onmessage = function(response) {
|
||||||
|
assert.strictEqual(response.data, 'ack');
|
||||||
|
socket.close();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
socket.send('syn');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('exposes the socket status', function(done) {
|
||||||
|
var mockServer = new MockServer('ws://localhost:8082');
|
||||||
|
mockServer.on('connection', function(server) {
|
||||||
|
assert.strictEqual(socket.getStatus(), WebSocket.OPEN);
|
||||||
|
server.close();
|
||||||
|
socket.close();
|
||||||
|
});
|
||||||
|
var socket = new TextSecureWebSocket('ws://localhost:8082');
|
||||||
|
socket.onclose = function() {
|
||||||
|
assert.strictEqual(socket.getStatus(), WebSocket.CLOSING);
|
||||||
|
done();
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reconnects', function(done) {
|
it('reconnects', function(done) {
|
||||||
|
@ -59,4 +74,21 @@ describe('TextSecureWebSocket', function() {
|
||||||
};
|
};
|
||||||
mockServer.close();
|
mockServer.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('sends a keepalive once a minute', function(done) {
|
||||||
|
this.timeout(60000);
|
||||||
|
var mockServer = new MockServer('ws://localhost:8081');
|
||||||
|
mockServer.on('connection', function(server) {
|
||||||
|
server.on('message', function(data) {
|
||||||
|
var message = textsecure.protobuf.WebSocketMessage.decode(data);
|
||||||
|
assert.strictEqual(message.type, textsecure.protobuf.WebSocketMessage.Type.REQUEST);
|
||||||
|
assert.strictEqual(message.request.verb, 'GET');
|
||||||
|
assert.strictEqual(message.request.path, '/v1/keepalive');
|
||||||
|
socket.close();
|
||||||
|
server.close();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var socket = new TextSecureWebSocket('ws://localhost:8081');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue