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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "remoting/protocol/fake_connection_to_host.h" | 8 #include "remoting/protocol/fake_connection_to_host.h" |
9 #include "remoting/signaling/fake_signal_strategy.h" | |
9 #include "remoting/test/connection_setup_info.h" | 10 #include "remoting/test/connection_setup_info.h" |
10 #include "remoting/test/test_chromoting_client.h" | 11 #include "remoting/test/test_chromoting_client.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace { | |
14 const char kTestUserName[] = "test_user@faux_address.com"; | |
15 const char kAccessToken[] = "faux_access_token"; | |
16 } | |
17 | |
18 namespace remoting { | 14 namespace remoting { |
19 namespace test { | 15 namespace test { |
20 | 16 |
21 using testing::_; | 17 using testing::_; |
22 | 18 |
23 // Provides base functionality for the TestChromotingClient Tests below. This | 19 // Provides base functionality for the TestChromotingClient Tests below. This |
24 // fixture also creates an IO MessageLoop for use by the TestChromotingClient. | 20 // fixture also creates an IO MessageLoop for use by the TestChromotingClient. |
25 // Overrides a subset of the RemoteConnectionObserver interface to track | 21 // Overrides a subset of the RemoteConnectionObserver interface to track |
26 // connection status changes for result verification. | 22 // connection status changes for result verification. |
27 class TestChromotingClientTest : public ::testing::Test, | 23 class TestChromotingClientTest : public ::testing::Test, |
28 public RemoteConnectionObserver { | 24 public RemoteConnectionObserver { |
29 public: | 25 public: |
30 TestChromotingClientTest(); | 26 TestChromotingClientTest(); |
31 ~TestChromotingClientTest() override; | 27 ~TestChromotingClientTest() override; |
32 | 28 |
33 protected: | 29 protected: |
34 // testing::Test interface. | 30 // testing::Test interface. |
35 void SetUp() override; | 31 void SetUp() override; |
36 void TearDown() override; | 32 void TearDown() override; |
37 | 33 |
38 // Used for result verification. | 34 // Used for result verification. |
39 bool is_connected_to_host_; | 35 bool is_connected_to_host_ =false; |
joedow
2015/12/17 16:59:45
add space -> "= false;"
Sergey Ulanov
2015/12/17 17:32:32
Done.
| |
40 protocol::ConnectionToHost::State connection_state_; | 36 protocol::ConnectionToHost::State connection_state_ = |
41 protocol::ErrorCode error_code_; | 37 protocol::ConnectionToHost::INITIALIZING; |
38 protocol::ErrorCode error_code_ = protocol::OK; | |
42 | 39 |
43 // Used for simulating different conditions for the TestChromotingClient. | 40 // Used for simulating different conditions for the TestChromotingClient. |
44 ConnectionSetupInfo connection_setup_info_; | 41 ConnectionSetupInfo connection_setup_info_; |
45 FakeConnectionToHost* fake_connection_to_host_; | 42 FakeConnectionToHost* fake_connection_to_host_ = nullptr; |
46 | 43 |
47 scoped_ptr<TestChromotingClient> test_chromoting_client_; | 44 scoped_ptr<TestChromotingClient> test_chromoting_client_; |
48 | 45 |
49 private: | 46 private: |
50 // RemoteConnectionObserver interface. | 47 // RemoteConnectionObserver interface. |
51 void ConnectionStateChanged(protocol::ConnectionToHost::State state, | 48 void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
52 protocol::ErrorCode error_code) override; | 49 protocol::ErrorCode error_code) override; |
53 void ConnectionReady(bool ready) override; | 50 void ConnectionReady(bool ready) override; |
54 | 51 |
55 base::MessageLoopForIO message_loop_; | 52 base::MessageLoopForIO message_loop_; |
56 | 53 |
57 DISALLOW_COPY_AND_ASSIGN(TestChromotingClientTest); | 54 DISALLOW_COPY_AND_ASSIGN(TestChromotingClientTest); |
58 }; | 55 }; |
59 | 56 |
60 TestChromotingClientTest::TestChromotingClientTest() | 57 TestChromotingClientTest::TestChromotingClientTest() {} |
61 : is_connected_to_host_(false), | 58 TestChromotingClientTest::~TestChromotingClientTest() {} |
62 connection_state_(protocol::ConnectionToHost::INITIALIZING), | |
63 error_code_(protocol::OK), | |
64 fake_connection_to_host_(nullptr) { | |
65 } | |
66 | |
67 TestChromotingClientTest::~TestChromotingClientTest() { | |
68 } | |
69 | 59 |
70 void TestChromotingClientTest::SetUp() { | 60 void TestChromotingClientTest::SetUp() { |
71 test_chromoting_client_.reset(new TestChromotingClient()); | 61 test_chromoting_client_.reset(new TestChromotingClient()); |
72 test_chromoting_client_->AddRemoteConnectionObserver(this); | 62 test_chromoting_client_->AddRemoteConnectionObserver(this); |
73 | 63 |
74 // Pass ownership of the FakeConnectionToHost to the chromoting instance but | 64 // Pass ownership of the FakeConnectionToHost to the chromoting instance but |
75 // keep the ptr around so we can use it to simulate state changes. It will | 65 // keep the ptr around so we can use it to simulate state changes. It will |
76 // remain valid until |test_chromoting_client_| is destroyed. | 66 // remain valid until |test_chromoting_client_| is destroyed. |
77 fake_connection_to_host_ = new FakeConnectionToHost(); | 67 fake_connection_to_host_ = new FakeConnectionToHost(); |
68 test_chromoting_client_->SetSignalStrategyForTests(make_scoped_ptr( | |
69 new FakeSignalStrategy("test_user@faux_address.com/123"))); | |
78 test_chromoting_client_->SetConnectionToHostForTests( | 70 test_chromoting_client_->SetConnectionToHostForTests( |
79 make_scoped_ptr(fake_connection_to_host_)); | 71 make_scoped_ptr(fake_connection_to_host_)); |
80 | 72 |
81 connection_setup_info_.access_token = kAccessToken; | 73 connection_setup_info_.host_jid = "test_host@faux_address.com/321"; |
82 connection_setup_info_.user_name = kTestUserName; | |
83 connection_setup_info_.auth_methods.push_back( | 74 connection_setup_info_.auth_methods.push_back( |
84 protocol::AuthenticationMethod::ThirdParty()); | 75 protocol::AuthenticationMethod::ThirdParty()); |
85 } | 76 } |
86 | 77 |
87 void TestChromotingClientTest::TearDown() { | 78 void TestChromotingClientTest::TearDown() { |
88 test_chromoting_client_->RemoveRemoteConnectionObserver(this); | 79 test_chromoting_client_->RemoveRemoteConnectionObserver(this); |
89 fake_connection_to_host_ = nullptr; | 80 fake_connection_to_host_ = nullptr; |
90 | 81 |
91 // The chromoting instance must be destroyed before the message loop. | 82 // The chromoting instance must be destroyed before the message loop. |
92 test_chromoting_client_.reset(); | 83 test_chromoting_client_.reset(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 // Close the connection via the TestChromotingClient and verify the error | 194 // Close the connection via the TestChromotingClient and verify the error |
204 // state is persisted. | 195 // state is persisted. |
205 test_chromoting_client_->EndConnection(); | 196 test_chromoting_client_->EndConnection(); |
206 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 197 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
207 EXPECT_EQ(protocol::ErrorCode::UNKNOWN_ERROR, error_code_); | 198 EXPECT_EQ(protocol::ErrorCode::UNKNOWN_ERROR, error_code_); |
208 EXPECT_FALSE(is_connected_to_host_); | 199 EXPECT_FALSE(is_connected_to_host_); |
209 } | 200 } |
210 | 201 |
211 } // namespace test | 202 } // namespace test |
212 } // namespace remoting | 203 } // namespace remoting |
OLD | NEW |