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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/test/launcher/unit_test_launcher.h" | 9 #include "base/test/launcher/unit_test_launcher.h" |
10 #include "base/test/test_suite.h" | 10 #include "base/test/test_suite.h" |
11 #include "base/test/test_switches.h" | 11 #include "base/test/test_switches.h" |
12 #include "google_apis/google_api_keys.h" | 12 #include "google_apis/google_api_keys.h" |
13 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 14 #include "remoting/test/app_remoting_test_driver_environment.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace switches { | 17 namespace switches { |
17 const char kUserNameSwitchName[] = "username"; | 18 const char kAuthCodeSwitchName[] = "authcode"; |
18 const char kAuthCodeSwitchName[] = "authcode"; | 19 const char kHelpSwitchName[] = "help"; |
19 const char kServiceEnvironmentSwitchName[] = "environment"; | 20 const char kLoggingLevelSwitchName[] = "verbosity"; |
20 const char kHelpSwitchName[] = "help"; | 21 const char kServiceEnvironmentSwitchName[] = "environment"; |
21 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; | 22 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; |
| 23 const char kUserNameSwitchName[] = "username"; |
22 } | 24 } |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 // Requested permissions needed for App Remoting tests. The spaces in between | 28 // Requested permissions needed for App Remoting tests. The spaces in between |
27 // scope fragments are necessary and will be escaped properly before use. | 29 // scope fragments are necessary and will be escaped properly before use. |
28 const char kAppRemotingAuthScopeValues[] = | 30 const char kAppRemotingAuthScopeValues[] = |
29 "https://www.googleapis.com/auth/appremoting.runapplication" | 31 "https://www.googleapis.com/auth/appremoting.runapplication" |
30 " https://www.googleapis.com/auth/googletalk" | 32 " https://www.googleapis.com/auth/googletalk" |
31 " https://www.googleapis.com/auth/userinfo.email" | 33 " https://www.googleapis.com/auth/userinfo.email" |
(...skipping 27 matching lines...) Expand all Loading... |
59 printf("\nRequired Parameters:\n"); | 61 printf("\nRequired Parameters:\n"); |
60 printf(" %s: Specifies which account to use when running tests\n", | 62 printf(" %s: Specifies which account to use when running tests\n", |
61 switches::kUserNameSwitchName); | 63 switches::kUserNameSwitchName); |
62 printf("\nOptional Parameters:\n"); | 64 printf("\nOptional Parameters:\n"); |
63 printf(" %s: Exchanged for a refresh and access token for authentication\n", | 65 printf(" %s: Exchanged for a refresh and access token for authentication\n", |
64 switches::kAuthCodeSwitchName); | 66 switches::kAuthCodeSwitchName); |
65 printf(" %s: Displays additional usage information\n", | 67 printf(" %s: Displays additional usage information\n", |
66 switches::kHelpSwitchName); | 68 switches::kHelpSwitchName); |
67 printf(" %s: Specifies the service api to use (dev|test) [default: dev]\n", | 69 printf(" %s: Specifies the service api to use (dev|test) [default: dev]\n", |
68 switches::kServiceEnvironmentSwitchName); | 70 switches::kServiceEnvironmentSwitchName); |
| 71 printf( |
| 72 " %s: Specifies the optional logging level of the tool (0-3)." |
| 73 " [default: off]\n", |
| 74 switches::kLoggingLevelSwitchName); |
69 } | 75 } |
70 | 76 |
71 void PrintAuthCodeInfo() { | 77 void PrintAuthCodeInfo() { |
72 printf("\n*******************************\n"); | 78 printf("\n*******************************\n"); |
73 printf("*** Auth Code Example Usage ***\n"); | 79 printf("*** Auth Code Example Usage ***\n"); |
74 printf("*******************************\n\n"); | 80 printf("*******************************\n\n"); |
75 | 81 |
76 printf("If this is the first time you are running the tool,\n"); | 82 printf("If this is the first time you are running the tool,\n"); |
77 printf("you will need to provide an authorization code.\n"); | 83 printf("you will need to provide an authorization code.\n"); |
78 printf("This code will be exchanged for a long term refresh token which\n"); | 84 printf("This code will be exchanged for a long term refresh token which\n"); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 144 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
139 } | 145 } |
140 | 146 |
141 // Verify we received the required input from the command line. | 147 // Verify we received the required input from the command line. |
142 if (!command_line->HasSwitch(switches::kUserNameSwitchName)) { | 148 if (!command_line->HasSwitch(switches::kUserNameSwitchName)) { |
143 LOG(ERROR) << "No user name passed in, can't authenticate without that!"; | 149 LOG(ERROR) << "No user name passed in, can't authenticate without that!"; |
144 PrintUsage(); | 150 PrintUsage(); |
145 return -1; | 151 return -1; |
146 } | 152 } |
147 | 153 |
| 154 std::string user_name; |
| 155 user_name = command_line->GetSwitchValueASCII(switches::kUserNameSwitchName); |
| 156 DVLOG(1) << "Running tests as: " << user_name; |
| 157 |
| 158 std::string auth_code; |
| 159 // Check to see if the user passed in a one time use auth_code for |
| 160 // refreshing their credentials. |
| 161 auth_code = command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName); |
| 162 |
| 163 std::string service_environment; |
| 164 // If the user passed in a service environment, use it, otherwise set a |
| 165 // default value. |
| 166 service_environment = command_line->GetSwitchValueASCII( |
| 167 switches::kServiceEnvironmentSwitchName); |
| 168 if (service_environment.empty()) { |
| 169 // Default to the development service environment. |
| 170 service_environment = "dev"; |
| 171 } else if (service_environment != "test" && service_environment != "dev") { |
| 172 // Only two values are allowed, so validate them before proceeding. |
| 173 LOG(ERROR) << "Invalid " << switches::kServiceEnvironmentSwitchName |
| 174 << " argument passed in."; |
| 175 PrintUsage(); |
| 176 return -1; |
| 177 } |
| 178 |
| 179 // Update the logging verbosity level is user specified one. |
| 180 std::string verbosity_level; |
| 181 verbosity_level = |
| 182 command_line->GetSwitchValueASCII(switches::kLoggingLevelSwitchName); |
| 183 if (!verbosity_level.empty()) { |
| 184 // Turn on logging for the test_driver and remoting components. |
| 185 // This switch is parsed during logging::InitLogging. |
| 186 command_line->AppendSwitchASCII("vmodule", |
| 187 "*/remoting/*=" + verbosity_level); |
| 188 logging::LoggingSettings logging_settings; |
| 189 logging::InitLogging(logging_settings); |
| 190 } |
| 191 |
| 192 // Create and register our global test data object. It will handle |
| 193 // retrieving an access token for the user and spinning up VMs. |
| 194 // The GTest framework will own the lifetime of this object once |
| 195 // it is registered below. |
| 196 scoped_ptr<remoting::test::AppRemotingTestDriverEnvironment> shared_data; |
| 197 |
| 198 shared_data.reset(new remoting::test::AppRemotingTestDriverEnvironment( |
| 199 user_name, service_environment)); |
| 200 |
| 201 if (!shared_data->Initialize(auth_code)) { |
| 202 // If we failed to initialize our shared data object, then bail. |
| 203 return -1; |
| 204 } |
| 205 |
| 206 // Since we've successfully set up our shared_data object, we'll assign the |
| 207 // value to our global* and transfer ownership to the framework. |
| 208 remoting::test::AppRemotingSharedData = shared_data.release(); |
| 209 testing::AddGlobalTestEnvironment(remoting::test::AppRemotingSharedData); |
| 210 |
148 // Because many tests may access the same remoting host(s), we need to run | 211 // Because many tests may access the same remoting host(s), we need to run |
149 // the tests sequentially so they do not interfere with each other. | 212 // the tests sequentially so they do not interfere with each other. |
150 return base::LaunchUnitTestsSerially( | 213 return base::LaunchUnitTestsSerially( |
151 argc, | 214 argc, |
152 argv, | 215 argv, |
153 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 216 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
154 } | 217 } |
OLD | NEW |