Chromium Code Reviews| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 // To avoid shared resource contention, tests will be run one at a time. | 191 // To avoid shared resource contention, tests will be run one at a time. |
| 191 command_line->AppendSwitch(switches::kSingleProcessTestsSwitchName); | 192 command_line->AppendSwitch(switches::kSingleProcessTestsSwitchName); |
| 192 | 193 |
| 193 if (command_line->HasSwitch(switches::kHelpSwitchName)) { | 194 if (command_line->HasSwitch(switches::kHelpSwitchName)) { |
| 194 PrintUsage(); | 195 PrintUsage(); |
| 195 PrintJsonFileInfo(); | 196 PrintJsonFileInfo(); |
| 196 PrintAuthCodeInfo(); | 197 PrintAuthCodeInfo(); |
| 197 return 0; | 198 return 0; |
| 198 } | 199 } |
| 199 | 200 |
| 200 // Update the logging verbosity level is user specified one. | 201 // Update the logging verbosity level if user specified one. |
| 201 std::string verbosity_level( | 202 std::string verbosity_level( |
| 202 command_line->GetSwitchValueASCII(switches::kLoggingLevelSwitchName)); | 203 command_line->GetSwitchValueASCII(switches::kLoggingLevelSwitchName)); |
| 203 if (!verbosity_level.empty()) { | 204 if (!verbosity_level.empty()) { |
| 204 // Turn on logging for the test_driver and remoting components. | 205 // Turn on logging for the test_driver and remoting components. |
| 205 // This switch is parsed during logging::InitLogging. | 206 // This switch is parsed during logging::InitLogging. |
| 206 command_line->AppendSwitchASCII("vmodule", | 207 command_line->AppendSwitchASCII("vmodule", |
| 207 "*/remoting/*=" + verbosity_level); | 208 "*/remoting/*=" + verbosity_level); |
| 208 logging::LoggingSettings logging_settings; | 209 logging::LoggingSettings logging_settings; |
| 209 logging::InitLogging(logging_settings); | 210 logging::InitLogging(logging_settings); |
| 210 } | 211 } |
| (...skipping 87 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); | |
|
joedow
2015/07/27 21:45:44
Please send an update once your change to add the
tonychun
2015/07/28 17:53:44
The changes have landed and are now together with
| |
| 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.Initialize(); | |
| 311 test_chromoting_client.StartConnection( | 319 test_chromoting_client.StartConnection( |
| 312 it->GenerateConnectionSetupInfo(access_token, username, pin)); | 320 it->GenerateConnectionSetupInfo(access_token, username, pin)); |
| 313 run_loop->Run(); | 321 run_loop->Run(); |
| 322 | |
| 323 observer.DisplayConnectionStats(); | |
| 324 test_chromoting_client.RemoveRemoteConnectionObserver(&observer); | |
| 314 test_chromoting_client.EndConnection(); | 325 test_chromoting_client.EndConnection(); |
| 315 } else { | 326 } else { |
| 316 LOG(ERROR) << "Requested host not found or not ready to connect"; | 327 LOG(ERROR) << "Requested host not found or not ready to connect"; |
| 317 } | 328 } |
| 318 | 329 |
| 319 return 0; | 330 return 0; |
| 320 } | 331 } |
| OLD | NEW |