| 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_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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 | 108 |
| 108 void TestChromotingClientTest::ConnectionReady(bool ready) { | 109 void TestChromotingClientTest::ConnectionReady(bool ready) { |
| 109 if (ready) { | 110 if (ready) { |
| 110 is_connected_to_host_ = true; | 111 is_connected_to_host_ = true; |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 TEST_F(TestChromotingClientTest, StartConnectionAndDisconnect) { | 115 TEST_F(TestChromotingClientTest, StartConnectionAndDisconnect) { |
| 115 test_chromoting_client_->StartConnection(kTestUserName, kAccessToken, | 116 test_chromoting_client_->StartConnection( |
| 116 remote_host_info_); | 117 remote_host_info_.GenerateConnectionInfo(kAccessToken, kTestUserName)); |
| 117 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); | 118 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); |
| 118 EXPECT_EQ(protocol::OK, error_code_); | 119 EXPECT_EQ(protocol::OK, error_code_); |
| 119 EXPECT_FALSE(is_connected_to_host_); | 120 EXPECT_FALSE(is_connected_to_host_); |
| 120 | 121 |
| 121 // Simulate an AUTHENTICATED message being sent from the Jingle session. | 122 // Simulate an AUTHENTICATED message being sent from the Jingle session. |
| 122 fake_connection_to_host_->SignalStateChange(protocol::Session::AUTHENTICATED, | 123 fake_connection_to_host_->SignalStateChange(protocol::Session::AUTHENTICATED, |
| 123 protocol::OK); | 124 protocol::OK); |
| 124 EXPECT_EQ(protocol::ConnectionToHost::State::AUTHENTICATED, | 125 EXPECT_EQ(protocol::ConnectionToHost::State::AUTHENTICATED, |
| 125 connection_state_); | 126 connection_state_); |
| 126 EXPECT_EQ(protocol::OK, error_code_); | 127 EXPECT_EQ(protocol::OK, error_code_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 EXPECT_TRUE(is_connected_to_host_); | 140 EXPECT_TRUE(is_connected_to_host_); |
| 140 | 141 |
| 141 test_chromoting_client_->EndConnection(); | 142 test_chromoting_client_->EndConnection(); |
| 142 EXPECT_EQ(protocol::ConnectionToHost::State::CLOSED, connection_state_); | 143 EXPECT_EQ(protocol::ConnectionToHost::State::CLOSED, connection_state_); |
| 143 EXPECT_EQ(protocol::OK, error_code_); | 144 EXPECT_EQ(protocol::OK, error_code_); |
| 144 EXPECT_FALSE(is_connected_to_host_); | 145 EXPECT_FALSE(is_connected_to_host_); |
| 145 } | 146 } |
| 146 | 147 |
| 147 TEST_F(TestChromotingClientTest, | 148 TEST_F(TestChromotingClientTest, |
| 148 StartConnectionThenFailWithAuthenticationError) { | 149 StartConnectionThenFailWithAuthenticationError) { |
| 149 test_chromoting_client_->StartConnection(kTestUserName, kAccessToken, | 150 test_chromoting_client_->StartConnection( |
| 150 remote_host_info_); | 151 remote_host_info_.GenerateConnectionInfo(kAccessToken, kTestUserName)); |
| 151 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); | 152 EXPECT_EQ(protocol::ConnectionToHost::State::CONNECTING, connection_state_); |
| 152 EXPECT_EQ(protocol::OK, error_code_); | 153 EXPECT_EQ(protocol::OK, error_code_); |
| 153 EXPECT_FALSE(is_connected_to_host_); | 154 EXPECT_FALSE(is_connected_to_host_); |
| 154 | 155 |
| 155 fake_connection_to_host_->SignalStateChange(protocol::Session::FAILED, | 156 fake_connection_to_host_->SignalStateChange(protocol::Session::FAILED, |
| 156 protocol::AUTHENTICATION_FAILED); | 157 protocol::AUTHENTICATION_FAILED); |
| 157 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 158 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
| 158 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); | 159 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); |
| 159 EXPECT_FALSE(is_connected_to_host_); | 160 EXPECT_FALSE(is_connected_to_host_); |
| 160 | 161 |
| 161 // Close the connection via the TestChromotingClient and verify the error | 162 // Close the connection via the TestChromotingClient and verify the error |
| 162 // state is persisted. | 163 // state is persisted. |
| 163 test_chromoting_client_->EndConnection(); | 164 test_chromoting_client_->EndConnection(); |
| 164 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); | 165 EXPECT_EQ(protocol::ConnectionToHost::State::FAILED, connection_state_); |
| 165 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); | 166 EXPECT_EQ(protocol::ErrorCode::AUTHENTICATION_FAILED, error_code_); |
| 166 EXPECT_FALSE(is_connected_to_host_); | 167 EXPECT_FALSE(is_connected_to_host_); |
| 167 } | 168 } |
| 168 | 169 |
| 169 TEST_F(TestChromotingClientTest, StartConnectionThenFailWithUnknownError) { | 170 TEST_F(TestChromotingClientTest, StartConnectionThenFailWithUnknownError) { |
| 170 test_chromoting_client_->StartConnection(kTestUserName, kAccessToken, | 171 test_chromoting_client_->StartConnection( |
| 171 remote_host_info_); | 172 remote_host_info_.GenerateConnectionInfo(kAccessToken, kTestUserName)); |
| 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 |