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/test/connection_setup_info.h" |
9 #include "remoting/test/test_chromoting_client.h" | 10 #include "remoting/test/test_chromoting_client.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 const char kTestUserName[] = "test_user@faux_address.com"; | 14 const char kTestUserName[] = "test_user@faux_address.com"; |
14 const char kAccessToken[] = "faux_access_token"; | 15 const char kAccessToken[] = "faux_access_token"; |
15 } | 16 } |
16 | 17 |
17 namespace remoting { | 18 namespace remoting { |
18 namespace test { | 19 namespace test { |
(...skipping 14 matching lines...) Expand all Loading... |
33 // testing::Test interface. | 34 // testing::Test interface. |
34 void SetUp() override; | 35 void SetUp() override; |
35 void TearDown() override; | 36 void TearDown() override; |
36 | 37 |
37 // Used for result verification. | 38 // Used for result verification. |
38 bool is_connected_to_host_; | 39 bool is_connected_to_host_; |
39 protocol::ConnectionToHost::State connection_state_; | 40 protocol::ConnectionToHost::State connection_state_; |
40 protocol::ErrorCode error_code_; | 41 protocol::ErrorCode error_code_; |
41 | 42 |
42 // Used for simulating different conditions for the TestChromotingClient. | 43 // Used for simulating different conditions for the TestChromotingClient. |
43 RemoteHostInfo remote_host_info_; | 44 ConnectionSetupInfo connection_setup_info_; |
44 FakeConnectionToHost* fake_connection_to_host_; | 45 FakeConnectionToHost* fake_connection_to_host_; |
45 | 46 |
46 scoped_ptr<TestChromotingClient> test_chromoting_client_; | 47 scoped_ptr<TestChromotingClient> test_chromoting_client_; |
47 | 48 |
48 private: | 49 private: |
49 // RemoteConnectionObserver interface. | 50 // RemoteConnectionObserver interface. |
50 void ConnectionStateChanged(protocol::ConnectionToHost::State state, | 51 void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
51 protocol::ErrorCode error_code) override; | 52 protocol::ErrorCode error_code) override; |
52 void ConnectionReady(bool ready) override; | 53 void ConnectionReady(bool ready) override; |
53 | 54 |
(...skipping 16 matching lines...) Expand all Loading... |
70 test_chromoting_client_.reset(new TestChromotingClient()); | 71 test_chromoting_client_.reset(new TestChromotingClient()); |
71 test_chromoting_client_->AddRemoteConnectionObserver(this); | 72 test_chromoting_client_->AddRemoteConnectionObserver(this); |
72 | 73 |
73 // Pass ownership of the FakeConnectionToHost to the chromoting instance but | 74 // Pass ownership of the FakeConnectionToHost to the chromoting instance but |
74 // keep the ptr around so we can use it to simulate state changes. It will | 75 // keep the ptr around so we can use it to simulate state changes. It will |
75 // remain valid until |test_chromoting_client_| is destroyed. | 76 // remain valid until |test_chromoting_client_| is destroyed. |
76 fake_connection_to_host_ = new FakeConnectionToHost(); | 77 fake_connection_to_host_ = new FakeConnectionToHost(); |
77 test_chromoting_client_->SetConnectionToHostForTests( | 78 test_chromoting_client_->SetConnectionToHostForTests( |
78 make_scoped_ptr(fake_connection_to_host_)); | 79 make_scoped_ptr(fake_connection_to_host_)); |
79 | 80 |
80 remote_host_info_.remote_host_status = kRemoteHostStatusReady; | 81 connection_setup_info_.access_token = kAccessToken; |
| 82 connection_setup_info_.user_name = kTestUserName; |
| 83 connection_setup_info_.auth_methods.push_back( |
| 84 protocol::AuthenticationMethod::ThirdParty()); |
81 } | 85 } |
82 | 86 |
83 void TestChromotingClientTest::TearDown() { | 87 void TestChromotingClientTest::TearDown() { |
84 test_chromoting_client_->RemoveRemoteConnectionObserver(this); | 88 test_chromoting_client_->RemoveRemoteConnectionObserver(this); |
85 fake_connection_to_host_ = nullptr; | 89 fake_connection_to_host_ = nullptr; |
86 | 90 |
87 // The chromoting instance must be destroyed before the message loop. | 91 // The chromoting instance must be destroyed before the message loop. |
88 test_chromoting_client_.reset(); | 92 test_chromoting_client_.reset(); |
89 | 93 |
90 // The LibjingleTransportFactory destroys the PortAllocator via a DeleteSoon | 94 // The LibjingleTransportFactory destroys the PortAllocator via a DeleteSoon |
(...skipping 14 matching lines...) Expand all Loading... |
105 } | 109 } |
106 } | 110 } |
107 | 111 |
108 void TestChromotingClientTest::ConnectionReady(bool ready) { | 112 void TestChromotingClientTest::ConnectionReady(bool ready) { |
109 if (ready) { | 113 if (ready) { |
110 is_connected_to_host_ = true; | 114 is_connected_to_host_ = true; |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 TEST_F(TestChromotingClientTest, StartConnectionAndDisconnect) { | 118 TEST_F(TestChromotingClientTest, StartConnectionAndDisconnect) { |
115 test_chromoting_client_->StartConnection(kTestUserName, kAccessToken, | 119 test_chromoting_client_->StartConnection(connection_setup_info_); |
116 remote_host_info_); | |
117 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); | 120 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); |
118 EXPECT_EQ(protocol::OK, error_code_); | 121 EXPECT_EQ(protocol::OK, error_code_); |
119 EXPECT_FALSE(is_connected_to_host_); | 122 EXPECT_FALSE(is_connected_to_host_); |
120 | 123 |
121 // Simulate an AUTHENTICATED message being sent from the Jingle session. | 124 // Simulate an AUTHENTICATED message being sent from the Jingle session. |
122 fake_connection_to_host_->SignalStateChange(protocol::Session::AUTHENTICATED, | 125 fake_connection_to_host_->SignalStateChange(protocol::Session::AUTHENTICATED, |
123 protocol::OK); | 126 protocol::OK); |
124 EXPECT_EQ(protocol::ConnectionToHost::State::AUTHENTICATED, | 127 EXPECT_EQ(protocol::ConnectionToHost::State::AUTHENTICATED, |
125 connection_state_); | 128 connection_state_); |
126 EXPECT_EQ(protocol::OK, error_code_); | 129 EXPECT_EQ(protocol::OK, error_code_); |
(...skipping 12 matching lines...) Expand all Loading... |
139 EXPECT_TRUE(is_connected_to_host_); | 142 EXPECT_TRUE(is_connected_to_host_); |
140 | 143 |
141 test_chromoting_client_->EndConnection(); | 144 test_chromoting_client_->EndConnection(); |
142 EXPECT_EQ(protocol::ConnectionToHost::State::CLOSED, connection_state_); | 145 EXPECT_EQ(protocol::ConnectionToHost::State::CLOSED, connection_state_); |
143 EXPECT_EQ(protocol::OK, error_code_); | 146 EXPECT_EQ(protocol::OK, error_code_); |
144 EXPECT_FALSE(is_connected_to_host_); | 147 EXPECT_FALSE(is_connected_to_host_); |
145 } | 148 } |
146 | 149 |
147 TEST_F(TestChromotingClientTest, | 150 TEST_F(TestChromotingClientTest, |
148 StartConnectionThenFailWithAuthenticationError) { | 151 StartConnectionThenFailWithAuthenticationError) { |
149 test_chromoting_client_->StartConnection(kTestUserName, kAccessToken, | 152 test_chromoting_client_->StartConnection(connection_setup_info_); |
150 remote_host_info_); | |
151 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); | 153 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); |
152 EXPECT_EQ(protocol::OK, error_code_); | 154 EXPECT_EQ(protocol::OK, error_code_); |
153 EXPECT_FALSE(is_connected_to_host_); | 155 EXPECT_FALSE(is_connected_to_host_); |
154 | 156 |
155 fake_connection_to_host_->SignalStateChange(protocol::Session::FAILED, | 157 fake_connection_to_host_->SignalStateChange(protocol::Session::FAILED, |
156 protocol::AUTHENTICATION_FAILED); | 158 protocol::AUTHENTICATION_FAILED); |
157 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 159 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
158 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); | 160 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); |
159 EXPECT_FALSE(is_connected_to_host_); | 161 EXPECT_FALSE(is_connected_to_host_); |
160 | 162 |
161 // Close the connection via the TestChromotingClient and verify the error | 163 // Close the connection via the TestChromotingClient and verify the error |
162 // state is persisted. | 164 // state is persisted. |
163 test_chromoting_client_->EndConnection(); | 165 test_chromoting_client_->EndConnection(); |
164 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 166 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
165 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); | 167 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); |
166 EXPECT_FALSE(is_connected_to_host_); | 168 EXPECT_FALSE(is_connected_to_host_); |
167 } | 169 } |
168 | 170 |
169 TEST_F(TestChromotingClientTest, StartConnectionThenFailWithUnknownError) { | 171 TEST_F(TestChromotingClientTest, StartConnectionThenFailWithUnknownError) { |
170 test_chromoting_client_->StartConnection(kTestUserName, kAccessToken, | 172 test_chromoting_client_->StartConnection(connection_setup_info_); |
171 remote_host_info_); | |
172 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); | 173 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); |
173 EXPECT_EQ(protocol::OK, error_code_); | 174 EXPECT_EQ(protocol::OK, error_code_); |
174 EXPECT_FALSE(is_connected_to_host_); | 175 EXPECT_FALSE(is_connected_to_host_); |
175 | 176 |
176 // Simulate an AUTHENTICATED message being sent from the Jingle session. | 177 // Simulate an AUTHENTICATED message being sent from the Jingle session. |
177 fake_connection_to_host_->SignalStateChange(protocol::Session::AUTHENTICATED, | 178 fake_connection_to_host_->SignalStateChange(protocol::Session::AUTHENTICATED, |
178 protocol::OK); | 179 protocol::OK); |
179 EXPECT_EQ(protocol::ConnectionToHost::State::AUTHENTICATED, | 180 EXPECT_EQ(protocol::ConnectionToHost::State::AUTHENTICATED, |
180 connection_state_); | 181 connection_state_); |
181 EXPECT_EQ(protocol::OK, error_code_); | 182 EXPECT_EQ(protocol::OK, error_code_); |
(...skipping 20 matching lines...) Expand all Loading... |
202 // Close the connection via the TestChromotingClient and verify the error | 203 // Close the connection via the TestChromotingClient and verify the error |
203 // state is persisted. | 204 // state is persisted. |
204 test_chromoting_client_->EndConnection(); | 205 test_chromoting_client_->EndConnection(); |
205 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 206 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
206 EXPECT_EQ(protocol::ErrorCode::UNKNOWN_ERROR, error_code_); | 207 EXPECT_EQ(protocol::ErrorCode::UNKNOWN_ERROR, error_code_); |
207 EXPECT_FALSE(is_connected_to_host_); | 208 EXPECT_FALSE(is_connected_to_host_); |
208 } | 209 } |
209 | 210 |
210 } // namespace test | 211 } // namespace test |
211 } // namespace remoting | 212 } // namespace remoting |
OLD | NEW |