mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Lightly massage some of the generated JavaScript
This commit is contained in:
parent
31ad9566e6
commit
1867a3f121
19 changed files with 986 additions and 989 deletions
|
@ -1,62 +1,43 @@
|
|||
// Generated by CoffeeScript 2.4.1
|
||||
/*
|
||||
jasmine tests for Snowflake
|
||||
*/
|
||||
var FakeBroker, PeerConnection, SessionDescription, WebSocket, config, log, ui;
|
||||
|
||||
// Fake browser functionality:
|
||||
PeerConnection = class PeerConnection {
|
||||
class PeerConnection {
|
||||
setRemoteDescription() {
|
||||
return true;
|
||||
}
|
||||
|
||||
send(data) {}
|
||||
|
||||
};
|
||||
|
||||
SessionDescription = (function() {
|
||||
class SessionDescription {};
|
||||
class SessionDescription {};
|
||||
SessionDescription.prototype.type = 'offer';
|
||||
|
||||
SessionDescription.prototype.type = 'offer';
|
||||
class WebSocket {
|
||||
constructor() {
|
||||
this.bufferedAmount = 0;
|
||||
}
|
||||
send(data) {}
|
||||
};
|
||||
WebSocket.prototype.OPEN = 1;
|
||||
WebSocket.prototype.CLOSED = 0;
|
||||
|
||||
return SessionDescription;
|
||||
var log = function() {};
|
||||
|
||||
}).call(this);
|
||||
var config = new Config;
|
||||
|
||||
WebSocket = (function() {
|
||||
class WebSocket {
|
||||
constructor() {
|
||||
this.bufferedAmount = 0;
|
||||
}
|
||||
var ui = new UI;
|
||||
|
||||
send(data) {}
|
||||
|
||||
};
|
||||
|
||||
WebSocket.prototype.OPEN = 1;
|
||||
|
||||
WebSocket.prototype.CLOSED = 0;
|
||||
|
||||
return WebSocket;
|
||||
|
||||
}).call(this);
|
||||
|
||||
log = function() {};
|
||||
|
||||
config = new Config;
|
||||
|
||||
ui = new UI;
|
||||
|
||||
FakeBroker = class FakeBroker {
|
||||
class FakeBroker {
|
||||
getClientOffer() {
|
||||
return new Promise(function(F, R) {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
describe('Snowflake', function() {
|
||||
|
||||
it('constructs correctly', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, {
|
||||
|
@ -67,22 +48,25 @@ describe('Snowflake', function() {
|
|||
fake: 'broker'
|
||||
});
|
||||
expect(s.ui).not.toBeNull();
|
||||
return expect(s.retries).toBe(0);
|
||||
expect(s.retries).toBe(0);
|
||||
});
|
||||
|
||||
it('sets relay address correctly', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, null);
|
||||
s.setRelayAddr('foo');
|
||||
return expect(s.relayAddr).toEqual('foo');
|
||||
expect(s.relayAddr).toEqual('foo');
|
||||
});
|
||||
|
||||
it('initalizes WebRTC connection', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
spyOn(s.broker, 'getClientOffer').and.callThrough();
|
||||
s.beginWebRTC();
|
||||
expect(s.retries).toBe(1);
|
||||
return expect(s.broker.getClientOffer).toHaveBeenCalled();
|
||||
expect(s.broker.getClientOffer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('receives SDP offer and sends answer', function() {
|
||||
var pair, s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
|
@ -92,8 +76,9 @@ describe('Snowflake', function() {
|
|||
spyOn(pair, 'receiveWebRTCOffer').and.returnValue(true);
|
||||
spyOn(s, 'sendAnswer');
|
||||
s.receiveOffer(pair, '{"type":"offer","sdp":"foo"}');
|
||||
return expect(s.sendAnswer).toHaveBeenCalled();
|
||||
expect(s.sendAnswer).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not send answer when receiving invalid offer', function() {
|
||||
var pair, s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
|
@ -103,12 +88,14 @@ describe('Snowflake', function() {
|
|||
spyOn(pair, 'receiveWebRTCOffer').and.returnValue(false);
|
||||
spyOn(s, 'sendAnswer');
|
||||
s.receiveOffer(pair, '{"type":"not a good offer","sdp":"foo"}');
|
||||
return expect(s.sendAnswer).not.toHaveBeenCalled();
|
||||
expect(s.sendAnswer).not.toHaveBeenCalled();
|
||||
});
|
||||
return it('can make a proxypair', function() {
|
||||
|
||||
it('can make a proxypair', function() {
|
||||
var s;
|
||||
s = new Snowflake(config, ui, new FakeBroker());
|
||||
s.makeProxyPair();
|
||||
return expect(s.proxyPairs.length).toBe(1);
|
||||
expect(s.proxyPairs.length).toBe(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue