| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/jingle_glue/mock_objects.h" | 8 #include "remoting/jingle_glue/mock_objects.h" |
| 9 #include "remoting/host/audio_capturer.h" | 9 #include "remoting/host/audio_capturer.h" |
| 10 #include "remoting/host/chromoting_host_context.h" | 10 #include "remoting/host/chromoting_host_context.h" |
| 11 #include "remoting/host/chromoting_host.h" | 11 #include "remoting/host/chromoting_host.h" |
| 12 #include "remoting/host/desktop_environment.h" |
| 13 #include "remoting/host/desktop_environment_factory.h" |
| 14 #include "remoting/host/event_executor_fake.h" |
| 12 #include "remoting/host/host_mock_objects.h" | 15 #include "remoting/host/host_mock_objects.h" |
| 13 #include "remoting/host/it2me_host_user_interface.h" | 16 #include "remoting/host/it2me_host_user_interface.h" |
| 14 #include "remoting/host/video_frame_capturer_fake.h" | 17 #include "remoting/host/video_frame_capturer_fake.h" |
| 15 #include "remoting/proto/video.pb.h" | 18 #include "remoting/proto/video.pb.h" |
| 16 #include "remoting/protocol/errors.h" | 19 #include "remoting/protocol/errors.h" |
| 17 #include "remoting/protocol/protocol_mock_objects.h" | 20 #include "remoting/protocol/protocol_mock_objects.h" |
| 18 #include "remoting/protocol/session_config.h" | 21 #include "remoting/protocol/session_config.h" |
| 19 #include "testing/gmock_mutant.h" | 22 #include "testing/gmock_mutant.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // done callbacks. | 58 // done callbacks. |
| 56 ACTION(RunDoneTask) { | 59 ACTION(RunDoneTask) { |
| 57 arg1.Run(); | 60 arg1.Run(); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void DoNothing() { | 63 void DoNothing() { |
| 61 } | 64 } |
| 62 | 65 |
| 63 } // namespace | 66 } // namespace |
| 64 | 67 |
| 68 class MockDesktopEnvironmentFactory : public DesktopEnvironmentFactory { |
| 69 public: |
| 70 MockDesktopEnvironmentFactory(); |
| 71 virtual ~MockDesktopEnvironmentFactory(); |
| 72 |
| 73 virtual scoped_ptr<DesktopEnvironment> Create( |
| 74 ChromotingHostContext* context) OVERRIDE; |
| 75 |
| 76 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(MockDesktopEnvironmentFactory); |
| 78 }; |
| 79 |
| 80 MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory() { |
| 81 } |
| 82 |
| 83 MockDesktopEnvironmentFactory::~MockDesktopEnvironmentFactory() { |
| 84 } |
| 85 |
| 86 scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create( |
| 87 ChromotingHostContext* context) { |
| 88 scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); |
| 89 scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); |
| 90 return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment( |
| 91 scoped_ptr<AudioCapturer>(NULL), |
| 92 event_executor.Pass(), |
| 93 video_capturer.Pass())); |
| 94 } |
| 95 |
| 65 class ChromotingHostTest : public testing::Test { | 96 class ChromotingHostTest : public testing::Test { |
| 66 public: | 97 public: |
| 67 ChromotingHostTest() { | 98 ChromotingHostTest() { |
| 68 } | 99 } |
| 69 | 100 |
| 70 virtual void SetUp() OVERRIDE { | 101 virtual void SetUp() OVERRIDE { |
| 71 message_loop_proxy_ = base::MessageLoopProxy::current(); | 102 message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 72 | 103 |
| 73 EXPECT_CALL(context_, ui_task_runner()) | 104 EXPECT_CALL(context_, ui_task_runner()) |
| 74 .Times(AnyNumber()) | 105 .Times(AnyNumber()) |
| 75 .WillRepeatedly(Return(message_loop_proxy_.get())); | 106 .WillRepeatedly(Return(message_loop_proxy_.get())); |
| 76 EXPECT_CALL(context_, capture_task_runner()) | 107 EXPECT_CALL(context_, capture_task_runner()) |
| 77 .Times(AnyNumber()) | 108 .Times(AnyNumber()) |
| 78 .WillRepeatedly(Return(message_loop_proxy_.get())); | 109 .WillRepeatedly(Return(message_loop_proxy_.get())); |
| 79 EXPECT_CALL(context_, encode_task_runner()) | 110 EXPECT_CALL(context_, encode_task_runner()) |
| 80 .Times(AnyNumber()) | 111 .Times(AnyNumber()) |
| 81 .WillRepeatedly(Return(message_loop_proxy_.get())); | 112 .WillRepeatedly(Return(message_loop_proxy_.get())); |
| 82 EXPECT_CALL(context_, network_task_runner()) | 113 EXPECT_CALL(context_, network_task_runner()) |
| 83 .Times(AnyNumber()) | 114 .Times(AnyNumber()) |
| 84 .WillRepeatedly(Return(message_loop_proxy_.get())); | 115 .WillRepeatedly(Return(message_loop_proxy_.get())); |
| 85 | 116 |
| 86 scoped_ptr<VideoFrameCapturer> capturer(new VideoFrameCapturerFake()); | 117 desktop_environment_factory_.reset(new MockDesktopEnvironmentFactory()); |
| 87 scoped_ptr<AudioCapturer> audio_capturer(NULL); | |
| 88 event_executor_ = new MockEventExecutor(); | |
| 89 desktop_environment_ = DesktopEnvironment::CreateFake( | |
| 90 &context_, | |
| 91 capturer.Pass(), | |
| 92 scoped_ptr<EventExecutor>(event_executor_), | |
| 93 audio_capturer.Pass()); | |
| 94 session_manager_ = new protocol::MockSessionManager(); | 118 session_manager_ = new protocol::MockSessionManager(); |
| 95 | 119 |
| 96 host_ = new ChromotingHost( | 120 host_ = new ChromotingHost( |
| 97 &context_, &signal_strategy_, desktop_environment_.get(), | 121 &context_, &signal_strategy_, desktop_environment_factory_.get(), |
| 98 scoped_ptr<protocol::SessionManager>(session_manager_)); | 122 scoped_ptr<protocol::SessionManager>(session_manager_)); |
| 99 host_->AddStatusObserver(&host_status_observer_); | 123 host_->AddStatusObserver(&host_status_observer_); |
| 100 | 124 |
| 101 disconnect_window_ = new MockDisconnectWindow(); | 125 disconnect_window_ = new MockDisconnectWindow(); |
| 102 continue_window_ = new MockContinueWindow(); | 126 continue_window_ = new MockContinueWindow(); |
| 103 local_input_monitor_ = new MockLocalInputMonitor(); | 127 local_input_monitor_ = new MockLocalInputMonitor(); |
| 104 it2me_host_user_interface_.reset(new It2MeHostUserInterface(&context_)); | 128 it2me_host_user_interface_.reset(new It2MeHostUserInterface(&context_)); |
| 105 it2me_host_user_interface_->StartForTest( | 129 it2me_host_user_interface_->StartForTest( |
| 106 host_, | 130 host_, |
| 107 base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()), | 131 base::Bind(&ChromotingHost::Shutdown, host_, base::Closure()), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 138 EXPECT_CALL(*session_unowned1_, SetEventHandler(_)) | 162 EXPECT_CALL(*session_unowned1_, SetEventHandler(_)) |
| 139 .Times(AnyNumber()) | 163 .Times(AnyNumber()) |
| 140 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler)); | 164 .WillRepeatedly(Invoke(this, &ChromotingHostTest::SetEventHandler)); |
| 141 EXPECT_CALL(*session_unowned2_, SetEventHandler(_)) | 165 EXPECT_CALL(*session_unowned2_, SetEventHandler(_)) |
| 142 .Times(AnyNumber()); | 166 .Times(AnyNumber()); |
| 143 EXPECT_CALL(*session1_, config()) | 167 EXPECT_CALL(*session1_, config()) |
| 144 .WillRepeatedly(ReturnRef(session_config1_)); | 168 .WillRepeatedly(ReturnRef(session_config1_)); |
| 145 EXPECT_CALL(*session2_, config()) | 169 EXPECT_CALL(*session2_, config()) |
| 146 .WillRepeatedly(ReturnRef(session_config2_)); | 170 .WillRepeatedly(ReturnRef(session_config2_)); |
| 147 | 171 |
| 148 owned_connection1_.reset(new MockConnectionToClient( | 172 owned_connection1_.reset(new MockConnectionToClient(session1_, |
| 149 session1_, &host_stub1_, desktop_environment_->event_executor())); | 173 &host_stub1_)); |
| 150 connection1_ = owned_connection1_.get(); | 174 connection1_ = owned_connection1_.get(); |
| 151 owned_connection2_.reset(new MockConnectionToClient( | 175 owned_connection2_.reset(new MockConnectionToClient(session2_, |
| 152 session2_, &host_stub2_, desktop_environment_->event_executor())); | 176 &host_stub2_)); |
| 153 connection2_ = owned_connection2_.get(); | 177 connection2_ = owned_connection2_.get(); |
| 154 | 178 |
| 155 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _)) | 179 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _)) |
| 156 .WillByDefault(DeleteArg<0>()); | 180 .WillByDefault(DeleteArg<0>()); |
| 157 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _)) | 181 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _)) |
| 158 .WillByDefault(DeleteArg<0>()); | 182 .WillByDefault(DeleteArg<0>()); |
| 159 ON_CALL(*connection1_, video_stub()) | 183 ON_CALL(*connection1_, video_stub()) |
| 160 .WillByDefault(Return(&video_stub1_)); | 184 .WillByDefault(Return(&video_stub1_)); |
| 161 ON_CALL(*connection1_, client_stub()) | 185 ON_CALL(*connection1_, client_stub()) |
| 162 .WillByDefault(Return(&client_stub1_)); | 186 .WillByDefault(Return(&client_stub1_)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 187 protocol::CandidateSessionConfig::CreateDefault(); | 211 protocol::CandidateSessionConfig::CreateDefault(); |
| 188 } | 212 } |
| 189 | 213 |
| 190 // Helper method to pretend a client is connected to ChromotingHost. | 214 // Helper method to pretend a client is connected to ChromotingHost. |
| 191 void SimulateClientConnection(int connection_index, bool authenticate, | 215 void SimulateClientConnection(int connection_index, bool authenticate, |
| 192 bool reject) { | 216 bool reject) { |
| 193 scoped_ptr<protocol::ConnectionToClient> connection = | 217 scoped_ptr<protocol::ConnectionToClient> connection = |
| 194 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). | 218 ((connection_index == 0) ? owned_connection1_ : owned_connection2_). |
| 195 PassAs<protocol::ConnectionToClient>(); | 219 PassAs<protocol::ConnectionToClient>(); |
| 196 protocol::ConnectionToClient* connection_ptr = connection.get(); | 220 protocol::ConnectionToClient* connection_ptr = connection.get(); |
| 221 scoped_ptr<DesktopEnvironment> desktop_environment = |
| 222 host_->desktop_environment_factory_->Create(&context_); |
| 223 connection_ptr->set_input_stub(desktop_environment->event_executor()); |
| 224 |
| 197 ClientSession* client = new ClientSession( | 225 ClientSession* client = new ClientSession( |
| 198 host_.get(), | 226 host_.get(), |
| 227 context_.capture_task_runner(), |
| 228 context_.encode_task_runner(), |
| 229 context_.network_task_runner(), |
| 199 connection.Pass(), | 230 connection.Pass(), |
| 200 desktop_environment_->event_executor(), | 231 host_->desktop_environment_factory_->Create(&context_), |
| 201 desktop_environment_->event_executor(), | |
| 202 desktop_environment_->capturer(), | |
| 203 base::TimeDelta()); | 232 base::TimeDelta()); |
| 204 connection_ptr->set_host_stub(client); | 233 connection_ptr->set_host_stub(client); |
| 205 | 234 |
| 206 context_.network_task_runner()->PostTask( | 235 context_.network_task_runner()->PostTask( |
| 207 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, | 236 FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, |
| 208 host_, client)); | 237 host_, client)); |
| 209 | 238 |
| 210 if (authenticate) { | 239 if (authenticate) { |
| 211 context_.network_task_runner()->PostTask( | 240 context_.network_task_runner()->PostTask( |
| 212 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, | 241 FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // Do |action| when that happens. | 326 // Do |action| when that happens. |
| 298 template <class A> | 327 template <class A> |
| 299 Expectation ExpectClientConnected(int connection_index, A action) { | 328 Expectation ExpectClientConnected(int connection_index, A action) { |
| 300 const std::string& session_jid = get_session_jid(connection_index); | 329 const std::string& session_jid = get_session_jid(connection_index); |
| 301 MockVideoStub& video_stub = get_video_stub(connection_index); | 330 MockVideoStub& video_stub = get_video_stub(connection_index); |
| 302 | 331 |
| 303 Expectation client_authenticated = | 332 Expectation client_authenticated = |
| 304 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); | 333 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); |
| 305 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) | 334 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) |
| 306 .After(client_authenticated); | 335 .After(client_authenticated); |
| 307 Expectation session_started = | |
| 308 EXPECT_CALL(*event_executor_, OnSessionStartedPtr(_)) | |
| 309 .After(client_authenticated); | |
| 310 Expectation video_packet_sent = | 336 Expectation video_packet_sent = |
| 311 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) | 337 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) |
| 312 .After(session_started) | 338 .After(client_authenticated) |
| 313 .WillOnce(DoAll( | 339 .WillOnce(DoAll( |
| 314 action, | 340 action, |
| 315 RunDoneTask())) | 341 RunDoneTask())) |
| 316 .RetiresOnSaturation(); | 342 .RetiresOnSaturation(); |
| 317 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) | 343 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) |
| 318 .Times(AnyNumber()) | 344 .Times(AnyNumber()) |
| 319 .After(video_packet_sent) | 345 .After(video_packet_sent) |
| 320 .WillRepeatedly(RunDoneTask()); | 346 .WillRepeatedly(RunDoneTask()); |
| 321 return video_packet_sent; | 347 return video_packet_sent; |
| 322 } | 348 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 348 // Expect the side-effects of a client disconnection, after a given | 374 // Expect the side-effects of a client disconnection, after a given |
| 349 // expectation. The given action will be done after the event executor is | 375 // expectation. The given action will be done after the event executor is |
| 350 // notifed that the session has finished. | 376 // notifed that the session has finished. |
| 351 template <class A> | 377 template <class A> |
| 352 void ExpectClientDisconnectEffects(int connection_index, | 378 void ExpectClientDisconnectEffects(int connection_index, |
| 353 bool expect_host_status_change, | 379 bool expect_host_status_change, |
| 354 Expectation after, | 380 Expectation after, |
| 355 A action) { | 381 A action) { |
| 356 const std::string& session_jid = get_session_jid(connection_index); | 382 const std::string& session_jid = get_session_jid(connection_index); |
| 357 | 383 |
| 358 EXPECT_CALL(*event_executor_, OnSessionFinished()) | |
| 359 .After(after) | |
| 360 .WillOnce(action); | |
| 361 if (expect_host_status_change) { | 384 if (expect_host_status_change) { |
| 362 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) | 385 EXPECT_CALL(host_status_observer_, OnClientDisconnected(session_jid)) |
| 363 .After(after) | 386 .After(after) |
| 387 .WillOnce(action) |
| 364 .RetiresOnSaturation(); | 388 .RetiresOnSaturation(); |
| 365 } | 389 } |
| 366 } | 390 } |
| 367 | 391 |
| 368 protected: | 392 protected: |
| 369 MessageLoop message_loop_; | 393 MessageLoop message_loop_; |
| 370 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 394 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 371 MockChromotingHostContext context_; | 395 MockChromotingHostContext context_; |
| 372 MockConnectionToClientEventHandler handler_; | 396 MockConnectionToClientEventHandler handler_; |
| 373 MockSignalStrategy signal_strategy_; | 397 MockSignalStrategy signal_strategy_; |
| 374 MockEventExecutor* event_executor_; | 398 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
| 375 scoped_ptr<DesktopEnvironment> desktop_environment_; | |
| 376 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; | 399 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; |
| 377 scoped_refptr<ChromotingHost> host_; | 400 scoped_refptr<ChromotingHost> host_; |
| 378 MockHostStatusObserver host_status_observer_; | 401 MockHostStatusObserver host_status_observer_; |
| 379 protocol::MockSessionManager* session_manager_; | 402 protocol::MockSessionManager* session_manager_; |
| 380 std::string xmpp_login_; | 403 std::string xmpp_login_; |
| 381 MockConnectionToClient* connection1_; | 404 MockConnectionToClient* connection1_; |
| 382 scoped_ptr<MockConnectionToClient> owned_connection1_; | 405 scoped_ptr<MockConnectionToClient> owned_connection1_; |
| 383 ClientSession* client1_; | 406 ClientSession* client1_; |
| 384 std::string session_jid1_; | 407 std::string session_jid1_; |
| 385 MockSession* session1_; // Owned by |connection_|. | 408 MockSession* session1_; // Owned by |connection_|. |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 ExpectClientDisconnected(0, true, video_packet_sent, | 655 ExpectClientDisconnected(0, true, video_packet_sent, |
| 633 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 656 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
| 634 EXPECT_CALL(host_status_observer_, OnShutdown()); | 657 EXPECT_CALL(host_status_observer_, OnShutdown()); |
| 635 | 658 |
| 636 host_->Start(xmpp_login_); | 659 host_->Start(xmpp_login_); |
| 637 SimulateClientConnection(0, true, false); | 660 SimulateClientConnection(0, true, false); |
| 638 message_loop_.Run(); | 661 message_loop_.Run(); |
| 639 } | 662 } |
| 640 | 663 |
| 641 } // namespace remoting | 664 } // namespace remoting |
| OLD | NEW |