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/client_session.h" | 5 #include "remoting/host/client_session.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 128 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
129 | 129 |
130 // Used to run |message_loop_| after each test, until no objects remain that | 130 // Used to run |message_loop_| after each test, until no objects remain that |
131 // require it. | 131 // require it. |
132 base::RunLoop run_loop_; | 132 base::RunLoop run_loop_; |
133 | 133 |
134 // HostExtensions to pass when creating the ClientSession. Caller retains | 134 // HostExtensions to pass when creating the ClientSession. Caller retains |
135 // ownership of the HostExtensions themselves. | 135 // ownership of the HostExtensions themselves. |
136 std::vector<HostExtension*> extensions_; | 136 std::vector<HostExtension*> extensions_; |
137 | 137 |
138 std::vector<protocol::DataChannelManager::NameCallbackPair> | |
139 data_channel_callbacks_; | |
140 | |
141 // ClientSession instance under test. | 138 // ClientSession instance under test. |
142 std::unique_ptr<ClientSession> client_session_; | 139 std::unique_ptr<ClientSession> client_session_; |
143 | 140 |
144 // ClientSession::EventHandler mock for use in tests. | 141 // ClientSession::EventHandler mock for use in tests. |
145 MockClientSessionEventHandler session_event_handler_; | 142 MockClientSessionEventHandler session_event_handler_; |
146 | 143 |
147 // Stubs returned to |client_session_| components by |connection_|. | 144 // Stubs returned to |client_session_| components by |connection_|. |
148 MockClientStub client_stub_; | 145 MockClientStub client_stub_; |
149 | 146 |
150 // ClientSession owns |connection_| but tests need it to inject fake events. | 147 // ClientSession owns |connection_| but tests need it to inject fake events. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // HostStub is not touched by ClientSession, so we can safely pass nullptr. | 180 // HostStub is not touched by ClientSession, so we can safely pass nullptr. |
184 std::unique_ptr<protocol::FakeConnectionToClient> connection( | 181 std::unique_ptr<protocol::FakeConnectionToClient> connection( |
185 new protocol::FakeConnectionToClient(std::move(session))); | 182 new protocol::FakeConnectionToClient(std::move(session))); |
186 connection->set_client_stub(&client_stub_); | 183 connection->set_client_stub(&client_stub_); |
187 connection_ = connection.get(); | 184 connection_ = connection.get(); |
188 | 185 |
189 client_session_.reset(new ClientSession( | 186 client_session_.reset(new ClientSession( |
190 &session_event_handler_, std::move(connection), | 187 &session_event_handler_, std::move(connection), |
191 desktop_environment_factory_.get(), | 188 desktop_environment_factory_.get(), |
192 DesktopEnvironmentOptions::CreateDefault(), base::TimeDelta(), nullptr, | 189 DesktopEnvironmentOptions::CreateDefault(), base::TimeDelta(), nullptr, |
193 extensions_, data_channel_callbacks_)); | 190 extensions_)); |
194 } | 191 } |
195 | 192 |
196 void ClientSessionTest::CreateClientSession() { | 193 void ClientSessionTest::CreateClientSession() { |
197 CreateClientSession(base::MakeUnique<protocol::FakeSession>()); | 194 CreateClientSession(base::MakeUnique<protocol::FakeSession>()); |
198 } | 195 } |
199 | 196 |
200 void ClientSessionTest::ConnectClientSession() { | 197 void ClientSessionTest::ConnectClientSession() { |
201 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 198 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
202 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 199 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
203 | 200 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 EXPECT_TRUE(extension2.was_instantiated()); | 428 EXPECT_TRUE(extension2.was_instantiated()); |
432 EXPECT_FALSE(extension2.has_handled_message()); | 429 EXPECT_FALSE(extension2.has_handled_message()); |
433 | 430 |
434 // ext3 was sent a message but not instantiated. | 431 // ext3 was sent a message but not instantiated. |
435 EXPECT_FALSE(extension3.was_instantiated()); | 432 EXPECT_FALSE(extension3.was_instantiated()); |
436 } | 433 } |
437 | 434 |
438 TEST_F(ClientSessionTest, DataChannelCallbackIsCalled) { | 435 TEST_F(ClientSessionTest, DataChannelCallbackIsCalled) { |
439 bool callback_called = false; | 436 bool callback_called = false; |
440 | 437 |
441 data_channel_callbacks_.push_back( | |
442 protocol::DataChannelManager::NameCallbackPair( | |
443 kTestDataChannelCallbackName, | |
444 base::Bind([](bool* callback_was_called, const std::string& name, | |
445 std::unique_ptr<protocol::MessagePipe> pipe) | |
446 -> void { *callback_was_called = true; }, | |
447 &callback_called))); | |
448 | |
449 CreateClientSession(); | 438 CreateClientSession(); |
| 439 client_session_->RegisterDataChannelManagerCallback( |
| 440 kTestDataChannelCallbackName, |
| 441 base::Bind([](bool* callback_was_called, const std::string& name, |
| 442 std::unique_ptr<protocol::MessagePipe> pipe) |
| 443 -> void { *callback_was_called = true; }, |
| 444 &callback_called)); |
450 ConnectClientSession(); | 445 ConnectClientSession(); |
451 | 446 |
452 std::unique_ptr<protocol::MessagePipe> pipe = | 447 std::unique_ptr<protocol::MessagePipe> pipe = |
453 base::WrapUnique(new protocol::FakeMessagePipe(false)); | 448 base::WrapUnique(new protocol::FakeMessagePipe(false)); |
454 | 449 |
455 client_session_->OnIncomingDataChannel(kTestDataChannelCallbackName, | 450 client_session_->OnIncomingDataChannel(kTestDataChannelCallbackName, |
456 std::move(pipe)); | 451 std::move(pipe)); |
457 | 452 |
458 ASSERT_TRUE(callback_called); | 453 ASSERT_TRUE(callback_called); |
459 } | 454 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 CreateClientSession(std::move(session)); | 505 CreateClientSession(std::move(session)); |
511 ConnectClientSession(); | 506 ConnectClientSession(); |
512 ASSERT_FALSE(desktop_environment_factory_->last_desktop_environment() | 507 ASSERT_FALSE(desktop_environment_factory_->last_desktop_environment() |
513 ->options() | 508 ->options() |
514 .desktop_capture_options() | 509 .desktop_capture_options() |
515 ->allow_directx_capturer()); | 510 ->allow_directx_capturer()); |
516 } | 511 } |
517 #endif | 512 #endif |
518 | 513 |
519 } // namespace remoting | 514 } // namespace remoting |
OLD | NEW |