| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test/test_chromoting_client.h" |
| 6 |
| 5 #include <string> | 7 #include <string> |
| 6 | 8 |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 9 #include "remoting/protocol/fake_connection_to_host.h" | 12 #include "remoting/protocol/fake_connection_to_host.h" |
| 10 #include "remoting/signaling/fake_signal_strategy.h" | 13 #include "remoting/signaling/fake_signal_strategy.h" |
| 11 #include "remoting/test/connection_setup_info.h" | 14 #include "remoting/test/connection_setup_info.h" |
| 12 #include "remoting/test/test_chromoting_client.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 namespace remoting { | 17 namespace remoting { |
| 16 namespace test { | 18 namespace test { |
| 17 | 19 |
| 18 using testing::_; | 20 using testing::_; |
| 19 | 21 |
| 20 // Provides base functionality for the TestChromotingClient Tests below. This | 22 // Provides base functionality for the TestChromotingClient Tests below. This |
| 21 // fixture also creates an IO MessageLoop for use by the TestChromotingClient. | 23 // fixture also creates an IO MessageLoop for use by the TestChromotingClient. |
| 22 // Overrides a subset of the RemoteConnectionObserver interface to track | 24 // Overrides a subset of the RemoteConnectionObserver interface to track |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 // Used for result verification. | 37 // Used for result verification. |
| 36 bool is_connected_to_host_ = false; | 38 bool is_connected_to_host_ = false; |
| 37 protocol::ConnectionToHost::State connection_state_ = | 39 protocol::ConnectionToHost::State connection_state_ = |
| 38 protocol::ConnectionToHost::INITIALIZING; | 40 protocol::ConnectionToHost::INITIALIZING; |
| 39 protocol::ErrorCode error_code_ = protocol::OK; | 41 protocol::ErrorCode error_code_ = protocol::OK; |
| 40 | 42 |
| 41 // Used for simulating different conditions for the TestChromotingClient. | 43 // Used for simulating different conditions for the TestChromotingClient. |
| 42 ConnectionSetupInfo connection_setup_info_; | 44 ConnectionSetupInfo connection_setup_info_; |
| 43 FakeConnectionToHost* fake_connection_to_host_ = nullptr; | 45 FakeConnectionToHost* fake_connection_to_host_ = nullptr; |
| 44 | 46 |
| 45 scoped_ptr<TestChromotingClient> test_chromoting_client_; | 47 std::unique_ptr<TestChromotingClient> test_chromoting_client_; |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 // RemoteConnectionObserver interface. | 50 // RemoteConnectionObserver interface. |
| 49 void ConnectionStateChanged(protocol::ConnectionToHost::State state, | 51 void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
| 50 protocol::ErrorCode error_code) override; | 52 protocol::ErrorCode error_code) override; |
| 51 void ConnectionReady(bool ready) override; | 53 void ConnectionReady(bool ready) override; |
| 52 | 54 |
| 53 base::MessageLoopForIO message_loop_; | 55 base::MessageLoopForIO message_loop_; |
| 54 | 56 |
| 55 DISALLOW_COPY_AND_ASSIGN(TestChromotingClientTest); | 57 DISALLOW_COPY_AND_ASSIGN(TestChromotingClientTest); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 TestChromotingClientTest::TestChromotingClientTest() {} | 60 TestChromotingClientTest::TestChromotingClientTest() {} |
| 59 TestChromotingClientTest::~TestChromotingClientTest() {} | 61 TestChromotingClientTest::~TestChromotingClientTest() {} |
| 60 | 62 |
| 61 void TestChromotingClientTest::SetUp() { | 63 void TestChromotingClientTest::SetUp() { |
| 62 test_chromoting_client_.reset(new TestChromotingClient()); | 64 test_chromoting_client_.reset(new TestChromotingClient()); |
| 63 test_chromoting_client_->AddRemoteConnectionObserver(this); | 65 test_chromoting_client_->AddRemoteConnectionObserver(this); |
| 64 | 66 |
| 65 // Pass ownership of the FakeConnectionToHost to the chromoting instance but | 67 // Pass ownership of the FakeConnectionToHost to the chromoting instance but |
| 66 // keep the ptr around so we can use it to simulate state changes. It will | 68 // keep the ptr around so we can use it to simulate state changes. It will |
| 67 // remain valid until |test_chromoting_client_| is destroyed. | 69 // remain valid until |test_chromoting_client_| is destroyed. |
| 68 fake_connection_to_host_ = new FakeConnectionToHost(); | 70 fake_connection_to_host_ = new FakeConnectionToHost(); |
| 69 test_chromoting_client_->SetSignalStrategyForTests(make_scoped_ptr( | 71 test_chromoting_client_->SetSignalStrategyForTests(base::WrapUnique( |
| 70 new FakeSignalStrategy("test_user@faux_address.com/123"))); | 72 new FakeSignalStrategy("test_user@faux_address.com/123"))); |
| 71 test_chromoting_client_->SetConnectionToHostForTests( | 73 test_chromoting_client_->SetConnectionToHostForTests( |
| 72 make_scoped_ptr(fake_connection_to_host_)); | 74 base::WrapUnique(fake_connection_to_host_)); |
| 73 | 75 |
| 74 connection_setup_info_.host_jid = "test_host@faux_address.com/321"; | 76 connection_setup_info_.host_jid = "test_host@faux_address.com/321"; |
| 75 } | 77 } |
| 76 | 78 |
| 77 void TestChromotingClientTest::TearDown() { | 79 void TestChromotingClientTest::TearDown() { |
| 78 test_chromoting_client_->RemoveRemoteConnectionObserver(this); | 80 test_chromoting_client_->RemoveRemoteConnectionObserver(this); |
| 79 fake_connection_to_host_ = nullptr; | 81 fake_connection_to_host_ = nullptr; |
| 80 | 82 |
| 81 // The chromoting instance must be destroyed before the message loop. | 83 // The chromoting instance must be destroyed before the message loop. |
| 82 test_chromoting_client_.reset(); | 84 test_chromoting_client_.reset(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // Close the connection via the TestChromotingClient and verify the error | 195 // Close the connection via the TestChromotingClient and verify the error |
| 194 // state is persisted. | 196 // state is persisted. |
| 195 test_chromoting_client_->EndConnection(); | 197 test_chromoting_client_->EndConnection(); |
| 196 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 198 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
| 197 EXPECT_EQ(protocol::ErrorCode::UNKNOWN_ERROR, error_code_); | 199 EXPECT_EQ(protocol::ErrorCode::UNKNOWN_ERROR, error_code_); |
| 198 EXPECT_FALSE(is_connected_to_host_); | 200 EXPECT_FALSE(is_connected_to_host_); |
| 199 } | 201 } |
| 200 | 202 |
| 201 } // namespace test | 203 } // namespace test |
| 202 } // namespace remoting | 204 } // namespace remoting |
| OLD | NEW |