| 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, base::Bind(&ChromotingHostTest::AddClientToHost, | 174 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, |
| 175 host_, client)); | 175 host_, client)); |
| 176 if (authenticate) { | 176 if (authenticate) { |
| 177 context_.network_message_loop()->PostTask( | 177 context_.network_message_loop()->PostTask( |
| 178 FROM_HERE, base::Bind(&ClientSession::OnAuthenticationComplete, | 178 FROM_HERE, base::Bind(&ClientSession::OnConnectionOpened, |
| 179 client.get())); | 179 client.get(), connection)); |
| 180 } |
| 181 |
| 182 if (connection_index == 0) { |
| 183 client_ = client; |
| 184 } else { |
| 185 client2_ = client; |
| 180 } | 186 } |
| 181 } | 187 } |
| 182 | 188 |
| 183 // Helper method to remove a client connection from ChromotingHost. | 189 // Helper method to remove a client connection from ChromotingHost. |
| 184 void RemoveClientConnection() { | 190 void RemoveClientSession() { |
| 185 context_.network_message_loop()->PostTask( | 191 context_.network_message_loop()->PostTask( |
| 186 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, | 192 FROM_HERE, base::Bind( |
| 187 host_.get(), connection_)); | 193 &ClientSession::OnConnectionClosed, client_, connection_)); |
| 188 } | 194 } |
| 189 | 195 |
| 190 static void AddClientToHost(scoped_refptr<ChromotingHost> host, | 196 static void AddClientToHost(scoped_refptr<ChromotingHost> host, |
| 191 scoped_refptr<ClientSession> session) { | 197 scoped_refptr<ClientSession> session) { |
| 192 host->clients_.push_back(session); | 198 host->clients_.push_back(session); |
| 193 } | 199 } |
| 194 | 200 |
| 195 void ShutdownHost() { | 201 void ShutdownHost() { |
| 196 host_->Shutdown(base::Bind(&PostQuitTask, &message_loop_)); | 202 host_->Shutdown(base::Bind(&PostQuitTask, &message_loop_)); |
| 197 } | 203 } |
| 198 | 204 |
| 199 protected: | 205 protected: |
| 200 MessageLoop message_loop_; | 206 MessageLoop message_loop_; |
| 201 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 207 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 202 MockConnectionToClientEventHandler handler_; | 208 MockConnectionToClientEventHandler handler_; |
| 203 scoped_ptr<DesktopEnvironment> desktop_environment_; | 209 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 204 scoped_refptr<ChromotingHost> host_; | 210 scoped_refptr<ChromotingHost> host_; |
| 205 scoped_refptr<InMemoryHostConfig> config_; | 211 scoped_refptr<InMemoryHostConfig> config_; |
| 206 MockChromotingHostContext context_; | 212 MockChromotingHostContext context_; |
| 207 scoped_refptr<MockConnectionToClient> connection_; | 213 scoped_refptr<MockConnectionToClient> connection_; |
| 214 scoped_refptr<ClientSession> client_; |
| 208 std::string session_jid_; | 215 std::string session_jid_; |
| 209 scoped_ptr<MockSession> session_; | 216 MockSession* session_; // Owned by |connection_|. |
| 210 SessionConfig session_config_; | 217 SessionConfig session_config_; |
| 211 MockVideoStub video_stub_; | 218 MockVideoStub video_stub_; |
| 212 MockClientStub client_stub_; | 219 MockClientStub client_stub_; |
| 213 MockHostStub host_stub_; | 220 MockHostStub host_stub_; |
| 214 scoped_refptr<MockConnectionToClient> connection2_; | 221 scoped_refptr<MockConnectionToClient> connection2_; |
| 222 scoped_refptr<ClientSession> client2_; |
| 215 std::string session2_jid_; | 223 std::string session2_jid_; |
| 216 scoped_ptr<MockSession> session2_; | 224 MockSession* session2_; // Owned by |connection2_|. |
| 217 SessionConfig session_config2_; | 225 SessionConfig session_config2_; |
| 218 MockVideoStub video_stub2_; | 226 MockVideoStub video_stub2_; |
| 219 MockClientStub client_stub2_; | 227 MockClientStub client_stub2_; |
| 220 MockHostStub host_stub2_; | 228 MockHostStub host_stub2_; |
| 221 MockEventExecutor event_executor2_; | 229 MockEventExecutor event_executor2_; |
| 222 | 230 |
| 223 // Owned by |host_|. | 231 // Owned by |host_|. |
| 224 MockEventExecutor* event_executor_; | 232 MockEventExecutor* event_executor_; |
| 225 MockCurtain* curtain_; | 233 MockCurtain* curtain_; |
| 226 MockDisconnectWindow* disconnect_window_; | 234 MockDisconnectWindow* disconnect_window_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // connection. | 278 // connection. |
| 271 { | 279 { |
| 272 InSequence s; | 280 InSequence s; |
| 273 // Ensure that curtain mode is activated before the first video packet. | 281 // Ensure that curtain mode is activated before the first video packet. |
| 274 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) | 282 EXPECT_CALL(*curtain_, EnableCurtainMode(true)) |
| 275 .Times(1); | 283 .Times(1); |
| 276 EXPECT_CALL(*disconnect_window_, Show(_, _)) | 284 EXPECT_CALL(*disconnect_window_, Show(_, _)) |
| 277 .Times(0); | 285 .Times(0); |
| 278 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 286 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
| 279 .WillOnce(DoAll( | 287 .WillOnce(DoAll( |
| 280 InvokeWithoutArgs(this, | 288 InvokeWithoutArgs(this, &ChromotingHostTest::RemoveClientSession), |
| 281 &ChromotingHostTest::RemoveClientConnection), | |
| 282 RunDoneTask())) | 289 RunDoneTask())) |
| 283 .RetiresOnSaturation(); | 290 .RetiresOnSaturation(); |
| 284 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 291 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
| 285 .Times(AnyNumber()); | 292 .Times(AnyNumber()); |
| 286 EXPECT_CALL(*curtain_, EnableCurtainMode(false)) | 293 EXPECT_CALL(*curtain_, EnableCurtainMode(false)) |
| 287 .Times(1); | 294 .Times(1); |
| 288 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 295 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
| 289 .Times(AnyNumber()); | 296 .Times(AnyNumber()); |
| 290 } | 297 } |
| 291 | 298 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 377 |
| 371 // Ensure that curtain mode is not activated if a connection does not | 378 // Ensure that curtain mode is not activated if a connection does not |
| 372 // authenticate. | 379 // authenticate. |
| 373 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) | 380 EXPECT_CALL(*curtain_, EnableCurtainMode(_)) |
| 374 .Times(0); | 381 .Times(0); |
| 375 EXPECT_CALL(*disconnect_window_, Show(_, _)) | 382 EXPECT_CALL(*disconnect_window_, Show(_, _)) |
| 376 .Times(0); | 383 .Times(0); |
| 377 EXPECT_CALL(*connection_.get(), Disconnect()) | 384 EXPECT_CALL(*connection_.get(), Disconnect()) |
| 378 .WillOnce(QuitMainMessageLoop(&message_loop_)); | 385 .WillOnce(QuitMainMessageLoop(&message_loop_)); |
| 379 SimulateClientConnection(0, false); | 386 SimulateClientConnection(0, false); |
| 380 RemoveClientConnection(); | 387 RemoveClientSession(); |
| 381 message_loop_.Run(); | 388 message_loop_.Run(); |
| 382 } | 389 } |
| 383 | 390 |
| 384 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { | 391 TEST_F(ChromotingHostTest, CurtainModeFailSecond) { |
| 385 host_->Start(); | 392 host_->Start(); |
| 386 | 393 |
| 387 // When a video packet is received we connect the second mock | 394 // When a video packet is received we connect the second mock |
| 388 // connection. | 395 // connection. |
| 389 { | 396 { |
| 390 InSequence s; | 397 InSequence s; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 .InSequence(s1); | 443 .InSequence(s1); |
| 437 EXPECT_CALL(*local_input_monitor_, Start(_)) | 444 EXPECT_CALL(*local_input_monitor_, Start(_)) |
| 438 .Times(1) | 445 .Times(1) |
| 439 .InSequence(s2); | 446 .InSequence(s2); |
| 440 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | 447 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) |
| 441 .InSequence(s1, s2) | 448 .InSequence(s1, s2) |
| 442 .WillOnce(DoAll( | 449 .WillOnce(DoAll( |
| 443 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), | 450 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost), |
| 444 RunDoneTask())) | 451 RunDoneTask())) |
| 445 .RetiresOnSaturation(); | 452 .RetiresOnSaturation(); |
| 446 EXPECT_CALL(video_stub_, ProcessVideoPacket(_, _)) | |
| 447 .Times(AnyNumber()) | |
| 448 .InSequence(s1, s2); | |
| 449 EXPECT_CALL(*connection_.get(), Disconnect()) | 453 EXPECT_CALL(*connection_.get(), Disconnect()) |
| 450 .InSequence(s1, s2) | 454 .InSequence(s1, s2) |
| 451 .RetiresOnSaturation(); | 455 .RetiresOnSaturation(); |
| 452 EXPECT_CALL(*local_input_monitor_, Stop()) | 456 EXPECT_CALL(*local_input_monitor_, Stop()) |
| 453 .Times(1) | 457 .Times(1) |
| 454 .InSequence(s1, s2); | 458 .InSequence(s1, s2); |
| 455 EXPECT_CALL(*continue_window_, Hide()) | 459 EXPECT_CALL(*continue_window_, Hide()) |
| 456 .Times(1) | 460 .Times(1) |
| 457 .InSequence(s1); | 461 .InSequence(s1); |
| 458 EXPECT_CALL(*disconnect_window_, Hide()) | 462 EXPECT_CALL(*disconnect_window_, Hide()) |
| 459 .Times(1) | 463 .Times(1) |
| 460 .InSequence(s2); | 464 .InSequence(s2); |
| 461 } | 465 } |
| 462 SimulateClientConnection(0, true); | 466 SimulateClientConnection(0, true); |
| 463 message_loop_.Run(); | 467 message_loop_.Run(); |
| 464 host_->set_it2me(false); | 468 host_->set_it2me(false); |
| 465 EXPECT_THAT(curtain_activated, false); | 469 EXPECT_THAT(curtain_activated, false); |
| 466 } | 470 } |
| 467 | 471 |
| 468 } // namespace remoting | 472 } // namespace remoting |
| OLD | NEW |