OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 var testUsername = 'testUsername@gmail.com'; | 9 var testUsername = 'testUsername@gmail.com'; |
10 var testToken = 'testToken'; | 10 var testToken = 'testToken'; |
11 | 11 |
12 var sendMessage = null; | 12 /** @type {(sinon.$spy|function(string):void)} */ |
13 var startTls = null; | 13 var sendMessage = function(msg) {}; |
14 var onHandshakeDone = null; | 14 |
15 var onStanzaStr = null; | 15 /** @type {(sinon.$spy|function():void)} */ |
16 var onError = null; | 16 var startTls = function() {}; |
| 17 |
| 18 /** @type {(sinon.$spy|function(string, remoting.XmppStreamParser):void)} */ |
| 19 var onHandshakeDone = function(name, parser) {}; |
| 20 |
| 21 /** @type {(sinon.$spy|function(remoting.Error, string):void)} */ |
| 22 var onError = function(error, message) {}; |
| 23 |
| 24 /** @type {remoting.XmppLoginHandler} */ |
17 var loginHandler = null; | 25 var loginHandler = null; |
18 | 26 |
19 module('XmppLoginHandler', { | 27 module('XmppLoginHandler', { |
20 setup: function() { | 28 setup: function() { |
21 sendMessage = sinon.spy(); | 29 sendMessage = sinon.spy(); |
22 startTls = sinon.spy(); | 30 startTls = sinon.spy(); |
23 onHandshakeDone = sinon.spy(); | 31 onHandshakeDone = sinon.spy(); |
24 onError = sinon.spy(); | 32 onError = sinon.spy(); |
| 33 |
25 loginHandler = new remoting.XmppLoginHandler( | 34 loginHandler = new remoting.XmppLoginHandler( |
26 'google.com', testUsername, testToken, false, sendMessage, | 35 'google.com', testUsername, testToken, false, |
27 startTls, onHandshakeDone, onError); | 36 /** @type {function(string):void} */ (sendMessage), |
| 37 /** @type {function():void} */ (startTls), |
| 38 /** @type {function(string, remoting.XmppStreamParser):void} */ |
| 39 (onHandshakeDone), |
| 40 /** @type {function(remoting.Error, string):void} */ (onError)); |
28 } | 41 } |
29 }); | 42 }); |
30 | 43 |
31 // Executes handshake base. | 44 // Executes handshake base. |
32 function handshakeBase() { | 45 function handshakeBase() { |
33 loginHandler.start(); | 46 loginHandler.start(); |
34 | 47 |
35 sinon.assert.calledWith(startTls); | 48 sinon.assert.calledWith(startTls); |
36 startTls.reset(); | 49 startTls.reset(); |
37 | 50 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 157 |
145 test('should return UNEXPECTED error when failed to parse stream', | 158 test('should return UNEXPECTED error when failed to parse stream', |
146 function() { | 159 function() { |
147 handshakeBase(); | 160 handshakeBase(); |
148 loginHandler.onDataReceived( | 161 loginHandler.onDataReceived( |
149 base.encodeUtf8('BAD DATA')); | 162 base.encodeUtf8('BAD DATA')); |
150 sinon.assert.calledWith(onError, remoting.Error.UNEXPECTED); | 163 sinon.assert.calledWith(onError, remoting.Error.UNEXPECTED); |
151 }); | 164 }); |
152 | 165 |
153 })(); | 166 })(); |
OLD | NEW |