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 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/test/test_suite.h" | 15 #include "base/test/test_suite.h" |
16 #include "base/test/test_switches.h" | 16 #include "base/test/test_switches.h" |
17 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
18 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
19 #include "remoting/test/access_token_fetcher.h" | 19 #include "remoting/test/access_token_fetcher.h" |
| 20 #include "remoting/test/connection_time_observer.h" |
20 #include "remoting/test/host_info.h" | 21 #include "remoting/test/host_info.h" |
21 #include "remoting/test/host_list_fetcher.h" | 22 #include "remoting/test/host_list_fetcher.h" |
22 #include "remoting/test/refresh_token_store.h" | 23 #include "remoting/test/refresh_token_store.h" |
23 #include "remoting/test/test_chromoting_client.h" | 24 #include "remoting/test/test_chromoting_client.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace switches { | 27 namespace switches { |
27 const char kAuthCodeSwitchName[] = "authcode"; | 28 const char kAuthCodeSwitchName[] = "authcode"; |
28 const char kPinSwitchName[] = "pin"; | 29 const char kPinSwitchName[] = "pin"; |
29 const char kHelpSwitchName[] = "help"; | 30 const char kHelpSwitchName[] = "help"; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 299 |
299 // Check if requested host is online and ready to receive connections. | 300 // Check if requested host is online and ready to receive connections. |
300 auto it = std::find_if(hostlist.begin(), hostlist.end(), | 301 auto it = std::find_if(hostlist.begin(), hostlist.end(), |
301 [&hostname](const remoting::test::HostInfo& host_info) { | 302 [&hostname](const remoting::test::HostInfo& host_info) { |
302 return host_info.host_name == hostname && | 303 return host_info.host_name == hostname && |
303 host_info.IsReadyForConnection(); | 304 host_info.IsReadyForConnection(); |
304 }); | 305 }); |
305 if (it != hostlist.end()) { | 306 if (it != hostlist.end()) { |
306 // Host is online and ready, initiate a remote session. | 307 // Host is online and ready, initiate a remote session. |
307 base::Timer timer(true, false); | 308 base::Timer timer(true, false); |
| 309 remoting::test::ConnectionTimeObserver observer; |
| 310 test_chromoting_client.AddRemoteConnectionObserver(&observer); |
| 311 |
| 312 // The timer will forcefully end the chromoting connection process in |
| 313 // |kConnectionTimeoutSeconds| seconds. The set limit on time to connect |
| 314 // stops the client from waiting indefinitely for a connection. |
308 timer.Start(FROM_HERE, | 315 timer.Start(FROM_HERE, |
309 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds), | 316 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds), |
310 run_loop->QuitClosure()); | 317 run_loop->QuitClosure()); |
| 318 observer.ConnectionStateChanged( |
| 319 remoting::protocol::ConnectionToHost::State::INITIALIZING, |
| 320 remoting::protocol::ErrorCode::OK); |
311 test_chromoting_client.StartConnection( | 321 test_chromoting_client.StartConnection( |
312 it->GenerateConnectionSetupInfo(access_token, username, pin)); | 322 it->GenerateConnectionSetupInfo(access_token, username, pin)); |
313 run_loop->Run(); | 323 run_loop->Run(); |
| 324 |
| 325 observer.DisplayConnectionStats(); |
| 326 test_chromoting_client.RemoveRemoteConnectionObserver(&observer); |
314 test_chromoting_client.EndConnection(); | 327 test_chromoting_client.EndConnection(); |
315 } else { | 328 } else { |
316 LOG(ERROR) << "Requested host not found or not ready to connect"; | 329 LOG(ERROR) << "Requested host not found or not ready to connect"; |
317 } | 330 } |
318 | 331 |
319 return 0; | 332 return 0; |
320 } | 333 } |
OLD | NEW |