| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/task_scheduler/task_scheduler.h" | 12 #include "base/task_scheduler/task_scheduler.h" |
| 13 #include "base/test/launcher/unit_test_launcher.h" | 13 #include "base/test/launcher/unit_test_launcher.h" |
| 14 #include "base/test/test_suite.h" | 14 #include "base/test/test_suite.h" |
| 15 #include "base/test/test_switches.h" | 15 #include "base/test/test_switches.h" |
| 16 #include "google_apis/google_api_keys.h" | 16 #include "google_apis/google_api_keys.h" |
| 17 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
| 18 #include "remoting/test/chromoting_test_driver_environment.h" | 18 #include "remoting/test/chromoting_test_driver_environment.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace switches { | 21 namespace switches { |
| 22 const char kAuthCodeSwitchName[] = "authcode"; | 22 const char kAuthCodeSwitchName[] = "authcode"; |
| 23 const char kHelpSwitchName[] = "help"; | 23 const char kHelpSwitchName[] = "help"; |
| 24 const char kHostNameSwitchName[] = "hostname"; | 24 const char kHostNameSwitchName[] = "hostname"; |
| 25 const char kHostJidSwitchName[] = "hostjid"; | 25 const char kHostJidSwitchName[] = "hostjid"; |
| 26 const char kLoggingLevelSwitchName[] = "verbosity"; | 26 const char kLoggingLevelSwitchName[] = "verbosity"; |
| 27 const char kPinSwitchName[] = "pin"; | 27 const char kPinSwitchName[] = "pin"; |
| 28 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; | 28 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; |
| 29 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; | 29 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; |
| 30 const char kShowHostListSwitchName[] = "show-host-list"; |
| 30 const char kTestEnvironmentSwitchName[] = "use-test-env"; | 31 const char kTestEnvironmentSwitchName[] = "use-test-env"; |
| 31 const char kUserNameSwitchName[] = "username"; | 32 const char kUserNameSwitchName[] = "username"; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 const char kChromotingAuthScopeValues[] = | 36 const char kChromotingAuthScopeValues[] = |
| 36 "https://www.googleapis.com/auth/chromoting " | 37 "https://www.googleapis.com/auth/chromoting " |
| 37 "https://www.googleapis.com/auth/googletalk " | 38 "https://www.googleapis.com/auth/googletalk " |
| 38 "https://www.googleapis.com/auth/userinfo.email"; | 39 "https://www.googleapis.com/auth/userinfo.email"; |
| 39 | 40 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 printf("************************************\n"); | 62 printf("************************************\n"); |
| 62 | 63 |
| 63 printf("\nUsage:\n"); | 64 printf("\nUsage:\n"); |
| 64 printf(" chromoting_test_driver --username=<example@gmail.com> [options]" | 65 printf(" chromoting_test_driver --username=<example@gmail.com> [options]" |
| 65 " --hostname=<example hostname>\n"); | 66 " --hostname=<example hostname>\n"); |
| 66 printf("\nRequired Parameters:\n"); | 67 printf("\nRequired Parameters:\n"); |
| 67 printf(" %s: Specifies which account to use when running tests\n", | 68 printf(" %s: Specifies which account to use when running tests\n", |
| 68 switches::kUserNameSwitchName); | 69 switches::kUserNameSwitchName); |
| 69 printf(" %s: Specifies which host to connect to when running tests\n", | 70 printf(" %s: Specifies which host to connect to when running tests\n", |
| 70 switches::kHostNameSwitchName); | 71 switches::kHostNameSwitchName); |
| 72 printf( |
| 73 " %s: Retrieves and displays the connection status for all known " |
| 74 "hosts, no tests will be run\n", |
| 75 switches::kShowHostListSwitchName); |
| 71 printf("\nOptional Parameters:\n"); | 76 printf("\nOptional Parameters:\n"); |
| 72 printf(" %s: Exchanged for a refresh and access token for authentication\n", | 77 printf(" %s: Exchanged for a refresh and access token for authentication\n", |
| 73 switches::kAuthCodeSwitchName); | 78 switches::kAuthCodeSwitchName); |
| 74 printf(" %s: Displays additional usage information\n", | 79 printf(" %s: Displays additional usage information\n", |
| 75 switches::kHelpSwitchName); | 80 switches::kHelpSwitchName); |
| 76 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", | 81 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", |
| 77 switches::kRefreshTokenPathSwitchName); | 82 switches::kRefreshTokenPathSwitchName); |
| 78 printf(" %s: Specifies the optional logging level of the tool (0-3)." | 83 printf(" %s: Specifies the optional logging level of the tool (0-3)." |
| 79 " [default: off]\n", switches::kLoggingLevelSwitchName); | 84 " [default: off]\n", switches::kLoggingLevelSwitchName); |
| 80 printf( | 85 printf( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 std::string auth_code = | 218 std::string auth_code = |
| 214 command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName); | 219 command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName); |
| 215 options.refresh_token_file_path = | 220 options.refresh_token_file_path = |
| 216 command_line->GetSwitchValuePath(switches::kRefreshTokenPathSwitchName); | 221 command_line->GetSwitchValuePath(switches::kRefreshTokenPathSwitchName); |
| 217 | 222 |
| 218 // The host name determines which host to initiate a session with from the | 223 // The host name determines which host to initiate a session with from the |
| 219 // host list returned from the directory service. | 224 // host list returned from the directory service. |
| 220 options.host_name = | 225 options.host_name = |
| 221 command_line->GetSwitchValueASCII(switches::kHostNameSwitchName); | 226 command_line->GetSwitchValueASCII(switches::kHostNameSwitchName); |
| 222 | 227 |
| 223 if (options.host_name.empty()) { | 228 if (!options.host_name.empty()) { |
| 229 VLOG(1) << "host_name: '" << options.host_name << "'"; |
| 230 } else if (command_line->HasSwitch(switches::kShowHostListSwitchName)) { |
| 231 options.host_name = "unspecified"; |
| 232 } else { |
| 224 LOG(ERROR) << "No hostname passed in, connect to host requires hostname!"; | 233 LOG(ERROR) << "No hostname passed in, connect to host requires hostname!"; |
| 225 return -1; | 234 return -1; |
| 226 } | 235 } |
| 227 VLOG(1) << "host_name: '" << options.host_name << "'"; | |
| 228 | 236 |
| 229 options.host_jid = | 237 options.host_jid = |
| 230 command_line->GetSwitchValueASCII(switches::kHostJidSwitchName); | 238 command_line->GetSwitchValueASCII(switches::kHostJidSwitchName); |
| 231 VLOG(1) << "host_jid: '" << options.host_jid << "'"; | 239 VLOG(1) << "host_jid: '" << options.host_jid << "'"; |
| 232 | 240 |
| 233 options.pin = command_line->GetSwitchValueASCII(switches::kPinSwitchName); | 241 options.pin = command_line->GetSwitchValueASCII(switches::kPinSwitchName); |
| 234 | 242 |
| 235 options.use_test_environment = | 243 options.use_test_environment = |
| 236 command_line->HasSwitch(switches::kTestEnvironmentSwitchName); | 244 command_line->HasSwitch(switches::kTestEnvironmentSwitchName); |
| 237 | 245 |
| 238 // Create and register our global test data object. It will handle | 246 // Create and register our global test data object. It will handle |
| 239 // retrieving an access token or host list for the user. The GTest framework | 247 // retrieving an access token or host list for the user. The GTest framework |
| 240 // will own the lifetime of this object once it is registered below. | 248 // will own the lifetime of this object once it is registered below. |
| 241 std::unique_ptr<remoting::test::ChromotingTestDriverEnvironment> shared_data( | 249 std::unique_ptr<remoting::test::ChromotingTestDriverEnvironment> shared_data( |
| 242 new remoting::test::ChromotingTestDriverEnvironment(options)); | 250 new remoting::test::ChromotingTestDriverEnvironment(options)); |
| 243 | 251 |
| 244 if (!shared_data->Initialize(auth_code)) { | 252 if (!shared_data->Initialize(auth_code)) { |
| 245 VLOG(1) << "Failed to initialize ChromotingTestDriverEnvironment instance."; | 253 VLOG(1) << "Failed to initialize ChromotingTestDriverEnvironment instance."; |
| 246 // If we failed to initialize our shared data object, then bail. | 254 // If we failed to initialize our shared data object, then bail. |
| 247 return -1; | 255 return -1; |
| 248 } | 256 } |
| 249 | 257 |
| 258 if (command_line->HasSwitch(switches::kShowHostListSwitchName)) { |
| 259 // When this flag is specified, we will show the host list and exit. |
| 260 shared_data->RefreshHostList(); |
| 261 shared_data->DisplayHostList(); |
| 262 return 0; |
| 263 } |
| 264 |
| 250 // This method is necessary as there are occasional propagation delays in the | 265 // This method is necessary as there are occasional propagation delays in the |
| 251 // backend and we don't want the test to fail because of that. | 266 // backend and we don't want the test to fail because of that. |
| 252 if (!shared_data->WaitForHostOnline(options.host_jid, options.host_name)) { | 267 if (!shared_data->WaitForHostOnline()) { |
| 253 VLOG(1) << "The expected host was not available for connections."; | 268 VLOG(1) << "The expected host was not available for connections."; |
| 254 // Host is not online. No point running further tests. | 269 // Host is not online. No point running further tests. |
| 255 return -1; | 270 return -1; |
| 256 } | 271 } |
| 257 | 272 |
| 273 if (options.pin.empty()) { |
| 274 LOG(WARNING) << "No PIN specified, tests may not run reliably."; |
| 275 } |
| 276 |
| 258 // Since we've successfully set up our shared_data object, we'll assign the | 277 // Since we've successfully set up our shared_data object, we'll assign the |
| 259 // value to our global* and transfer ownership to the framework. | 278 // value to our global* and transfer ownership to the framework. |
| 260 remoting::test::g_chromoting_shared_data = shared_data.release(); | 279 remoting::test::g_chromoting_shared_data = shared_data.release(); |
| 261 testing::AddGlobalTestEnvironment(remoting::test::g_chromoting_shared_data); | 280 testing::AddGlobalTestEnvironment(remoting::test::g_chromoting_shared_data); |
| 262 | 281 |
| 263 // Running the tests serially will avoid clients from connecting to the same | 282 // Running the tests serially will avoid clients from connecting to the same |
| 264 // host. | 283 // host. |
| 265 #if defined(OS_IOS) | 284 #if defined(OS_IOS) |
| 266 return base::LaunchUnitTests( | 285 return base::LaunchUnitTests( |
| 267 argc, argv, | 286 argc, argv, |
| 268 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 287 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
| 269 #else | 288 #else |
| 270 return base::LaunchUnitTestsSerially( | 289 return base::LaunchUnitTestsSerially( |
| 271 argc, argv, | 290 argc, argv, |
| 272 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 291 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
| 273 #endif | 292 #endif |
| 274 } | 293 } |
| OLD | NEW |