Cable-Desktop/libtextsecure/test/websocket_test.js
lilia f764445c86 Remove erroneous license file and headers
We only use GPLV3 around here.

// FREEBIE
2015-09-07 14:58:42 -07:00

66 baris
2,2 KiB
JavaScript

/*
* vim: ts=4:sw=4:expandtab
*/
describe('TextSecureWebSocket', function() {
var RealWebSocket = window.WebSocket;
before(function() { window.WebSocket = MockSocket; });
after (function() { window.WebSocket = RealWebSocket; });
it('connects and disconnects', function(done) {
var mockServer = new MockServer('ws://localhost:8080');
mockServer.on('connection', function(server) {
socket.close();
server.close();
done();
});
var socket = new TextSecureWebSocket('ws://localhost:8080');
});
it('sends and receives', function(done) {
var mockServer = new MockServer('ws://localhost:8080');
mockServer.on('connection', function(server) {
server.on('message', function(data) {
server.send('ack');
server.close();
});
});
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) {
this.timeout(60000);
var mockServer = new MockServer('ws://localhost:8082');
var socket = new TextSecureWebSocket('ws://localhost:8082');
socket.onclose = function() {
var mockServer = new MockServer('ws://localhost:8082');
mockServer.on('connection', function(server) {
socket.close();
server.close();
done();
});
};
mockServer.close();
});
});