| 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/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "remoting/base/auto_thread_task_runner.h" | 9 #include "remoting/base/auto_thread_task_runner.h" |
| 10 #include "remoting/host/audio_capturer.h" | 10 #include "remoting/host/audio_capturer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "remoting/signaling/mock_signal_strategy.h" | 21 #include "remoting/signaling/mock_signal_strategy.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gmock_mutant.h" | 23 #include "testing/gmock_mutant.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 using ::remoting::protocol::MockClientStub; | 26 using ::remoting::protocol::MockClientStub; |
| 27 using ::remoting::protocol::MockConnectionToClient; | 27 using ::remoting::protocol::MockConnectionToClient; |
| 28 using ::remoting::protocol::MockConnectionToClientEventHandler; | 28 using ::remoting::protocol::MockConnectionToClientEventHandler; |
| 29 using ::remoting::protocol::MockHostStub; | 29 using ::remoting::protocol::MockHostStub; |
| 30 using ::remoting::protocol::MockSession; | 30 using ::remoting::protocol::MockSession; |
| 31 using ::remoting::protocol::MockVideoStub; | 31 using ::remoting::protocol::MockVideoSender; |
| 32 using ::remoting::protocol::Session; | 32 using ::remoting::protocol::Session; |
| 33 using ::remoting::protocol::SessionConfig; | 33 using ::remoting::protocol::SessionConfig; |
| 34 | 34 |
| 35 using testing::_; | 35 using testing::_; |
| 36 using testing::AnyNumber; | 36 using testing::AnyNumber; |
| 37 using testing::AtLeast; | 37 using testing::AtLeast; |
| 38 using testing::AtMost; | 38 using testing::AtMost; |
| 39 using testing::CreateFunctor; | 39 using testing::CreateFunctor; |
| 40 using testing::DeleteArg; | 40 using testing::DeleteArg; |
| 41 using testing::DoAll; | 41 using testing::DoAll; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 EXPECT_CALL(*session2_, config()) | 136 EXPECT_CALL(*session2_, config()) |
| 137 .WillRepeatedly(ReturnRef(session_config2_)); | 137 .WillRepeatedly(ReturnRef(session_config2_)); |
| 138 | 138 |
| 139 owned_connection1_.reset(new MockConnectionToClient(session1_, | 139 owned_connection1_.reset(new MockConnectionToClient(session1_, |
| 140 &host_stub1_)); | 140 &host_stub1_)); |
| 141 connection1_ = owned_connection1_.get(); | 141 connection1_ = owned_connection1_.get(); |
| 142 owned_connection2_.reset(new MockConnectionToClient(session2_, | 142 owned_connection2_.reset(new MockConnectionToClient(session2_, |
| 143 &host_stub2_)); | 143 &host_stub2_)); |
| 144 connection2_ = owned_connection2_.get(); | 144 connection2_ = owned_connection2_.get(); |
| 145 | 145 |
| 146 ON_CALL(video_stub1_, ProcessVideoPacketPtr(_, _)) | 146 ON_CALL(video_sender1_, ProcessVideoPacketPtr(_, _)) |
| 147 .WillByDefault(DeleteArg<0>()); | 147 .WillByDefault(DeleteArg<0>()); |
| 148 ON_CALL(video_stub2_, ProcessVideoPacketPtr(_, _)) | 148 ON_CALL(video_sender2_, ProcessVideoPacketPtr(_, _)) |
| 149 .WillByDefault(DeleteArg<0>()); | 149 .WillByDefault(DeleteArg<0>()); |
| 150 ON_CALL(*connection1_, video_stub()) | 150 ON_CALL(*connection1_, video_sender()) |
| 151 .WillByDefault(Return(&video_stub1_)); | 151 .WillByDefault(Return(&video_sender1_)); |
| 152 ON_CALL(*connection1_, client_stub()) | 152 ON_CALL(*connection1_, client_stub()) |
| 153 .WillByDefault(Return(&client_stub1_)); | 153 .WillByDefault(Return(&client_stub1_)); |
| 154 ON_CALL(*connection1_, session()) | 154 ON_CALL(*connection1_, session()) |
| 155 .WillByDefault(Return(session1_)); | 155 .WillByDefault(Return(session1_)); |
| 156 ON_CALL(*connection2_, video_stub()) | 156 ON_CALL(*connection2_, video_sender()) |
| 157 .WillByDefault(Return(&video_stub2_)); | 157 .WillByDefault(Return(&video_sender2_)); |
| 158 ON_CALL(*connection2_, client_stub()) | 158 ON_CALL(*connection2_, client_stub()) |
| 159 .WillByDefault(Return(&client_stub2_)); | 159 .WillByDefault(Return(&client_stub2_)); |
| 160 ON_CALL(*connection2_, session()) | 160 ON_CALL(*connection2_, session()) |
| 161 .WillByDefault(Return(session2_)); | 161 .WillByDefault(Return(session2_)); |
| 162 EXPECT_CALL(*connection1_, video_stub()) | 162 EXPECT_CALL(*connection1_, video_sender()) |
| 163 .Times(AnyNumber()); | 163 .Times(AnyNumber()); |
| 164 EXPECT_CALL(*connection1_, client_stub()) | 164 EXPECT_CALL(*connection1_, client_stub()) |
| 165 .Times(AnyNumber()); | 165 .Times(AnyNumber()); |
| 166 EXPECT_CALL(*connection1_, session()) | 166 EXPECT_CALL(*connection1_, session()) |
| 167 .Times(AnyNumber()); | 167 .Times(AnyNumber()); |
| 168 EXPECT_CALL(*connection2_, video_stub()) | 168 EXPECT_CALL(*connection2_, video_sender()) |
| 169 .Times(AnyNumber()); | 169 .Times(AnyNumber()); |
| 170 EXPECT_CALL(*connection2_, client_stub()) | 170 EXPECT_CALL(*connection2_, client_stub()) |
| 171 .Times(AnyNumber()); | 171 .Times(AnyNumber()); |
| 172 EXPECT_CALL(*connection2_, session()) | 172 EXPECT_CALL(*connection2_, session()) |
| 173 .Times(AnyNumber()); | 173 .Times(AnyNumber()); |
| 174 | 174 |
| 175 empty_candidate_config_ = | 175 empty_candidate_config_ = |
| 176 protocol::CandidateSessionConfig::CreateEmpty(); | 176 protocol::CandidateSessionConfig::CreateEmpty(); |
| 177 default_candidate_config_ = | 177 default_candidate_config_ = |
| 178 protocol::CandidateSessionConfig::CreateDefault(); | 178 protocol::CandidateSessionConfig::CreateDefault(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); | 337 return EXPECT_CALL(*session_manager_, Init(_, host_.get())); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Expect a client to connect. | 340 // Expect a client to connect. |
| 341 // Return an expectation that a session has started, and that the first | 341 // Return an expectation that a session has started, and that the first |
| 342 // video packet has been sent to the client. | 342 // video packet has been sent to the client. |
| 343 // Do |action| when that happens. | 343 // Do |action| when that happens. |
| 344 template <class A> | 344 template <class A> |
| 345 Expectation ExpectClientConnected(int connection_index, A action) { | 345 Expectation ExpectClientConnected(int connection_index, A action) { |
| 346 const std::string& session_jid = get_session_jid(connection_index); | 346 const std::string& session_jid = get_session_jid(connection_index); |
| 347 MockVideoStub& video_stub = get_video_stub(connection_index); | 347 MockVideoSender& video_sender = get_video_sender(connection_index); |
| 348 | 348 |
| 349 Expectation client_authenticated = | 349 Expectation client_authenticated = |
| 350 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); | 350 EXPECT_CALL(host_status_observer_, OnClientAuthenticated(session_jid)); |
| 351 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) | 351 EXPECT_CALL(host_status_observer_, OnClientConnected(session_jid)) |
| 352 .After(client_authenticated); | 352 .After(client_authenticated); |
| 353 Expectation video_packet_sent = | 353 Expectation video_packet_sent = |
| 354 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) | 354 EXPECT_CALL(video_sender, ProcessVideoPacketPtr(_, _)) |
| 355 .After(client_authenticated) | 355 .After(client_authenticated) |
| 356 .WillOnce(DoAll( | 356 .WillOnce(DoAll( |
| 357 action, | 357 action, |
| 358 RunDoneTask())) | 358 RunDoneTask())) |
| 359 .RetiresOnSaturation(); | 359 .RetiresOnSaturation(); |
| 360 EXPECT_CALL(video_stub, ProcessVideoPacketPtr(_, _)) | 360 EXPECT_CALL(video_sender, ProcessVideoPacketPtr(_, _)) |
| 361 .Times(AnyNumber()) | 361 .Times(AnyNumber()) |
| 362 .After(video_packet_sent) | 362 .After(video_packet_sent) |
| 363 .WillRepeatedly(RunDoneTask()); | 363 .WillRepeatedly(RunDoneTask()); |
| 364 return video_packet_sent; | 364 return video_packet_sent; |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Return an expectation that a client will disconnect after a given | 367 // Return an expectation that a client will disconnect after a given |
| 368 // expectation. The given action will be done after the event executor is | 368 // expectation. The given action will be done after the event executor is |
| 369 // notified that the session has finished. | 369 // notified that the session has finished. |
| 370 template <class A> | 370 template <class A> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 scoped_ptr<ChromotingHost> host_; | 415 scoped_ptr<ChromotingHost> host_; |
| 416 MockHostStatusObserver host_status_observer_; | 416 MockHostStatusObserver host_status_observer_; |
| 417 protocol::MockSessionManager* session_manager_; | 417 protocol::MockSessionManager* session_manager_; |
| 418 std::string xmpp_login_; | 418 std::string xmpp_login_; |
| 419 MockConnectionToClient* connection1_; | 419 MockConnectionToClient* connection1_; |
| 420 scoped_ptr<MockConnectionToClient> owned_connection1_; | 420 scoped_ptr<MockConnectionToClient> owned_connection1_; |
| 421 ClientSession* client1_; | 421 ClientSession* client1_; |
| 422 std::string session_jid1_; | 422 std::string session_jid1_; |
| 423 MockSession* session1_; // Owned by |connection_|. | 423 MockSession* session1_; // Owned by |connection_|. |
| 424 SessionConfig session_config1_; | 424 SessionConfig session_config1_; |
| 425 MockVideoStub video_stub1_; | 425 MockVideoSender video_sender1_; |
| 426 MockClientStub client_stub1_; | 426 MockClientStub client_stub1_; |
| 427 MockHostStub host_stub1_; | 427 MockHostStub host_stub1_; |
| 428 MockConnectionToClient* connection2_; | 428 MockConnectionToClient* connection2_; |
| 429 scoped_ptr<MockConnectionToClient> owned_connection2_; | 429 scoped_ptr<MockConnectionToClient> owned_connection2_; |
| 430 ClientSession* client2_; | 430 ClientSession* client2_; |
| 431 std::string session_jid2_; | 431 std::string session_jid2_; |
| 432 MockSession* session2_; // Owned by |connection2_|. | 432 MockSession* session2_; // Owned by |connection2_|. |
| 433 SessionConfig session_config2_; | 433 SessionConfig session_config2_; |
| 434 MockVideoStub video_stub2_; | 434 MockVideoSender video_sender2_; |
| 435 MockClientStub client_stub2_; | 435 MockClientStub client_stub2_; |
| 436 MockHostStub host_stub2_; | 436 MockHostStub host_stub2_; |
| 437 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. | 437 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. |
| 438 SessionConfig session_unowned_config1_; | 438 SessionConfig session_unowned_config1_; |
| 439 std::string session_unowned_jid1_; | 439 std::string session_unowned_jid1_; |
| 440 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. | 440 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. |
| 441 SessionConfig session_unowned_config2_; | 441 SessionConfig session_unowned_config2_; |
| 442 std::string session_unowned_jid2_; | 442 std::string session_unowned_jid2_; |
| 443 protocol::Session::EventHandler* session_unowned1_event_handler_; | 443 protocol::Session::EventHandler* session_unowned1_event_handler_; |
| 444 protocol::Session::EventHandler* session_unowned2_event_handler_; | 444 protocol::Session::EventHandler* session_unowned2_event_handler_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 456 | 456 |
| 457 // Returns the list of clients of the host_. | 457 // Returns the list of clients of the host_. |
| 458 std::list<ClientSession*>& get_clients_from_host() { | 458 std::list<ClientSession*>& get_clients_from_host() { |
| 459 return host_->clients_; | 459 return host_->clients_; |
| 460 } | 460 } |
| 461 | 461 |
| 462 const std::string& get_session_jid(int connection_index) { | 462 const std::string& get_session_jid(int connection_index) { |
| 463 return (connection_index == 0) ? session_jid1_ : session_jid2_; | 463 return (connection_index == 0) ? session_jid1_ : session_jid2_; |
| 464 } | 464 } |
| 465 | 465 |
| 466 MockVideoStub& get_video_stub(int connection_index) { | 466 MockVideoSender& get_video_sender(int connection_index) { |
| 467 return (connection_index == 0) ? video_stub1_ : video_stub2_; | 467 return (connection_index == 0) ? video_sender1_ : video_sender2_; |
| 468 } | 468 } |
| 469 }; | 469 }; |
| 470 | 470 |
| 471 TEST_F(ChromotingHostTest, StartAndShutdown) { | 471 TEST_F(ChromotingHostTest, StartAndShutdown) { |
| 472 Expectation start = ExpectHostAndSessionManagerStart(); | 472 Expectation start = ExpectHostAndSessionManagerStart(); |
| 473 EXPECT_CALL(host_status_observer_, OnShutdown()).After(start); | 473 EXPECT_CALL(host_status_observer_, OnShutdown()).After(start); |
| 474 | 474 |
| 475 host_->Start(xmpp_login_); | 475 host_->Start(xmpp_login_); |
| 476 ShutdownHost(); | 476 ShutdownHost(); |
| 477 message_loop_.Run(); | 477 message_loop_.Run(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 ExpectClientDisconnected(0, true, video_packet_sent, | 711 ExpectClientDisconnected(0, true, video_packet_sent, |
| 712 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); | 712 InvokeWithoutArgs(this, &ChromotingHostTest::ShutdownHost)); |
| 713 EXPECT_CALL(host_status_observer_, OnShutdown()); | 713 EXPECT_CALL(host_status_observer_, OnShutdown()); |
| 714 | 714 |
| 715 host_->Start(xmpp_login_); | 715 host_->Start(xmpp_login_); |
| 716 SimulateClientConnection(0, true, false); | 716 SimulateClientConnection(0, true, false); |
| 717 message_loop_.Run(); | 717 message_loop_.Run(); |
| 718 } | 718 } |
| 719 | 719 |
| 720 } // namespace remoting | 720 } // namespace remoting |
| OLD | NEW |