Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: remoting/webapp/unittests/xmpp_login_handler_unittest.js

Issue 959963002: [Chromoting] Enable jscompile for webapp unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix key tester Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_spy = function(msg) {};
14 var onHandshakeDone = null; 14 /** @type {function(string):void} */
15 var onStanzaStr = null; 15 var sendMessage = function(msg) {};
16 var onError = null; 16
17 /** @type {(sinon.Spy|function():void)} */
18 var startTls_spy = function() {};
19 /** @type {function():void} */
20 var startTls = function() {};
21
22 /** @type {(sinon.Spy|function(string, remoting.XmppStreamParser):void)} */
23 var onHandshakeDone_spy = function(name, parser) {};
24 /** @type {function(string, remoting.XmppStreamParser):void} */
25 var onHandshakeDone = function(name, parser) {};
26
27 /** @type {(sinon.Spy|function(remoting.Error, string):void)} */
28 var onError_spy = function(error, message) {};
29 /** @type {function(remoting.Error, string):void} */
30 var onError = function(error, message) {};
31
32 /** @type {remoting.XmppLoginHandler} */
17 var loginHandler = null; 33 var loginHandler = null;
18 34
19 module('XmppLoginHandler', { 35 module('XmppLoginHandler', {
20 setup: function() { 36 setup: function() {
21 sendMessage = sinon.spy(); 37 sendMessage_spy = sinon.spy();
22 startTls = sinon.spy(); 38 sendMessage = /** @type {function(string):void} */ (sendMessage_spy);
23 onHandshakeDone = sinon.spy(); 39 startTls_spy = sinon.spy();
24 onError = sinon.spy(); 40 startTls = /** @type {function():void} */ (startTls_spy);
41 onHandshakeDone_spy = sinon.spy();
42 onHandshakeDone =
43 /** @type {function(string, remoting.XmppStreamParser):void} */
44 (onHandshakeDone_spy);
45 onError_spy = sinon.spy();
46 onError = /** @type {function(remoting.Error, string):void} */(onError_spy);
47
25 loginHandler = new remoting.XmppLoginHandler( 48 loginHandler = new remoting.XmppLoginHandler(
26 'google.com', testUsername, testToken, false, sendMessage, 49 'google.com', testUsername, testToken, false,
27 startTls, onHandshakeDone, onError); 50 sendMessage, startTls, onHandshakeDone, onError);
28 } 51 }
29 }); 52 });
30 53
31 // Executes handshake base. 54 // Executes handshake base.
32 function handshakeBase() { 55 function handshakeBase() {
33 loginHandler.start(); 56 loginHandler.start();
34 57
35 sinon.assert.calledWith(startTls); 58 sinon.assert.calledWith(startTls);
36 startTls.reset(); 59 startTls_spy.reset();
37 60
38 loginHandler.onTlsStarted(); 61 loginHandler.onTlsStarted();
39 var cookie = window.btoa("\0" + testUsername + "\0" + testToken); 62 var cookie = window.btoa("\0" + testUsername + "\0" + testToken);
40 sinon.assert.calledWith( 63 sinon.assert.calledWith(
41 sendMessage, 64 sendMessage,
42 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + 65 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' +
43 'xmlns:stream="http://etherx.jabber.org/streams">' + 66 'xmlns:stream="http://etherx.jabber.org/streams">' +
44 '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-OAUTH2" ' + 67 '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-OAUTH2" ' +
45 'auth:service="oauth2" auth:allow-generated-jid="true" ' + 68 'auth:service="oauth2" auth:allow-generated-jid="true" ' +
46 'auth:client-uses-full-bind-result="true" ' + 69 'auth:client-uses-full-bind-result="true" ' +
47 'auth:allow-non-google-login="true" ' + 70 'auth:allow-non-google-login="true" ' +
48 'xmlns:auth="http://www.google.com/talk/protocol/auth">' + cookie + 71 'xmlns:auth="http://www.google.com/talk/protocol/auth">' + cookie +
49 '</auth>'); 72 '</auth>');
50 sendMessage.reset(); 73 sendMessage_spy.reset();
51 74
52 loginHandler.onDataReceived(base.encodeUtf8( 75 loginHandler.onDataReceived(base.encodeUtf8(
53 '<stream:stream from="google.com" id="DCDDE5171CB2154A" version="1.0" ' + 76 '<stream:stream from="google.com" id="DCDDE5171CB2154A" version="1.0" ' +
54 'xmlns:stream="http://etherx.jabber.org/streams" ' + 77 'xmlns:stream="http://etherx.jabber.org/streams" ' +
55 'xmlns="jabber:client">' + 78 'xmlns="jabber:client">' +
56 '<stream:features>' + 79 '<stream:features>' +
57 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + 80 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' +
58 '<mechanism>X-OAUTH2</mechanism>' + 81 '<mechanism>X-OAUTH2</mechanism>' +
59 '<mechanism>X-GOOGLE-TOKEN</mechanism>' + 82 '<mechanism>X-GOOGLE-TOKEN</mechanism>' +
60 '<mechanism>PLAIN</mechanism>' + 83 '<mechanism>PLAIN</mechanism>' +
(...skipping 11 matching lines...) Expand all
72 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + 95 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' +
73 'xmlns:stream="http://etherx.jabber.org/streams">' + 96 'xmlns:stream="http://etherx.jabber.org/streams">' +
74 '<iq type="set" id="0">' + 97 '<iq type="set" id="0">' +
75 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' + 98 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' +
76 '<resource>chromoting</resource>' + 99 '<resource>chromoting</resource>' +
77 '</bind>' + 100 '</bind>' +
78 '</iq>' + 101 '</iq>' +
79 '<iq type="set" id="1">' + 102 '<iq type="set" id="1">' +
80 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' + 103 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' +
81 '</iq>'); 104 '</iq>');
82 sendMessage.reset(); 105 sendMessage_spy.reset();
83 106
84 loginHandler.onDataReceived(base.encodeUtf8( 107 loginHandler.onDataReceived(base.encodeUtf8(
85 '<stream:stream from="google.com" id="104FA10576E2AA80" version="1.0" ' + 108 '<stream:stream from="google.com" id="104FA10576E2AA80" version="1.0" ' +
86 'xmlns:stream="http://etherx.jabber.org/streams" ' + 109 'xmlns:stream="http://etherx.jabber.org/streams" ' +
87 'xmlns="jabber:client">' + 110 'xmlns="jabber:client">' +
88 '<stream:features>' + 111 '<stream:features>' +
89 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>' + 112 '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>' +
90 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' + 113 '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>' +
91 '</stream:features>' + 114 '</stream:features>' +
92 '<iq id="0" type="result">' + 115 '<iq id="0" type="result">' +
(...skipping 10 matching lines...) Expand all
103 loginHandler = new remoting.XmppLoginHandler( 126 loginHandler = new remoting.XmppLoginHandler(
104 'google.com', testUsername, testToken, true, sendMessage, 127 'google.com', testUsername, testToken, true, sendMessage,
105 startTls, onHandshakeDone, onError); 128 startTls, onHandshakeDone, onError);
106 loginHandler.start(); 129 loginHandler.start();
107 130
108 sinon.assert.calledWith( 131 sinon.assert.calledWith(
109 sendMessage, 132 sendMessage,
110 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' + 133 '<stream:stream to="google.com" version="1.0" xmlns="jabber:client" ' +
111 'xmlns:stream="http://etherx.jabber.org/streams">' + 134 'xmlns:stream="http://etherx.jabber.org/streams">' +
112 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>'); 135 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>');
113 sendMessage.reset(); 136 sendMessage_spy.reset();
114 137
115 loginHandler.onDataReceived(base.encodeUtf8( 138 loginHandler.onDataReceived(base.encodeUtf8(
116 '<stream:stream from="google.com" id="78A87C70559EF28A" version="1.0" ' + 139 '<stream:stream from="google.com" id="78A87C70559EF28A" version="1.0" ' +
117 'xmlns:stream="http://etherx.jabber.org/streams"' + 140 'xmlns:stream="http://etherx.jabber.org/streams"' +
118 'xmlns="jabber:client">' + 141 'xmlns="jabber:client">' +
119 '<stream:features>' + 142 '<stream:features>' +
120 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">' + 143 '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">' +
121 '<required/>' + 144 '<required/>' +
122 '</starttls>' + 145 '</starttls>' +
123 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + 146 '<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' +
(...skipping 20 matching lines...) Expand all
144 167
145 test('should return UNEXPECTED error when failed to parse stream', 168 test('should return UNEXPECTED error when failed to parse stream',
146 function() { 169 function() {
147 handshakeBase(); 170 handshakeBase();
148 loginHandler.onDataReceived( 171 loginHandler.onDataReceived(
149 base.encodeUtf8('BAD DATA')); 172 base.encodeUtf8('BAD DATA'));
150 sinon.assert.calledWith(onError, remoting.Error.UNEXPECTED); 173 sinon.assert.calledWith(onError, remoting.Error.UNEXPECTED);
151 }); 174 });
152 175
153 })(); 176 })();
OLDNEW
« no previous file with comments | « remoting/webapp/unittests/xmpp_connection_unittest.js ('k') | remoting/webapp/unittests/xmpp_stream_parser_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698