| 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/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/test/launcher/unit_test_launcher.h" | 12 #include "base/test/launcher/unit_test_launcher.h" |
| 12 #include "base/test/test_suite.h" | 13 #include "base/test/test_suite.h" |
| 13 #include "base/test/test_switches.h" | 14 #include "base/test/test_switches.h" |
| 14 #include "google_apis/google_api_keys.h" | 15 #include "google_apis/google_api_keys.h" |
| 15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 16 #include "remoting/test/chromoting_test_driver_environment.h" | 17 #include "remoting/test/chromoting_test_driver_environment.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace switches { | 20 namespace switches { |
| 20 const char kAuthCodeSwitchName[] = "authcode"; | 21 const char kAuthCodeSwitchName[] = "authcode"; |
| 21 const char kHelpSwitchName[] = "help"; | 22 const char kHelpSwitchName[] = "help"; |
| 22 const char kHostNameSwitchName[] = "hostname"; | 23 const char kHostNameSwitchName[] = "hostname"; |
| 23 const char kHostJidSwitchName[] = "hostjid"; | 24 const char kHostJidSwitchName[] = "hostjid"; |
| 24 const char kLoggingLevelSwitchName[] = "verbosity"; | 25 const char kLoggingLevelSwitchName[] = "verbosity"; |
| 25 const char kPinSwitchName[] = "pin"; | 26 const char kPinSwitchName[] = "pin"; |
| 26 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; | 27 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; |
| 27 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; | 28 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; |
| 29 const char kTestEnvironmentSwitchName[] = "use-test-env"; |
| 28 const char kUserNameSwitchName[] = "username"; | 30 const char kUserNameSwitchName[] = "username"; |
| 29 } | 31 } |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 const char kChromotingAuthScopeValues[] = | 34 const char kChromotingAuthScopeValues[] = |
| 33 "https://www.googleapis.com/auth/chromoting " | 35 "https://www.googleapis.com/auth/chromoting " |
| 34 "https://www.googleapis.com/auth/googletalk " | 36 "https://www.googleapis.com/auth/googletalk " |
| 35 "https://www.googleapis.com/auth/userinfo.email"; | 37 "https://www.googleapis.com/auth/userinfo.email"; |
| 36 | 38 |
| 37 std::string GetAuthorizationCodeUri() { | 39 std::string GetAuthorizationCodeUri() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 switches::kHostNameSwitchName); | 69 switches::kHostNameSwitchName); |
| 68 printf("\nOptional Parameters:\n"); | 70 printf("\nOptional Parameters:\n"); |
| 69 printf(" %s: Exchanged for a refresh and access token for authentication\n", | 71 printf(" %s: Exchanged for a refresh and access token for authentication\n", |
| 70 switches::kAuthCodeSwitchName); | 72 switches::kAuthCodeSwitchName); |
| 71 printf(" %s: Displays additional usage information\n", | 73 printf(" %s: Displays additional usage information\n", |
| 72 switches::kHelpSwitchName); | 74 switches::kHelpSwitchName); |
| 73 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", | 75 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", |
| 74 switches::kRefreshTokenPathSwitchName); | 76 switches::kRefreshTokenPathSwitchName); |
| 75 printf(" %s: Specifies the optional logging level of the tool (0-3)." | 77 printf(" %s: Specifies the optional logging level of the tool (0-3)." |
| 76 " [default: off]\n", switches::kLoggingLevelSwitchName); | 78 " [default: off]\n", switches::kLoggingLevelSwitchName); |
| 79 printf( |
| 80 " %s: Specifies that the test environment APIs should be used." |
| 81 " [default: false]\n", |
| 82 switches::kTestEnvironmentSwitchName); |
| 77 } | 83 } |
| 78 | 84 |
| 79 void PrintAuthCodeInfo() { | 85 void PrintAuthCodeInfo() { |
| 80 printf("\n*******************************\n"); | 86 printf("\n*******************************\n"); |
| 81 printf("*** Auth Code Example Usage ***\n"); | 87 printf("*** Auth Code Example Usage ***\n"); |
| 82 printf("*******************************\n\n"); | 88 printf("*******************************\n\n"); |
| 83 | 89 |
| 84 printf("If this is the first time you are running the tool,\n"); | 90 printf("If this is the first time you are running the tool,\n"); |
| 85 printf("you will need to provide an authorization code.\n"); | 91 printf("you will need to provide an authorization code.\n"); |
| 86 printf("This code will be exchanged for a long term refresh token which\n"); | 92 printf("This code will be exchanged for a long term refresh token which\n"); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 " --%s=./example_file.json\n\n", | 137 " --%s=./example_file.json\n\n", |
| 132 switches::kUserNameSwitchName, "username1@fauxdomain.com", | 138 switches::kUserNameSwitchName, "username1@fauxdomain.com", |
| 133 switches::kHostNameSwitchName, switches::kRefreshTokenPathSwitchName); | 139 switches::kHostNameSwitchName, switches::kRefreshTokenPathSwitchName); |
| 134 } | 140 } |
| 135 | 141 |
| 136 } // namespace | 142 } // namespace |
| 137 | 143 |
| 138 int main(int argc, char* argv[]) { | 144 int main(int argc, char* argv[]) { |
| 139 base::TestSuite test_suite(argc, argv); | 145 base::TestSuite test_suite(argc, argv); |
| 140 base::MessageLoopForIO message_loop; | 146 base::MessageLoopForIO message_loop; |
| 147 base::FeatureList::InitializeInstance(std::string(), std::string()); |
| 141 | 148 |
| 142 if (!base::CommandLine::InitializedForCurrentProcess()) { | 149 if (!base::CommandLine::InitializedForCurrentProcess()) { |
| 143 if (!base::CommandLine::Init(argc, argv)) { | 150 if (!base::CommandLine::Init(argc, argv)) { |
| 144 LOG(ERROR) << "Failed to initialize command line singleton."; | 151 LOG(ERROR) << "Failed to initialize command line singleton."; |
| 145 return -1; | 152 return -1; |
| 146 } | 153 } |
| 147 } | 154 } |
| 148 | 155 |
| 149 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 156 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 150 DCHECK(command_line); | 157 DCHECK(command_line); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return -1; | 221 return -1; |
| 215 } | 222 } |
| 216 VLOG(1) << "host_name: '" << options.host_name << "'"; | 223 VLOG(1) << "host_name: '" << options.host_name << "'"; |
| 217 | 224 |
| 218 options.host_jid = | 225 options.host_jid = |
| 219 command_line->GetSwitchValueASCII(switches::kHostJidSwitchName); | 226 command_line->GetSwitchValueASCII(switches::kHostJidSwitchName); |
| 220 VLOG(1) << "host_jid: '" << options.host_jid << "'"; | 227 VLOG(1) << "host_jid: '" << options.host_jid << "'"; |
| 221 | 228 |
| 222 options.pin = command_line->GetSwitchValueASCII(switches::kPinSwitchName); | 229 options.pin = command_line->GetSwitchValueASCII(switches::kPinSwitchName); |
| 223 | 230 |
| 231 options.use_test_environment = |
| 232 command_line->HasSwitch(switches::kTestEnvironmentSwitchName); |
| 233 |
| 224 // Create and register our global test data object. It will handle | 234 // Create and register our global test data object. It will handle |
| 225 // retrieving an access token or host list for the user. The GTest framework | 235 // retrieving an access token or host list for the user. The GTest framework |
| 226 // will own the lifetime of this object once it is registered below. | 236 // will own the lifetime of this object once it is registered below. |
| 227 std::unique_ptr<remoting::test::ChromotingTestDriverEnvironment> shared_data( | 237 std::unique_ptr<remoting::test::ChromotingTestDriverEnvironment> shared_data( |
| 228 new remoting::test::ChromotingTestDriverEnvironment(options)); | 238 new remoting::test::ChromotingTestDriverEnvironment(options)); |
| 229 | 239 |
| 230 if (!shared_data->Initialize(auth_code)) { | 240 if (!shared_data->Initialize(auth_code)) { |
| 231 VLOG(1) << "Failed to initialize ChromotingTestDriverEnvironment instance."; | 241 VLOG(1) << "Failed to initialize ChromotingTestDriverEnvironment instance."; |
| 232 // If we failed to initialize our shared data object, then bail. | 242 // If we failed to initialize our shared data object, then bail. |
| 233 return -1; | 243 return -1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 251 #if defined(OS_IOS) | 261 #if defined(OS_IOS) |
| 252 return base::LaunchUnitTests( | 262 return base::LaunchUnitTests( |
| 253 argc, argv, | 263 argc, argv, |
| 254 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 264 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
| 255 #else | 265 #else |
| 256 return base::LaunchUnitTestsSerially( | 266 return base::LaunchUnitTestsSerially( |
| 257 argc, argv, | 267 argc, argv, |
| 258 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 268 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
| 259 #endif | 269 #endif |
| 260 } | 270 } |
| OLD | NEW |