Chromium Code Reviews| Index: remoting/webapp/crd/js/xmpp_connection_unittest.js |
| diff --git a/remoting/webapp/crd/js/xmpp_connection_unittest.js b/remoting/webapp/crd/js/xmpp_connection_unittest.js |
| index f631e2bd8728d182701d5e9a0d9a31db16c7832d..f1ac39b839f70cde94957929d5b16453100a70d2 100644 |
| --- a/remoting/webapp/crd/js/xmpp_connection_unittest.js |
| +++ b/remoting/webapp/crd/js/xmpp_connection_unittest.js |
| @@ -35,8 +35,8 @@ function expectNextState(/** remoting.SignalStrategy.State */ expectedState) { |
| }); |
| } |
| -module('XmppConnection', { |
| - setup: function() { |
| +QUnit.module('XmppConnection', { |
| + beforeEach: function() { |
| onStanzaStr = sinon.spy(); |
| /** @param {Element} stanza */ |
| function onStanza(stanza) { |
| @@ -53,7 +53,9 @@ module('XmppConnection', { |
| } |
| }); |
| -QUnit.asyncTest('should go to FAILED state when failed to connect', function() { |
| +QUnit.test('should go to FAILED state when failed to connect', |
| + function(assert) { |
| + var done = assert.async(); |
| $testStub(socket.connect).withArgs("xmpp.example.com", 123) |
| .returns(new Promise(function(resolve, reject) { reject(-1); })); |
| @@ -71,12 +73,12 @@ QUnit.asyncTest('should go to FAILED state when failed to connect', function() { |
| function onFailed() { |
| sinon.assert.calledWith(socket.dispose); |
| QUnit.ok(connection.getError().hasTag(remoting.Error.Tag.NETWORK_FAILURE)); |
| - |
| - QUnit.start(); |
| + done(); |
| } |
| }); |
| -QUnit.asyncTest('should use XmppLoginHandler for handshake', function() { |
| +QUnit.test('should use XmppLoginHandler for handshake', function() { |
| + |
| $testStub(socket.connect).withArgs("xmpp.example.com", 123) |
| .returns(new Promise(function(resolve, reject) { resolve(0) })); |
| @@ -86,24 +88,17 @@ QUnit.asyncTest('should use XmppLoginHandler for handshake', function() { |
| var parser = new remoting.XmppStreamParser(); |
| var parserMock = sinon.mock(parser); |
| var setCallbacksCalled = parserMock.expects('setCallbacks').once(); |
| + var State = remoting.SignalStrategy.State; |
| - expectNextState(remoting.SignalStrategy.State.CONNECTING).then(onConnecting); |
| - connection.connect( |
| - 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken'); |
| - |
| - function onConnecting() { |
| - expectNextState(remoting.SignalStrategy.State.HANDSHAKE).then(onHandshake); |
| - } |
| - |
| - function onHandshake() { |
| + var promise = expectNextState(State.CONNECTING).then(function() { |
| + return expectNextState(State.HANDSHAKE); |
| + }).then(function() { |
| var handshakeDoneCallback = |
| connection.loginHandler_.getHandshakeDoneCallbackForTesting(); |
| - |
| - expectNextState(remoting.SignalStrategy.State.CONNECTED).then(onConnected); |
| + var onConnected = expectNextState(State.CONNECTED); |
| handshakeDoneCallback('test@example.com/123123', parser); |
| - } |
| - |
| - function onConnected() { |
| + return onConnected; |
| + }).then(function() { |
| setCallbacksCalled.verify(); |
| // Simulate read() callback with |data|. It should be passed to |
| @@ -114,9 +109,11 @@ QUnit.asyncTest('should use XmppLoginHandler for handshake', function() { |
| parserMock.expects('appendData').once().withArgs(data); |
| $testStub(socket.startReceiving).getCall(0).args[0](data); |
| appendDataCalled.verify(); |
| + }); |
| - QUnit.start(); |
| - } |
| + connection.connect( |
| + 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken'); |
|
John Williams
2015/03/17 19:22:37
Would it still work to put this call before the cr
|
| + return promise; |
| }); |
| })(); |