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

Unified Diff: remoting/webapp/unittests/xmpp_connection_unittest.js

Issue 514343002: XMPP implementation in JavaScript. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/unittests/xmpp_connection_unittest.js
diff --git a/remoting/webapp/unittests/xmpp_connection_unittest.js b/remoting/webapp/unittests/xmpp_connection_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..3631c07be356a461cc25478765c32b1d46be19c4
--- /dev/null
+++ b/remoting/webapp/unittests/xmpp_connection_unittest.js
@@ -0,0 +1,96 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function() {
+
+'use strict';
+
+var testUsername = 'testUsername@gmail.com';
+var testToken = 'testToken';
+var socketId = 3;
+
+var onStateChange = null;
+var onStanzaStr = null;
+var connection = null;
+
+module('XmppConnection', {
+ setup: function() {
+ onStateChange = sinon.spy();
+ onStanzaStr = sinon.spy();
+ function onStanza(stanza) {
+ onStanzaStr(new XMLSerializer().serializeToString(stanza));
+ }
+
+ sinon.stub(chrome.socket, 'create');
+ sinon.stub(chrome.socket, 'connect');
+ sinon.stub(chrome.socket, 'write');
+ sinon.stub(chrome.socket, 'read');
+ sinon.stub(chrome.socket, 'destroy');
+ sinon.stub(chrome.socket, 'secure');
+
+ connection = new remoting.XmppConnection(onStateChange, onStanza);
+ },
+
+ teardown: function() {
+ chrome.socket.create.restore();
+ chrome.socket.connect.restore();
+ chrome.socket.write.restore();
+ chrome.socket.read.restore();
+ chrome.socket.destroy.restore();
+ chrome.socket.secure.restore();
+ }
+});
+
+test('should go to FAILED state when failed to connect', function() {
+ connection.connect(
+ 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken');
+ sinon.assert.calledWith(onStateChange,
+ remoting.XmppConnection.State.CONNECTING);
+ sinon.assert.calledWith(chrome.socket.create, "tcp", {});
+ chrome.socket.create.getCall(0).args[2]({socketId: socketId});
+
+ sinon.assert.calledWith(
+ chrome.socket.connect, socketId, "xmpp.example.com", 123);
+ chrome.socket.connect.getCall(0).args[3](-1);
+
+ QUnit.equal(connection.getError(), remoting.Error.NETWORK_FAILURE);
+});
+
+test('should use XmppLoginHandler to complete handshake', function() {
+ connection.connect(
+ 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken');
+ sinon.assert.calledWith(onStateChange,
+ remoting.XmppConnection.State.CONNECTING);
+ sinon.assert.calledWith(chrome.socket.create, "tcp", {});
+ chrome.socket.create.getCall(0).args[2]({socketId: socketId});
+
+ sinon.assert.calledWith(
+ chrome.socket.connect, socketId, "xmpp.example.com", 123);
+ chrome.socket.connect.getCall(0).args[3](0);
+
+ sinon.assert.calledWith(onStateChange,
+ remoting.XmppConnection.State.HANDSHAKE);
+
+ connection.loginHandler_.onHandshakeDoneCallback_();
+ sinon.assert.calledWith(onStateChange,
+ remoting.XmppConnection.State.CONNECTED);
+});
+
+test('should read data', function() {
+ connection.connect(
+ 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken');
+ sinon.assert.calledWith(onStateChange,
+ remoting.XmppConnection.State.CONNECTING);
+ sinon.assert.calledWith(chrome.socket.create, "tcp", {});
+ chrome.socket.create.getCall(0).args[2]({socketId: socketId});
+
+ sinon.assert.calledWith(
+ chrome.socket.connect, socketId, "xmpp.example.com", 123);
+ chrome.socket.connect.getCall(0).args[3](0);
+
+ sinon.assert.calledWith(onStateChange,
+ remoting.XmppConnection.State.HANDSHAKE);
+});
+
+})();

Powered by Google App Engine
This is Rietveld 408576698