OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "base/task.h" | 8 #include "base/task.h" |
9 #include "remoting/host/capturer_fake.h" | 9 #include "remoting/host/capturer_fake.h" |
10 #include "remoting/host/chromoting_host.h" | 10 #include "remoting/host/chromoting_host.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 local_input_monitor_ = new MockLocalInputMonitor(); | 94 local_input_monitor_ = new MockLocalInputMonitor(); |
95 desktop_environment_.reset( | 95 desktop_environment_.reset( |
96 new DesktopEnvironment(&context_, capturer, event_executor_, curtain_, | 96 new DesktopEnvironment(&context_, capturer, event_executor_, curtain_, |
97 disconnect_window_, continue_window_, | 97 disconnect_window_, continue_window_, |
98 local_input_monitor_)); | 98 local_input_monitor_)); |
99 MockAccessVerifier* access_verifier = new MockAccessVerifier(); | 99 MockAccessVerifier* access_verifier = new MockAccessVerifier(); |
100 | 100 |
101 host_ = ChromotingHost::Create(&context_, config_, | 101 host_ = ChromotingHost::Create(&context_, config_, |
102 desktop_environment_.get(), | 102 desktop_environment_.get(), |
103 access_verifier, false); | 103 access_verifier, false); |
104 connection_ = new MockConnectionToClient( | 104 session_ = new MockSession(); |
105 &handler_, &host_stub_, event_executor_); | 105 session2_ = new MockSession(); |
106 connection2_ = new MockConnectionToClient( | |
107 &handler_, &host_stub2_, &event_executor2_); | |
108 session_.reset(new MockSession()); | |
109 session2_.reset(new MockSession()); | |
110 session_config_ = SessionConfig::GetDefault(); | 106 session_config_ = SessionConfig::GetDefault(); |
111 session_jid_ = "user@domain/rest-of-jid"; | 107 session_jid_ = "user@domain/rest-of-jid"; |
112 session2_jid_ = "user2@domain/rest-of-jid"; | 108 session2_jid_ = "user2@domain/rest-of-jid"; |
113 session_config2_ = SessionConfig::GetDefault(); | 109 session_config2_ = SessionConfig::GetDefault(); |
| 110 EXPECT_CALL(*session_, jid()) |
| 111 .WillRepeatedly(ReturnRef(session_jid_)); |
| 112 EXPECT_CALL(*session2_, jid()) |
| 113 .WillRepeatedly(ReturnRef(session2_jid_)); |
| 114 EXPECT_CALL(*session_, SetStateChangeCallback(_)) |
| 115 .Times(AnyNumber()); |
| 116 EXPECT_CALL(*session2_, SetStateChangeCallback(_)) |
| 117 .Times(AnyNumber()); |
| 118 EXPECT_CALL(*session_, config()) |
| 119 .WillRepeatedly(ReturnRef(session_config_)); |
| 120 EXPECT_CALL(*session2_, config()) |
| 121 .WillRepeatedly(ReturnRef(session_config2_)); |
| 122 |
| 123 connection_ = new MockConnectionToClient( |
| 124 session_, &host_stub_, event_executor_); |
| 125 connection2_ = new MockConnectionToClient( |
| 126 session2_, &host_stub2_, &event_executor2_); |
114 | 127 |
115 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) | 128 ON_CALL(video_stub_, ProcessVideoPacket(_, _)) |
116 .WillByDefault(DeleteArg<0>()); | 129 .WillByDefault(DeleteArg<0>()); |
117 ON_CALL(video_stub2_, ProcessVideoPacket(_, _)) | 130 ON_CALL(video_stub2_, ProcessVideoPacket(_, _)) |
118 .WillByDefault(DeleteArg<0>()); | 131 .WillByDefault(DeleteArg<0>()); |
119 ON_CALL(*connection_.get(), video_stub()) | 132 ON_CALL(*connection_.get(), video_stub()) |
120 .WillByDefault(Return(&video_stub_)); | 133 .WillByDefault(Return(&video_stub_)); |
121 ON_CALL(*connection_.get(), client_stub()) | 134 ON_CALL(*connection_.get(), client_stub()) |
122 .WillByDefault(Return(&client_stub_)); | 135 .WillByDefault(Return(&client_stub_)); |
123 ON_CALL(*connection_.get(), session()) | 136 ON_CALL(*connection_.get(), session()) |
124 .WillByDefault(Return(session_.get())); | 137 .WillByDefault(Return(session_)); |
125 ON_CALL(*connection2_.get(), video_stub()) | 138 ON_CALL(*connection2_.get(), video_stub()) |
126 .WillByDefault(Return(&video_stub2_)); | 139 .WillByDefault(Return(&video_stub2_)); |
127 ON_CALL(*connection2_.get(), client_stub()) | 140 ON_CALL(*connection2_.get(), client_stub()) |
128 .WillByDefault(Return(&client_stub2_)); | 141 .WillByDefault(Return(&client_stub2_)); |
129 ON_CALL(*connection2_.get(), session()) | 142 ON_CALL(*connection2_.get(), session()) |
130 .WillByDefault(Return(session2_.get())); | 143 .WillByDefault(Return(session2_)); |
131 ON_CALL(*session_.get(), config()) | |
132 .WillByDefault(ReturnRef(session_config_)); | |
133 ON_CALL(*session2_.get(), config()) | |
134 .WillByDefault(ReturnRef(session_config2_)); | |
135 EXPECT_CALL(*session_, jid()) | |
136 .WillRepeatedly(ReturnRef(session_jid_)); | |
137 EXPECT_CALL(*session2_, jid()) | |
138 .WillRepeatedly(ReturnRef(session2_jid_)); | |
139 EXPECT_CALL(*connection_.get(), video_stub()) | 144 EXPECT_CALL(*connection_.get(), video_stub()) |
140 .Times(AnyNumber()); | 145 .Times(AnyNumber()); |
141 EXPECT_CALL(*connection_.get(), client_stub()) | 146 EXPECT_CALL(*connection_.get(), client_stub()) |
142 .Times(AnyNumber()); | 147 .Times(AnyNumber()); |
143 EXPECT_CALL(*connection_.get(), session()) | 148 EXPECT_CALL(*connection_.get(), session()) |
144 .Times(AnyNumber()); | 149 .Times(AnyNumber()); |
145 EXPECT_CALL(*connection2_.get(), video_stub()) | 150 EXPECT_CALL(*connection2_.get(), video_stub()) |
146 .Times(AnyNumber()); | 151 .Times(AnyNumber()); |
147 EXPECT_CALL(*connection2_.get(), client_stub()) | 152 EXPECT_CALL(*connection2_.get(), client_stub()) |
148 .Times(AnyNumber()); | 153 .Times(AnyNumber()); |
149 EXPECT_CALL(*connection2_.get(), session()) | 154 EXPECT_CALL(*connection2_.get(), session()) |
150 .Times(AnyNumber()); | 155 .Times(AnyNumber()); |
151 EXPECT_CALL(*session_.get(), config()) | |
152 .Times(AnyNumber()); | |
153 EXPECT_CALL(*session2_.get(), config()) | |
154 .Times(AnyNumber()); | |
155 } | 156 } |
156 | 157 |
157 virtual void TearDown() OVERRIDE { | 158 virtual void TearDown() OVERRIDE { |
158 message_loop_.RunAllPending(); | 159 message_loop_.RunAllPending(); |
159 } | 160 } |
160 | 161 |
161 // Helper method to pretend a client is connected to ChromotingHost. | 162 // Helper method to pretend a client is connected to ChromotingHost. |
162 void SimulateClientConnection(int connection_index, bool authenticate) { | 163 void SimulateClientConnection(int connection_index, bool authenticate) { |
163 scoped_refptr<MockConnectionToClient> connection = | 164 scoped_refptr<protocol::ConnectionToClient> connection = |
164 (connection_index == 0) ? connection_ : connection2_; | 165 (connection_index == 0) ? connection_ : connection2_; |
165 | |
166 scoped_refptr<ClientSession> client = new ClientSession( | 166 scoped_refptr<ClientSession> client = new ClientSession( |
167 host_.get(), | 167 host_.get(), |
168 connection, | 168 connection, |
169 event_executor_, | 169 event_executor_, |
170 desktop_environment_->capturer()); | 170 desktop_environment_->capturer()); |
171 connection->set_host_stub(client.get()); | 171 connection->set_host_stub(client.get()); |
172 | 172 |
173 context_.network_message_loop()->PostTask( | 173 context_.network_message_loop()->PostTask( |
174 FROM_HERE, | 174 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, |
175 NewRunnableFunction(&ChromotingHostTest::AddClientToHost, | 175 host_, client)); |
176 host_, client)); | |
177 if (authenticate) { | 176 if (authenticate) { |
178 context_.network_message_loop()->PostTask( | 177 context_.network_message_loop()->PostTask( |
179 FROM_HERE, | 178 FROM_HERE, base::Bind(&ClientSession::OnConnectionOpened, |
180 NewRunnableMethod(client.get(), | 179 client.get(), connection)); |
181 &ClientSession::OnAuthenticationComplete)); | 180 } |
| 181 |
| 182 if (connection_index == 0) { |
| 183 client_ = client; |
| 184 } else { |
| 185 client2_ = client; |
182 } | 186 } |
183 } | 187 } |
184 | 188 |
185 // Helper method to remove a client connection from ChromotingHost. | 189 // Helper method to remove a client connection from ChromotingHost. |
186 void RemoveClientConnection() { | 190 void RemoveClientSession() { |
187 context_.network_message_loop()->PostTask( | 191 context_.network_message_loop()->PostTask( |
188 FROM_HERE, | 192 FROM_HERE, base::Bind( |
189 NewRunnableMethod(host_.get(), | 193 &ClientSession::OnConnectionClosed, client_, connection_)); |
190 &ChromotingHost::OnClientDisconnected, | |
191 connection_)); | |
192 } | 194 } |
193 | 195 |
194 static void AddClientToHost(scoped_refptr<ChromotingHost> host, | 196 static void AddClientToHost(scoped_refptr<ChromotingHost> host, |
195 scoped_refptr<ClientSession> session) { | 197 scoped_refptr<ClientSession> session) { |
196 host->clients_.push_back(session); | 198 host->clients_.push_back(session); |
197 } | 199 } |
198 | 200 |
199 void ShutdownHost() { | 201 void ShutdownHost() { |
200 host_->Shutdown( | 202 host_->Shutdown( |
201 NewRunnableFunction(&PostQuitTask, &message_loop_)); | 203 NewRunnableFunction(&PostQuitTask, &message_loop_)); |
202 } | 204 } |
203 | 205 |
204 protected: | 206 protected: |
205 MessageLoop message_loop_; | 207 MessageLoop message_loop_; |
206 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 208 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
207 MockConnectionToClientEventHandler handler_; | 209 MockConnectionToClientEventHandler handler_; |
208 scoped_ptr<DesktopEnvironment> desktop_environment_; | 210 scoped_ptr<DesktopEnvironment> desktop_environment_; |
209 scoped_refptr<ChromotingHost> host_; | 211 scoped_refptr<ChromotingHost> host_; |
210 scoped_refptr<InMemoryHostConfig> config_; | 212 scoped_refptr<InMemoryHostConfig> config_; |
211 MockChromotingHostContext context_; | 213 MockChromotingHostContext context_; |
212 scoped_refptr<MockConnectionToClient> connection_; | 214 scoped_refptr<MockConnectionToClient> connection_; |
| 215 scoped_refptr<ClientSession> client_; |
213 std::string session_jid_; | 216 std::string session_jid_; |
214 scoped_ptr<MockSession> session_; | 217 MockSession* session_; // Owned by |connection_|. |
215 SessionConfig session_config_; | 218 SessionConfig session_config_; |
216 MockVideoStub video_stub_; | 219 MockVideoStub video_stub_; |
217 MockClientStub client_stub_; | 220 MockClientStub client_stub_; |
218 MockHostStub host_stub_; | 221 MockHostStub host_stub_; |
219 scoped_refptr<MockConnectionToClient> connection2_; | 222 scoped_refptr<MockConnectionToClient> connection2_; |
| 223 scoped_refptr<ClientSession> client2_; |
220 std::string session2_jid_; | 224 std::string session2_jid_; |
221 scoped_ptr<MockSession> session2_; | 225 MockSession* session2_; // Owned by |connection2_|. |
222 SessionConfig session_config2_; | 226 SessionConfig session_config2_; |
223 MockVideoStub video_stub2_; | 227 MockVideoStub video_stub2_; |
224 MockClientStub client_stub2_; | 228 MockClientStub client_stub2_; |
225 MockHostStub host_stub2_; | 229 MockHostStub host_stub2_; |
226 MockEventExecutor event_executor2_; | 230 MockEventExecutor event_executor2_; |
227 | 231 |
228 // Owned by |host_|. | 232 // Owned by |host_|. |
229 MockEventExecutor* event_executor_; | 233 MockEventExecutor* event_executor_; |
230 MockCurtain* curtain_; | 234 MockCurtain* curtain_; |
231 MockDisconnectWindow* disconnect_window_; | 235 MockDisconnectWindow* disconnect_window_; |
232 MockContinueWindow* continue_window_; | 236 MockContinueWindow* continue_window_; |
233 MockLocalInputMonitor* local_input_monitor_; | 237 MockLocalInputMonitor* local_input_monitor_; |
234 }; | 238 }; |
235 | 239 |
236 TEST_F(ChromotingHostTest, DISABLED_StartAndShutdown) { | 240 TEST_F(ChromotingHostTest, DISABLED_StartAndShutdown) { |
237 host_->Start(); | 241 host_->Start(); |
238 | 242 |
239 message_loop_.PostTask( | 243 message_loop_.PostTask( |
240 FROM_HERE,NewRunnableMethod( | 244 FROM_HERE, NewRunnableMethod( |
241 host_.get(), &ChromotingHost::Shutdown, | 245 host_.get(), &ChromotingHost::Shutdown, |
242 NewRunnableFunction(&PostQuitTask, &message_loop_))); | 246 NewRunnableFunction(&PostQuitTask, &message_loop_))); |
243 message_loop_.Run(); | 247 message_loop_.Run(); |
244 } | 248 } |
245 | 249 |
246 TEST_F(ChromotingHostTest, DISABLED_Connect) { | 250 TEST_F(ChromotingHostTest, DISABLED_Connect) { |
247 host_->Start(); | 251 host_->Start(); |
248 | 252 |
249 // When the video packet is received we first shutdown ChromotingHost | 253 // When the video packet is received we first shutdown ChromotingHost |
250 // then execute the done task. | 254 // then execute the done task. |
(...skipping 24 matching lines...) Expand all Loading... |
275 // connection. | 279 // connection. |
276 { | 280 { |
277 InSequence s; | 281 InSequence s; |
278 // Ensure that curtain mode is activated before the first video packet. | 282 // Ensure that curtain mode is activated before the first video packet. |
279 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) | 283 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) |
280 .Times(1); | 284 .Times(1); |
281 EXPECT_CALL(*disconnect_window_, Show(_, _)) | 285 EXPECT_CALL(*disconnect_window_, Show(_, _)) |
282 .Times(0); | 286 .Times(0); |
283 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 287 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
284 .WillOnce(DoAll( | 288 .WillOnce(DoAll( |
285 InvokeWithoutArgs(this, | 289 InvokeWithoutArgs(this, &ChromotingHostTest::RemoveClientSession), |
286 &ChromotingHostTest::RemoveClientConnection), | |
287 RunDoneTask())) | 290 RunDoneTask())) |
288 .RetiresOnSaturation(); | 291 .RetiresOnSaturation(); |
289 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 292 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
290 .Times(AnyNumber()); | 293 .Times(AnyNumber()); |
291 EXPECT_CALL(*curtain_, EnableCurtainMode(false)) | 294 EXPECT_CALL(*curtain_, EnableCurtainMode(false)) |
292 .Times(1); | 295 .Times(1); |
293 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 296 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
294 .Times(AnyNumber()); | 297 .Times(AnyNumber()); |
295 } | 298 } |
296 | 299 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 378 |
376 // Ensure that curtain mode is not activated if a connection does not | 379 // Ensure that curtain mode is not activated if a connection does not |
377 // authenticate. | 380 // authenticate. |
378 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) | 381 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) |
379 .Times(0); | 382 .Times(0); |
380 EXPECT_CALL(*disconnect_window_, Show(_, _)) | 383 EXPECT_CALL(*disconnect_window_, Show(_, _)) |
381 .Times(0); | 384 .Times(0); |
382 EXPECT_CALL(*connection_.get(), Disconnect()) | 385 EXPECT_CALL(*connection_.get(), Disconnect()) |
383 .WillOnce(QuitMainMessageLoop(&message_loop_)); | 386 .WillOnce(QuitMainMessageLoop(&message_loop_)); |
384 SimulateClientConnection(0, false); | 387 SimulateClientConnection(0, false); |
385 RemoveClientConnection(); | 388 RemoveClientSession(); |
386 message_loop_.Run(); | 389 message_loop_.Run(); |
387 } | 390 } |
388 | 391 |
389 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { | 392 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { |
390 host_->Start(); | 393 host_->Start(); |
391 | 394 |
392 // When a video packet is received we connect the second mock | 395 // When a video packet is received we connect the second mock |
393 // connection. | 396 // connection. |
394 { | 397 { |
395 InSequence s; | 398 InSequence s; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 .InSequence(s1); | 444 .InSequence(s1); |
442 EXPECT_CALL(*local_input_monitor_, Start(_)) | 445 EXPECT_CALL(*local_input_monitor_, Start(_)) |
443 .Times(1) | 446 .Times(1) |
444 .InSequence(s2); | 447 .InSequence(s2); |
445 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 448 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
446 .InSequence(s1, s2) | 449 .InSequence(s1, s2) |
447 .WillOnce(DoAll( | 450 .WillOnce(DoAll( |
448 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), | 451 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), |
449 RunDoneTask())) | 452 RunDoneTask())) |
450 .RetiresOnSaturation(); | 453 .RetiresOnSaturation(); |
451 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | |
452 .Times(AnyNumber()) | |
453 .InSequence(s1, s2); | |
454 EXPECT_CALL(*connection_.get(), Disconnect()) | 454 EXPECT_CALL(*connection_.get(), Disconnect()) |
455 .InSequence(s1, s2) | 455 .InSequence(s1, s2) |
456 .RetiresOnSaturation(); | 456 .RetiresOnSaturation(); |
457 EXPECT_CALL(*local_input_monitor_, Stop()) | 457 EXPECT_CALL(*local_input_monitor_, Stop()) |
458 .Times(1) | 458 .Times(1) |
459 .InSequence(s1, s2); | 459 .InSequence(s1, s2); |
460 EXPECT_CALL(*continue_window_, Hide()) | 460 EXPECT_CALL(*continue_window_, Hide()) |
461 .Times(1) | 461 .Times(1) |
462 .InSequence(s1); | 462 .InSequence(s1); |
463 EXPECT_CALL(*disconnect_window_, Hide()) | 463 EXPECT_CALL(*disconnect_window_, Hide()) |
464 .Times(1) | 464 .Times(1) |
465 .InSequence(s2); | 465 .InSequence(s2); |
466 } | 466 } |
467 SimulateClientConnection(0, true); | 467 SimulateClientConnection(0, true); |
468 message_loop_.Run(); | 468 message_loop_.Run(); |
469 host_->set_it2me(false); | 469 host_->set_it2me(false); |
470 EXPECT_THAT(curtain_activated, false); | 470 EXPECT_THAT(curtain_activated, false); |
471 } | 471 } |
472 | 472 |
473 } // namespace remoting | 473 } // namespace remoting |
OLD | NEW |