| 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 "remoting/host/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "remoting/base/auto_thread_task_runner.h" | 13 #include "remoting/base/auto_thread_task_runner.h" |
| 13 #include "remoting/host/audio_capturer.h" | 14 #include "remoting/host/audio_capturer.h" |
| 14 #include "remoting/host/chromoting_host_context.h" | 15 #include "remoting/host/chromoting_host_context.h" |
| 15 #include "remoting/host/fake_desktop_environment.h" | 16 #include "remoting/host/fake_desktop_environment.h" |
| 16 #include "remoting/host/fake_mouse_cursor_monitor.h" | 17 #include "remoting/host/fake_mouse_cursor_monitor.h" |
| 17 #include "remoting/host/host_mock_objects.h" | 18 #include "remoting/host/host_mock_objects.h" |
| 18 #include "remoting/proto/video.pb.h" | 19 #include "remoting/proto/video.pb.h" |
| 19 #include "remoting/protocol/errors.h" | 20 #include "remoting/protocol/errors.h" |
| 20 #include "remoting/protocol/fake_connection_to_client.h" | 21 #include "remoting/protocol/fake_connection_to_client.h" |
| 21 #include "remoting/protocol/fake_desktop_capturer.h" | 22 #include "remoting/protocol/fake_desktop_capturer.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ChromotingHostTest() {} | 58 ChromotingHostTest() {} |
| 58 | 59 |
| 59 void SetUp() override { | 60 void SetUp() override { |
| 60 task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(), | 61 task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(), |
| 61 base::Bind(&base::DoNothing)); | 62 base::Bind(&base::DoNothing)); |
| 62 | 63 |
| 63 desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory()); | 64 desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory()); |
| 64 session_manager_ = new protocol::MockSessionManager(); | 65 session_manager_ = new protocol::MockSessionManager(); |
| 65 | 66 |
| 66 host_.reset(new ChromotingHost( | 67 host_.reset(new ChromotingHost( |
| 67 desktop_environment_factory_.get(), make_scoped_ptr(session_manager_), | 68 desktop_environment_factory_.get(), base::WrapUnique(session_manager_), |
| 68 protocol::TransportContext::ForTests(protocol::TransportRole::SERVER), | 69 protocol::TransportContext::ForTests(protocol::TransportRole::SERVER), |
| 69 task_runner_, // Audio | 70 task_runner_, // Audio |
| 70 task_runner_)); // Video encode | 71 task_runner_)); // Video encode |
| 71 host_->AddStatusObserver(&host_status_observer_); | 72 host_->AddStatusObserver(&host_status_observer_); |
| 72 | 73 |
| 73 xmpp_login_ = "host@domain"; | 74 xmpp_login_ = "host@domain"; |
| 74 session1_ = new MockSession(); | 75 session1_ = new MockSession(); |
| 75 session2_ = new MockSession(); | 76 session2_ = new MockSession(); |
| 76 session_unowned1_.reset(new MockSession()); | 77 session_unowned1_.reset(new MockSession()); |
| 77 session_unowned2_.reset(new MockSession()); | 78 session_unowned2_.reset(new MockSession()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 99 EXPECT_CALL(*session1_, config()) | 100 EXPECT_CALL(*session1_, config()) |
| 100 .WillRepeatedly(ReturnRef(*session_config1_)); | 101 .WillRepeatedly(ReturnRef(*session_config1_)); |
| 101 EXPECT_CALL(*session2_, config()) | 102 EXPECT_CALL(*session2_, config()) |
| 102 .WillRepeatedly(ReturnRef(*session_config2_)); | 103 .WillRepeatedly(ReturnRef(*session_config2_)); |
| 103 EXPECT_CALL(*session_unowned1_, config()) | 104 EXPECT_CALL(*session_unowned1_, config()) |
| 104 .WillRepeatedly(ReturnRef(*session_config1_)); | 105 .WillRepeatedly(ReturnRef(*session_config1_)); |
| 105 EXPECT_CALL(*session_unowned2_, config()) | 106 EXPECT_CALL(*session_unowned2_, config()) |
| 106 .WillRepeatedly(ReturnRef(*session_config2_)); | 107 .WillRepeatedly(ReturnRef(*session_config2_)); |
| 107 | 108 |
| 108 owned_connection1_.reset( | 109 owned_connection1_.reset( |
| 109 new protocol::FakeConnectionToClient(make_scoped_ptr(session1_))); | 110 new protocol::FakeConnectionToClient(base::WrapUnique(session1_))); |
| 110 owned_connection1_->set_host_stub(&host_stub1_); | 111 owned_connection1_->set_host_stub(&host_stub1_); |
| 111 connection1_ = owned_connection1_.get(); | 112 connection1_ = owned_connection1_.get(); |
| 112 connection1_->set_client_stub(&client_stub1_); | 113 connection1_->set_client_stub(&client_stub1_); |
| 113 | 114 |
| 114 owned_connection2_.reset( | 115 owned_connection2_.reset( |
| 115 new protocol::FakeConnectionToClient(make_scoped_ptr(session2_))); | 116 new protocol::FakeConnectionToClient(base::WrapUnique(session2_))); |
| 116 owned_connection2_->set_host_stub(&host_stub2_); | 117 owned_connection2_->set_host_stub(&host_stub2_); |
| 117 connection2_ = owned_connection2_.get(); | 118 connection2_ = owned_connection2_.get(); |
| 118 connection2_->set_client_stub(&client_stub2_); | 119 connection2_->set_client_stub(&client_stub2_); |
| 119 } | 120 } |
| 120 | 121 |
| 121 // Helper method to pretend a client is connected to ChromotingHost. | 122 // Helper method to pretend a client is connected to ChromotingHost. |
| 122 void SimulateClientConnection(int connection_index, bool authenticate, | 123 void SimulateClientConnection(int connection_index, bool authenticate, |
| 123 bool reject) { | 124 bool reject) { |
| 124 scoped_ptr<protocol::ConnectionToClient> connection = std::move( | 125 std::unique_ptr<protocol::ConnectionToClient> connection = std::move( |
| 125 (connection_index == 0) ? owned_connection1_ : owned_connection2_); | 126 (connection_index == 0) ? owned_connection1_ : owned_connection2_); |
| 126 protocol::ConnectionToClient* connection_ptr = connection.get(); | 127 protocol::ConnectionToClient* connection_ptr = connection.get(); |
| 127 scoped_ptr<ClientSession> client(new ClientSession( | 128 std::unique_ptr<ClientSession> client(new ClientSession( |
| 128 host_.get(), task_runner_ /* audio_task_runner */, | 129 host_.get(), task_runner_ /* audio_task_runner */, |
| 129 std::move(connection), desktop_environment_factory_.get(), | 130 std::move(connection), desktop_environment_factory_.get(), |
| 130 base::TimeDelta(), nullptr, std::vector<HostExtension*>())); | 131 base::TimeDelta(), nullptr, std::vector<HostExtension*>())); |
| 131 ClientSession* client_ptr = client.get(); | 132 ClientSession* client_ptr = client.get(); |
| 132 | 133 |
| 133 connection_ptr->set_host_stub(client.get()); | 134 connection_ptr->set_host_stub(client.get()); |
| 134 get_client(connection_index) = client_ptr; | 135 get_client(connection_index) = client_ptr; |
| 135 | 136 |
| 136 // |host| is responsible for deleting |client| from now on. | 137 // |host| is responsible for deleting |client| from now on. |
| 137 host_->clients_.push_back(client.release()); | 138 host_->clients_.push_back(client.release()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Expectation ExpectClientDisconnected(int connection_index) { | 200 Expectation ExpectClientDisconnected(int connection_index) { |
| 200 return EXPECT_CALL(host_status_observer_, | 201 return EXPECT_CALL(host_status_observer_, |
| 201 OnClientDisconnected(get_session_jid(connection_index))) | 202 OnClientDisconnected(get_session_jid(connection_index))) |
| 202 .RetiresOnSaturation(); | 203 .RetiresOnSaturation(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 protected: | 206 protected: |
| 206 base::MessageLoop message_loop_; | 207 base::MessageLoop message_loop_; |
| 207 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 208 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
| 208 MockConnectionToClientEventHandler handler_; | 209 MockConnectionToClientEventHandler handler_; |
| 209 scoped_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; | 210 std::unique_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; |
| 210 MockHostStatusObserver host_status_observer_; | 211 MockHostStatusObserver host_status_observer_; |
| 211 scoped_ptr<ChromotingHost> host_; | 212 std::unique_ptr<ChromotingHost> host_; |
| 212 protocol::MockSessionManager* session_manager_; | 213 protocol::MockSessionManager* session_manager_; |
| 213 std::string xmpp_login_; | 214 std::string xmpp_login_; |
| 214 protocol::FakeConnectionToClient* connection1_; | 215 protocol::FakeConnectionToClient* connection1_; |
| 215 scoped_ptr<protocol::FakeConnectionToClient> owned_connection1_; | 216 std::unique_ptr<protocol::FakeConnectionToClient> owned_connection1_; |
| 216 ClientSession* client1_; | 217 ClientSession* client1_; |
| 217 std::string session_jid1_; | 218 std::string session_jid1_; |
| 218 MockSession* session1_; // Owned by |connection_|. | 219 MockSession* session1_; // Owned by |connection_|. |
| 219 scoped_ptr<SessionConfig> session_config1_; | 220 std::unique_ptr<SessionConfig> session_config1_; |
| 220 MockClientStub client_stub1_; | 221 MockClientStub client_stub1_; |
| 221 MockHostStub host_stub1_; | 222 MockHostStub host_stub1_; |
| 222 protocol::FakeConnectionToClient* connection2_; | 223 protocol::FakeConnectionToClient* connection2_; |
| 223 scoped_ptr<protocol::FakeConnectionToClient> owned_connection2_; | 224 std::unique_ptr<protocol::FakeConnectionToClient> owned_connection2_; |
| 224 ClientSession* client2_; | 225 ClientSession* client2_; |
| 225 std::string session_jid2_; | 226 std::string session_jid2_; |
| 226 MockSession* session2_; // Owned by |connection2_|. | 227 MockSession* session2_; // Owned by |connection2_|. |
| 227 scoped_ptr<SessionConfig> session_config2_; | 228 std::unique_ptr<SessionConfig> session_config2_; |
| 228 MockClientStub client_stub2_; | 229 MockClientStub client_stub2_; |
| 229 MockHostStub host_stub2_; | 230 MockHostStub host_stub2_; |
| 230 scoped_ptr<MockSession> session_unowned1_; // Not owned by a connection. | 231 std::unique_ptr<MockSession> session_unowned1_; // Not owned by a connection. |
| 231 std::string session_unowned_jid1_; | 232 std::string session_unowned_jid1_; |
| 232 scoped_ptr<MockSession> session_unowned2_; // Not owned by a connection. | 233 std::unique_ptr<MockSession> session_unowned2_; // Not owned by a connection. |
| 233 std::string session_unowned_jid2_; | 234 std::string session_unowned_jid2_; |
| 234 protocol::Session::EventHandler* session_unowned1_event_handler_; | 235 protocol::Session::EventHandler* session_unowned1_event_handler_; |
| 235 protocol::Session::EventHandler* session_unowned2_event_handler_; | 236 protocol::Session::EventHandler* session_unowned2_event_handler_; |
| 236 | 237 |
| 237 protocol::FakeConnectionToClient*& get_connection(int connection_index) { | 238 protocol::FakeConnectionToClient*& get_connection(int connection_index) { |
| 238 return (connection_index == 0) ? connection1_ : connection2_; | 239 return (connection_index == 0) ? connection1_ : connection2_; |
| 239 } | 240 } |
| 240 | 241 |
| 241 // Returns the cached client pointers client1_ or client2_. | 242 // Returns the cached client pointers client1_ or client2_. |
| 242 ClientSession*& get_client(int connection_index) { | 243 ClientSession*& get_client(int connection_index) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 390 |
| 390 ExpectClientConnected(0); | 391 ExpectClientConnected(0); |
| 391 SimulateClientConnection(0, true, false); | 392 SimulateClientConnection(0, true, false); |
| 392 | 393 |
| 393 ExpectClientDisconnected(0); | 394 ExpectClientDisconnected(0); |
| 394 DisconnectAllClients(); | 395 DisconnectAllClients(); |
| 395 testing::Mock::VerifyAndClearExpectations(&host_status_observer_); | 396 testing::Mock::VerifyAndClearExpectations(&host_status_observer_); |
| 396 } | 397 } |
| 397 | 398 |
| 398 } // namespace remoting | 399 } // namespace remoting |
| OLD | NEW |