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 hostInstaller = null; | 9 var hostInstaller = null; |
10 var hangoutPort = null; | 10 var hangoutPort = null; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 sinon.assert.calledWith(hangoutPort.postMessage, { | 75 sinon.assert.calledWith(hangoutPort.postMessage, { |
76 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE, | 76 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE, |
77 result: false | 77 result: false |
78 }); | 78 }); |
79 QUnit.start(); | 79 QUnit.start(); |
80 }); | 80 }); |
81 }); | 81 }); |
82 | 82 |
83 QUnit.asyncTest('isHostInstalled() should return true if host is installed', | 83 QUnit.asyncTest('isHostInstalled() should return true if host is installed', |
84 function() { | 84 function() { |
85 sinon.stub(hostInstaller, "isInstalled").returns(Promise.resolve(true)); | 85 sinon.stub(hostInstaller, 'isInstalled').returns(Promise.resolve(true)); |
86 | 86 |
87 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; | 87 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; |
88 hangoutPort.onMessage.mock$fire({ | 88 hangoutPort.onMessage.mock$fire({ |
89 method: MessageTypes.IS_HOST_INSTALLED | 89 method: MessageTypes.IS_HOST_INSTALLED |
90 }); | 90 }); |
91 | 91 |
92 window.requestAnimationFrame(function() { | 92 window.requestAnimationFrame(function() { |
93 sinon.assert.calledWith(hangoutPort.postMessage, { | 93 sinon.assert.calledWith(hangoutPort.postMessage, { |
94 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE, | 94 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE, |
95 result: true | 95 result: true |
96 }); | 96 }); |
97 QUnit.start(); | 97 QUnit.start(); |
98 }); | 98 }); |
99 }); | 99 }); |
100 | 100 |
101 test('downloadHost() should trigger a host download', | 101 test('downloadHost() should trigger a host download', |
102 function() { | 102 function() { |
103 sinon.stub(hostInstaller, "download").returns(Promise.resolve(true)); | 103 sinon.stub(hostInstaller, 'download').returns(Promise.resolve(true)); |
104 | 104 |
105 hangoutPort.onMessage.mock$fire({ | 105 hangoutPort.onMessage.mock$fire({ |
106 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.DOWNLOAD_HOST | 106 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.DOWNLOAD_HOST |
107 }); | 107 }); |
108 | 108 |
109 sinon.assert.called(hostInstaller.download); | 109 sinon.assert.called(hostInstaller.download); |
110 }); | 110 }); |
111 | 111 |
112 test('connect() should return error if email is missing', | 112 test('connect() should return error if email is missing', |
113 function() { | 113 function() { |
114 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; | 114 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; |
115 | 115 |
116 hangoutPort.onMessage.mock$fire({ | 116 hangoutPort.onMessage.mock$fire({ |
117 method: MessageTypes.CONNECT | 117 method: MessageTypes.CONNECT |
118 }); | 118 }); |
119 | 119 |
120 sinon.assert.calledWithMatch(hangoutPort.postMessage, { | 120 sinon.assert.calledWithMatch(hangoutPort.postMessage, { |
121 method: MessageTypes.ERROR | 121 method: MessageTypes.ERROR |
122 }); | 122 }); |
123 }); | 123 }); |
124 | 124 |
125 QUnit.asyncTest('connect() should return access code', | 125 QUnit.asyncTest('connect() should return access code', |
126 function() { | 126 function() { |
127 // Stubs authentication. | 127 // Stubs authentication. |
128 sinon.stub(base, "isAppsV2").returns(true); | 128 sinon.stub(base, 'isAppsV2').returns(true); |
129 sinon.stub(chrome.identity, "getAuthToken") | 129 sinon.stub(remoting.MessageWindow, 'showConfirmWindow') |
| 130 .callsArgWith(4, 1 /* 1 for OK. */); |
| 131 sinon.stub(chrome.identity, 'getAuthToken') |
130 .callsArgWith(1, 'token'); | 132 .callsArgWith(1, 'token'); |
131 // Stubs Host behavior. | 133 // Stubs Host behavior. |
132 sinon.stub(host, "initialized").returns(true); | 134 sinon.stub(host, 'initialized').returns(true); |
133 sinon.stub(host, "connect") | 135 sinon.stub(host, 'connect') |
134 .callsArgWith(2, remoting.HostSession.State.RECEIVED_ACCESS_CODE); | 136 .callsArgWith(2, remoting.HostSession.State.RECEIVED_ACCESS_CODE); |
135 sinon.stub(host, "getAccessCode").returns('accessCode'); | 137 sinon.stub(host, 'getAccessCode').returns('accessCode'); |
136 | 138 |
137 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; | 139 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; |
138 hangoutPort.onMessage.mock$fire({ | 140 hangoutPort.onMessage.mock$fire({ |
139 method: MessageTypes.CONNECT, | 141 method: MessageTypes.CONNECT, |
140 email: 'test@chromium.org' | 142 email: 'test@chromium.org' |
141 }); | 143 }); |
142 | 144 |
143 window.requestAnimationFrame(function(){ | 145 window.requestAnimationFrame(function(){ |
144 // Verify that access code is correct in the response. | 146 // Verify that access code is correct in the response. |
145 sinon.assert.calledWithMatch(hangoutPort.postMessage, { | 147 sinon.assert.calledWithMatch(hangoutPort.postMessage, { |
146 method: MessageTypes.CONNECT_RESPONSE, | 148 method: MessageTypes.CONNECT_RESPONSE, |
147 accessCode: 'accessCode' | 149 accessCode: 'accessCode' |
148 }); | 150 }); |
149 | 151 |
150 chrome.identity.getAuthToken.restore(); | 152 chrome.identity.getAuthToken.restore(); |
151 base.isAppsV2.restore(); | 153 base.isAppsV2.restore(); |
| 154 remoting.MessageWindow.showConfirmWindow.restore(); |
152 QUnit.start(); | 155 QUnit.start(); |
153 }); | 156 }); |
154 }); | 157 }); |
155 | 158 |
156 test('should disconnect the session if Hangout crashes', function() { | 159 test('should disconnect the session if Hangout crashes', function() { |
157 sinon.spy(host, "disconnect"); | 160 sinon.spy(host, 'disconnect'); |
158 hangoutPort.onDisconnect.mock$fire(); | 161 hangoutPort.onDisconnect.mock$fire(); |
159 | 162 |
160 sinon.assert.called(onDisposedCallback); | 163 sinon.assert.called(onDisposedCallback); |
161 sinon.assert.called(host.disconnect); | 164 sinon.assert.called(host.disconnect); |
162 }); | 165 }); |
163 | 166 |
164 })(); | 167 })(); |
OLD | NEW |