| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 protocol::ClipboardEvent result; | 89 protocol::ClipboardEvent result; |
| 90 result.set_mime_type(kMimeTypeTextUtf8); | 90 result.set_mime_type(kMimeTypeTextUtf8); |
| 91 result.set_data(text); | 91 result.set_data(text); |
| 92 return result; | 92 return result; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 class ClientSessionTest : public testing::Test { | 97 class ClientSessionTest : public testing::Test { |
| 98 public: | 98 public: |
| 99 ClientSessionTest() : client_jid_("user@domain/rest-of-jid") {} | 99 ClientSessionTest() |
| 100 : message_loop_(base::MessageLoop::TYPE_IO), |
| 101 client_jid_("user@domain/rest-of-jid") {} |
| 100 | 102 |
| 101 void SetUp() override; | 103 void SetUp() override; |
| 102 void TearDown() override; | 104 void TearDown() override; |
| 103 | 105 |
| 104 // Creates the client session. | 106 // Creates the client session. |
| 105 void CreateClientSession(); | 107 void CreateClientSession(); |
| 106 | 108 |
| 107 protected: | 109 protected: |
| 108 // Notifies the client session that the client connection has been | 110 // Notifies the client session that the client connection has been |
| 109 // authenticated and channels have been connected. This effectively enables | 111 // authenticated and channels have been connected. This effectively enables |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void ClientSessionTest::TearDown() { | 164 void ClientSessionTest::TearDown() { |
| 163 if (client_session_) { | 165 if (client_session_) { |
| 164 client_session_->DisconnectSession(protocol::OK); | 166 client_session_->DisconnectSession(protocol::OK); |
| 165 client_session_.reset(); | 167 client_session_.reset(); |
| 166 desktop_environment_factory_.reset(); | 168 desktop_environment_factory_.reset(); |
| 167 } | 169 } |
| 168 | 170 |
| 169 // Clear out |task_runner_| reference so the loop can quit, and run it until | 171 // Clear out |task_runner_| reference so the loop can quit, and run it until |
| 170 // it does. | 172 // it does. |
| 171 task_runner_ = nullptr; | 173 task_runner_ = nullptr; |
| 172 run_loop_.Run(); | 174 run_loop_.QuitWhenIdle(); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void ClientSessionTest::CreateClientSession() { | 177 void ClientSessionTest::CreateClientSession() { |
| 176 // Mock protocol::Session APIs called directly by ClientSession. | 178 // Mock protocol::Session APIs called directly by ClientSession. |
| 177 std::unique_ptr<protocol::MockSession> session(new MockSession()); | 179 std::unique_ptr<protocol::MockSession> session(new MockSession()); |
| 178 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(*session_config_)); | 180 EXPECT_CALL(*session, config()).WillRepeatedly(ReturnRef(*session_config_)); |
| 179 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); | 181 EXPECT_CALL(*session, jid()).WillRepeatedly(ReturnRef(client_jid_)); |
| 180 | 182 |
| 181 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. | 183 // Mock protocol::ConnectionToClient APIs called directly by ClientSession. |
| 182 // HostStub is not touched by ClientSession, so we can safely pass nullptr. | 184 // HostStub is not touched by ClientSession, so we can safely pass nullptr. |
| 183 std::unique_ptr<protocol::FakeConnectionToClient> connection( | 185 std::unique_ptr<protocol::FakeConnectionToClient> connection( |
| 184 new protocol::FakeConnectionToClient(std::move(session))); | 186 new protocol::FakeConnectionToClient(std::move(session))); |
| 185 connection->set_client_stub(&client_stub_); | 187 connection->set_client_stub(&client_stub_); |
| 186 connection_ = connection.get(); | 188 connection_ = connection.get(); |
| 187 | 189 |
| 188 client_session_.reset(new ClientSession( | 190 client_session_.reset(new ClientSession( |
| 191 *ChromotingHostContext::CreateForTest(task_runner_), |
| 189 &session_event_handler_, | 192 &session_event_handler_, |
| 190 task_runner_, // Audio thread. | |
| 191 std::move(connection), desktop_environment_factory_.get(), | 193 std::move(connection), desktop_environment_factory_.get(), |
| 192 base::TimeDelta(), nullptr, extensions_)); | 194 base::TimeDelta(), nullptr, extensions_)); |
| 193 } | 195 } |
| 194 | 196 |
| 195 void ClientSessionTest::ConnectClientSession() { | 197 void ClientSessionTest::ConnectClientSession() { |
| 196 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); | 198 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_)); |
| 197 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); | 199 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_)); |
| 198 | 200 |
| 199 // Stubs should be set only after connection is authenticated. | 201 // Stubs should be set only after connection is authenticated. |
| 200 EXPECT_FALSE(connection_->clipboard_stub()); | 202 EXPECT_FALSE(connection_->clipboard_stub()); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 client_session_->DeliverClientMessage(message1); | 411 client_session_->DeliverClientMessage(message1); |
| 410 protocol::ExtensionMessage message3; | 412 protocol::ExtensionMessage message3; |
| 411 message3.set_type("ext3"); | 413 message3.set_type("ext3"); |
| 412 message3.set_data("data"); | 414 message3.set_data("data"); |
| 413 client_session_->DeliverClientMessage(message3); | 415 client_session_->DeliverClientMessage(message3); |
| 414 protocol::ExtensionMessage message4; | 416 protocol::ExtensionMessage message4; |
| 415 message4.set_type("ext4"); | 417 message4.set_type("ext4"); |
| 416 message4.set_data("data"); | 418 message4.set_data("data"); |
| 417 client_session_->DeliverClientMessage(message4); | 419 client_session_->DeliverClientMessage(message4); |
| 418 | 420 |
| 419 base::RunLoop().RunUntilIdle(); | 421 base::RunLoop().QuitWhenIdle(); |
| 420 | 422 |
| 421 // ext1 was instantiated and sent a message, and did not wrap anything. | 423 // ext1 was instantiated and sent a message, and did not wrap anything. |
| 422 EXPECT_TRUE(extension1.was_instantiated()); | 424 EXPECT_TRUE(extension1.was_instantiated()); |
| 423 EXPECT_TRUE(extension1.has_handled_message()); | 425 EXPECT_TRUE(extension1.has_handled_message()); |
| 424 | 426 |
| 425 // ext2 was instantiated but not sent a message, and wrapped video encoder. | 427 // ext2 was instantiated but not sent a message, and wrapped video encoder. |
| 426 EXPECT_TRUE(extension2.was_instantiated()); | 428 EXPECT_TRUE(extension2.was_instantiated()); |
| 427 EXPECT_FALSE(extension2.has_handled_message()); | 429 EXPECT_FALSE(extension2.has_handled_message()); |
| 428 | 430 |
| 429 // ext3 was sent a message but not instantiated. | 431 // ext3 was sent a message but not instantiated. |
| 430 EXPECT_FALSE(extension3.was_instantiated()); | 432 EXPECT_FALSE(extension3.was_instantiated()); |
| 431 } | 433 } |
| 432 | 434 |
| 433 } // namespace remoting | 435 } // namespace remoting |
| OLD | NEW |