| 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 "remoting/test/app_remoting_test_driver_environment.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace switches { | 17 namespace switches { |
| 18 const char kAuthCodeSwitchName[] = "authcode"; | 18 const char kAuthCodeSwitchName[] = "authcode"; |
| 19 const char kHelpSwitchName[] = "help"; | 19 const char kHelpSwitchName[] = "help"; |
| 20 const char kLoggingLevelSwitchName[] = "verbosity"; | 20 const char kLoggingLevelSwitchName[] = "verbosity"; |
| 21 const char kServiceEnvironmentSwitchName[] = "environment"; | 21 const char kServiceEnvironmentSwitchName[] = "environment"; |
| 22 const char kShowHostAvailabilitySwitchName[] = "show-host-availability"; |
| 22 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; | 23 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; |
| 23 const char kUserNameSwitchName[] = "username"; | 24 const char kUserNameSwitchName[] = "username"; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Requested permissions needed for App Remoting tests. The spaces in between | 29 // Requested permissions needed for App Remoting tests. The spaces in between |
| 29 // scope fragments are necessary and will be escaped properly before use. | 30 // scope fragments are necessary and will be escaped properly before use. |
| 30 const char kAppRemotingAuthScopeValues[] = | 31 const char kAppRemotingAuthScopeValues[] = |
| 31 "https://www.googleapis.com/auth/appremoting.runapplication" | 32 "https://www.googleapis.com/auth/appremoting.runapplication" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 printf("\nRequired Parameters:\n"); | 62 printf("\nRequired Parameters:\n"); |
| 62 printf(" %s: Specifies which account to use when running tests\n", | 63 printf(" %s: Specifies which account to use when running tests\n", |
| 63 switches::kUserNameSwitchName); | 64 switches::kUserNameSwitchName); |
| 64 printf("\nOptional Parameters:\n"); | 65 printf("\nOptional Parameters:\n"); |
| 65 printf(" %s: Exchanged for a refresh and access token for authentication\n", | 66 printf(" %s: Exchanged for a refresh and access token for authentication\n", |
| 66 switches::kAuthCodeSwitchName); | 67 switches::kAuthCodeSwitchName); |
| 67 printf(" %s: Displays additional usage information\n", | 68 printf(" %s: Displays additional usage information\n", |
| 68 switches::kHelpSwitchName); | 69 switches::kHelpSwitchName); |
| 69 printf(" %s: Specifies the service api to use (dev|test) [default: dev]\n", | 70 printf(" %s: Specifies the service api to use (dev|test) [default: dev]\n", |
| 70 switches::kServiceEnvironmentSwitchName); | 71 switches::kServiceEnvironmentSwitchName); |
| 71 printf( | 72 printf(" %s: Retrieves and displays the connection status for all known " |
| 72 " %s: Specifies the optional logging level of the tool (0-3)." | 73 "hosts, no tests will be run\n", |
| 73 " [default: off]\n", | 74 switches::kShowHostAvailabilitySwitchName); |
| 74 switches::kLoggingLevelSwitchName); | 75 printf(" %s: Specifies the optional logging level of the tool (0-3)." |
| 76 " [default: off]\n", |
| 77 switches::kLoggingLevelSwitchName); |
| 75 } | 78 } |
| 76 | 79 |
| 77 void PrintAuthCodeInfo() { | 80 void PrintAuthCodeInfo() { |
| 78 printf("\n*******************************\n"); | 81 printf("\n*******************************\n"); |
| 79 printf("*** Auth Code Example Usage ***\n"); | 82 printf("*** Auth Code Example Usage ***\n"); |
| 80 printf("*******************************\n\n"); | 83 printf("*******************************\n\n"); |
| 81 | 84 |
| 82 printf("If this is the first time you are running the tool,\n"); | 85 printf("If this is the first time you are running the tool,\n"); |
| 83 printf("you will need to provide an authorization code.\n"); | 86 printf("you will need to provide an authorization code.\n"); |
| 84 printf("This code will be exchanged for a long term refresh token which\n"); | 87 printf("This code will be exchanged for a long term refresh token which\n"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 98 | 101 |
| 99 printf("\nAuthorization URL:\n"); | 102 printf("\nAuthorization URL:\n"); |
| 100 printf("%s\n", GetAuthorizationCodeUri().c_str()); | 103 printf("%s\n", GetAuthorizationCodeUri().c_str()); |
| 101 | 104 |
| 102 printf("\nRedirected URL Example:\n"); | 105 printf("\nRedirected URL Example:\n"); |
| 103 printf("https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" | 106 printf("https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" |
| 104 "chrome-remote-desktop/dev?code=4/AKtf...\n"); | 107 "chrome-remote-desktop/dev?code=4/AKtf...\n"); |
| 105 | 108 |
| 106 printf("\nTool usage example with the newly created auth code:\n"); | 109 printf("\nTool usage example with the newly created auth code:\n"); |
| 107 printf("ar_test_driver --%s=example@gmail.com --%s=4/AKtf...\n\n", | 110 printf("ar_test_driver --%s=example@gmail.com --%s=4/AKtf...\n\n", |
| 108 switches::kUserNameSwitchName, | 111 switches::kUserNameSwitchName, switches::kAuthCodeSwitchName); |
| 109 switches::kAuthCodeSwitchName); | |
| 110 } | 112 } |
| 111 | 113 |
| 112 } // namespace | 114 } // namespace |
| 113 | 115 |
| 114 int main(int argc, char** argv) { | 116 int main(int argc, char** argv) { |
| 115 testing::InitGoogleTest(&argc, argv); | 117 testing::InitGoogleTest(&argc, argv); |
| 116 TestSuite test_suite(argc, argv); | 118 TestSuite test_suite(argc, argv); |
| 117 | 119 |
| 118 // The pointer returned here refers to a singleton, since we don't own the | 120 // The pointer returned here refers to a singleton, since we don't own the |
| 119 // lifetime of the object, don't wrap in a scoped_ptr construct or release it. | 121 // lifetime of the object, don't wrap in a scoped_ptr construct or release it. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 132 command_line->AppendSwitch(switches::kSingleProcessTestsSwitchName); | 134 command_line->AppendSwitch(switches::kSingleProcessTestsSwitchName); |
| 133 | 135 |
| 134 // If the user passed in the help flag, then show the help info for this tool | 136 // If the user passed in the help flag, then show the help info for this tool |
| 135 // and 'run' the tests which will print the gtest specific help and then exit. | 137 // and 'run' the tests which will print the gtest specific help and then exit. |
| 136 // NOTE: We do this check after updating the switches as otherwise the gtest | 138 // NOTE: We do this check after updating the switches as otherwise the gtest |
| 137 // help is written in parallel with our text and can appear interleaved. | 139 // help is written in parallel with our text and can appear interleaved. |
| 138 if (command_line->HasSwitch(switches::kHelpSwitchName)) { | 140 if (command_line->HasSwitch(switches::kHelpSwitchName)) { |
| 139 PrintUsage(); | 141 PrintUsage(); |
| 140 PrintAuthCodeInfo(); | 142 PrintAuthCodeInfo(); |
| 141 return base::LaunchUnitTestsSerially( | 143 return base::LaunchUnitTestsSerially( |
| 142 argc, | 144 argc, argv, |
| 143 argv, | |
| 144 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 145 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
| 145 } | 146 } |
| 146 | 147 |
| 147 // Verify we received the required input from the command line. | 148 // Verify we received the required input from the command line. |
| 148 if (!command_line->HasSwitch(switches::kUserNameSwitchName)) { | 149 if (!command_line->HasSwitch(switches::kUserNameSwitchName)) { |
| 149 LOG(ERROR) << "No user name passed in, can't authenticate without that!"; | 150 LOG(ERROR) << "No user name passed in, can't authenticate without that!"; |
| 150 PrintUsage(); | 151 PrintUsage(); |
| 151 return -1; | 152 return -1; |
| 152 } | 153 } |
| 153 | 154 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 175 } else { | 176 } else { |
| 176 LOG(ERROR) << "Invalid " << switches::kServiceEnvironmentSwitchName | 177 LOG(ERROR) << "Invalid " << switches::kServiceEnvironmentSwitchName |
| 177 << " argument passed in."; | 178 << " argument passed in."; |
| 178 PrintUsage(); | 179 PrintUsage(); |
| 179 return -1; | 180 return -1; |
| 180 } | 181 } |
| 181 | 182 |
| 182 // Update the logging verbosity level is user specified one. | 183 // Update the logging verbosity level is user specified one. |
| 183 std::string verbosity_level; | 184 std::string verbosity_level; |
| 184 verbosity_level = | 185 verbosity_level = |
| 185 command_line->GetSwitchValueASCII(switches::kLoggingLevelSwitchName); | 186 command_line->GetSwitchValueASCII(switches::kLoggingLevelSwitchName); |
| 186 if (!verbosity_level.empty()) { | 187 if (!verbosity_level.empty()) { |
| 187 // Turn on logging for the test_driver and remoting components. | 188 // Turn on logging for the test_driver and remoting components. |
| 188 // This switch is parsed during logging::InitLogging. | 189 // This switch is parsed during logging::InitLogging. |
| 189 command_line->AppendSwitchASCII("vmodule", | 190 command_line->AppendSwitchASCII("vmodule", |
| 190 "*/remoting/*=" + verbosity_level); | 191 "*/remoting/*=" + verbosity_level); |
| 191 logging::LoggingSettings logging_settings; | 192 logging::LoggingSettings logging_settings; |
| 192 logging::InitLogging(logging_settings); | 193 logging::InitLogging(logging_settings); |
| 193 } | 194 } |
| 194 | 195 |
| 195 // Create and register our global test data object. It will handle | 196 // Create and register our global test data object. It will handle |
| 196 // retrieving an access token for the user and spinning up VMs. | 197 // retrieving an access token for the user and spinning up VMs. |
| 197 // The GTest framework will own the lifetime of this object once | 198 // The GTest framework will own the lifetime of this object once |
| 198 // it is registered below. | 199 // it is registered below. |
| 199 scoped_ptr<remoting::test::AppRemotingTestDriverEnvironment> shared_data; | 200 scoped_ptr<remoting::test::AppRemotingTestDriverEnvironment> shared_data; |
| 200 | 201 |
| 201 shared_data.reset(new remoting::test::AppRemotingTestDriverEnvironment( | 202 shared_data.reset(new remoting::test::AppRemotingTestDriverEnvironment( |
| 202 user_name, service_environment)); | 203 user_name, service_environment)); |
| 203 | 204 |
| 204 if (!shared_data->Initialize(auth_code)) { | 205 if (!shared_data->Initialize(auth_code)) { |
| 205 // If we failed to initialize our shared data object, then bail. | 206 // If we failed to initialize our shared data object, then bail. |
| 206 return -1; | 207 return -1; |
| 207 } | 208 } |
| 208 | 209 |
| 210 if (command_line->HasSwitch(switches::kShowHostAvailabilitySwitchName)) { |
| 211 // When this flag is specified, we will retrieve connection information |
| 212 // for all known applications and report the status. No tests will be run. |
| 213 shared_data->ShowHostAvailability(); |
| 214 return 0; |
| 215 } |
| 216 |
| 209 // Since we've successfully set up our shared_data object, we'll assign the | 217 // Since we've successfully set up our shared_data object, we'll assign the |
| 210 // value to our global* and transfer ownership to the framework. | 218 // value to our global* and transfer ownership to the framework. |
| 211 remoting::test::AppRemotingSharedData = shared_data.release(); | 219 remoting::test::AppRemotingSharedData = shared_data.release(); |
| 212 testing::AddGlobalTestEnvironment(remoting::test::AppRemotingSharedData); | 220 testing::AddGlobalTestEnvironment(remoting::test::AppRemotingSharedData); |
| 213 | 221 |
| 214 // Because many tests may access the same remoting host(s), we need to run | 222 // Because many tests may access the same remoting host(s), we need to run |
| 215 // the tests sequentially so they do not interfere with each other. | 223 // the tests sequentially so they do not interfere with each other. |
| 216 return base::LaunchUnitTestsSerially( | 224 return base::LaunchUnitTestsSerially( |
| 217 argc, | 225 argc, argv, |
| 218 argv, | |
| 219 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | 226 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); |
| 220 } | 227 } |
| OLD | NEW |