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 | 7 |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/test/test_suite.h" | 15 #include "base/test/test_suite.h" |
| 15 #include "base/test/test_switches.h" | 16 #include "base/test/test_switches.h" |
| 16 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
| 17 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 18 #include "remoting/test/access_token_fetcher.h" | 19 #include "remoting/test/access_token_fetcher.h" |
| 20 #include "remoting/test/chromoting_host_info.h" | |
| 21 #include "remoting/test/chromoting_host_list_fetcher.h" | |
| 19 #include "remoting/test/refresh_token_store.h" | 22 #include "remoting/test/refresh_token_store.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 24 |
| 22 namespace switches { | 25 namespace switches { |
| 23 const char kAuthCodeSwitchName[] = "authcode"; | 26 const char kAuthCodeSwitchName[] = "authcode"; |
| 24 const char kHelpSwitchName[] = "help"; | 27 const char kHelpSwitchName[] = "help"; |
| 25 const char kHostNameSwitchName[] = "hostname"; | 28 const char kHostNameSwitchName[] = "hostname"; |
| 26 const char kLoggingLevelSwitchName[] = "verbosity"; | 29 const char kLoggingLevelSwitchName[] = "verbosity"; |
| 27 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; | 30 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; |
| 28 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; | 31 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 52 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), | 55 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), |
| 53 use_plus).c_str()); | 56 use_plus).c_str()); |
| 54 } | 57 } |
| 55 | 58 |
| 56 void PrintUsage() { | 59 void PrintUsage() { |
| 57 printf("\n************************************\n"); | 60 printf("\n************************************\n"); |
| 58 printf("*** Chromoting Test Driver Usage ***\n"); | 61 printf("*** Chromoting Test Driver Usage ***\n"); |
| 59 printf("************************************\n"); | 62 printf("************************************\n"); |
| 60 | 63 |
| 61 printf("\nUsage:\n"); | 64 printf("\nUsage:\n"); |
| 62 printf(" chromoting_test_driver --username=<example@gmail.com> [options]\n"); | 65 printf(" chromoting_test_driver --username=<example@gmail.com> [options]" |
| 66 " --hostname=<example hostname>\n"); | |
| 63 printf("\nRequired Parameters:\n"); | 67 printf("\nRequired Parameters:\n"); |
| 64 printf(" %s: Specifies which account to use when running tests\n", | 68 printf(" %s: Specifies which account to use when running tests\n", |
| 65 switches::kUserNameSwitchName); | 69 switches::kUserNameSwitchName); |
| 70 printf(" %s: Specifies which host to connect to when running tests\n", | |
| 71 switches::kHostNameSwitchName); | |
| 66 printf("\nOptional Parameters:\n"); | 72 printf("\nOptional Parameters:\n"); |
| 67 printf(" %s: Exchanged for a refresh and access token for authentication\n", | 73 printf(" %s: Exchanged for a refresh and access token for authentication\n", |
| 68 switches::kAuthCodeSwitchName); | 74 switches::kAuthCodeSwitchName); |
| 75 printf(" %s: Displays additional usage information\n", | |
| 76 switches::kHelpSwitchName); | |
| 69 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", | 77 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", |
| 70 switches::kRefreshTokenPathSwitchName); | 78 switches::kRefreshTokenPathSwitchName); |
| 71 printf(" %s: Displays additional usage information\n", | 79 printf(" %s: Specifies the optional logging level of the tool (0-3)." |
| 72 switches::kHelpSwitchName); | 80 " [default: off]\n", |
| 81 switches::kLoggingLevelSwitchName); | |
| 73 } | 82 } |
| 74 | 83 |
| 75 void PrintAuthCodeInfo() { | 84 void PrintAuthCodeInfo() { |
| 76 printf("\n*******************************\n"); | 85 printf("\n*******************************\n"); |
| 77 printf("*** Auth Code Example Usage ***\n"); | 86 printf("*** Auth Code Example Usage ***\n"); |
| 78 printf("*******************************\n\n"); | 87 printf("*******************************\n\n"); |
| 79 | 88 |
| 80 printf("If this is the first time you are running the tool,\n"); | 89 printf("If this is the first time you are running the tool,\n"); |
| 81 printf("you will need to provide an authorization code.\n"); | 90 printf("you will need to provide an authorization code.\n"); |
| 82 printf("This code will be exchanged for a long term refresh token which\n"); | 91 printf("This code will be exchanged for a long term refresh token which\n"); |
| 83 printf("will be stored locally and used to acquire a short lived access\n"); | 92 printf("will be stored locally and used to acquire a short lived access\n"); |
| 84 printf("token to connect to the remoting service apis and establish a\n"); | 93 printf("token to connect to the remoting service apis and establish a\n"); |
| 85 printf("remote host connection.\n\n"); | 94 printf("remote host connection.\n\n"); |
| 86 | 95 |
| 87 printf("Note: You may need to repeat this step if the stored refresh token"); | 96 printf("Note: You may need to repeat this step if the stored refresh token"); |
| 88 printf("\n has been revoked or expired.\n"); | 97 printf("\n has been revoked or expired.\n"); |
| 89 printf(" Passing in the same auth code twice will result in an error\n"); | 98 printf(" Passing in the same auth code twice will result in an error\n"); |
| 90 | 99 |
| 91 printf( | 100 printf("\nFollow these steps to produce an auth code:\n" |
| 92 "\nFollow these steps to produce an auth code:\n" | 101 " - Open the Authorization URL link shown below in your browser\n" |
| 93 " - Open the Authorization URL link shown below in your browser\n" | 102 " - Approve the requested permissions for the tool\n" |
| 94 " - Approve the requested permissions for the tool\n" | 103 " - Copy the 'code' value in the redirected URL\n" |
| 95 " - Copy the 'code' value in the redirected URL\n" | 104 " - Run the tool and pass in copied auth code as a parameter\n"); |
| 96 " - Run the tool and pass in copied auth code as a parameter\n"); | |
| 97 | 105 |
| 98 printf("\nAuthorization URL:\n"); | 106 printf("\nAuthorization URL:\n"); |
| 99 printf("%s\n", GetAuthorizationCodeUri().c_str()); | 107 printf("%s\n", GetAuthorizationCodeUri().c_str()); |
| 100 | 108 |
| 101 printf("\nRedirected URL Example:\n"); | 109 printf("\nRedirected URL Example:\n"); |
| 102 printf( | 110 printf("https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" |
| 103 "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" | 111 "chrome-remote-desktop/dev?code=4/AKtf...\n"); |
| 104 "chrome-remote-desktop/dev?code=4/AKtf...\n"); | |
| 105 | 112 |
| 106 printf("\nTool usage example with the newly created auth code:\n"); | 113 printf("\nTool usage example with the newly created auth code:\n"); |
| 107 printf("chromoting_test_driver --%s=example@gmail.com --%s=4/AKtf...\n\n", | 114 printf("chromoting_test_driver --%s=example@gmail.com --%s=example_host_name" |
| 108 switches::kUserNameSwitchName, switches::kAuthCodeSwitchName); | 115 " --%s=4/AKtf...\n\n", |
| 116 switches::kUserNameSwitchName, | |
| 117 switches::kHostNameSwitchName, | |
| 118 switches::kAuthCodeSwitchName); | |
| 109 } | 119 } |
| 110 | 120 |
| 111 void PrintJsonFileInfo() { | 121 void PrintJsonFileInfo() { |
| 112 printf("\n****************************************\n"); | 122 printf("\n****************************************\n"); |
| 113 printf("*** Refresh Token File Example Usage ***\n"); | 123 printf("*** Refresh Token File Example Usage ***\n"); |
| 114 printf("****************************************\n\n"); | 124 printf("****************************************\n\n"); |
| 115 | 125 |
| 116 printf("In order to use this option, a valid JSON file must exist, be\n"); | 126 printf("In order to use this option, a valid JSON file must exist, be\n"); |
| 117 printf("properly formatted, and contain a username/token KVP.\n"); | 127 printf("properly formatted, and contain a username/token KVP.\n"); |
| 118 printf("Contents of example_file.json\n"); | 128 printf("Contents of example_file.json\n"); |
| 119 printf("{\n"); | 129 printf("{\n"); |
| 120 printf(" \"username1@fauxdomain.com\": \"1/3798Gsdf898shksdvfyi8sshad\",\n"); | 130 printf(" \"username1@fauxdomain.com\": \"1/3798Gsdf898shksdvfyi8sshad\",\n"); |
| 121 printf(" \"username2@fauxdomain.com\": \"1/8974sdf87asdgadfgaerhfRsAa\",\n"); | 131 printf(" \"username2@fauxdomain.com\": \"1/8974sdf87asdgadfgaerhfRsAa\",\n"); |
| 122 printf("}\n\n"); | 132 printf("}\n\n"); |
| 123 | 133 |
| 124 printf("\nTool usage example:\n"); | 134 printf("\nTool usage example:\n"); |
| 125 printf("chromoting_test_driver --%s=%s --%s=./example_file.json\n\n", | 135 printf("chromoting_test_driver --%s=%s --%s=example_host_name" |
| 136 " --%s=./example_file.json\n\n", | |
| 126 switches::kUserNameSwitchName, "username1@fauxdomain.com", | 137 switches::kUserNameSwitchName, "username1@fauxdomain.com", |
| 127 switches::kRefreshTokenPathSwitchName); | 138 switches::kHostNameSwitchName, switches::kRefreshTokenPathSwitchName); |
| 128 } | 139 } |
| 129 | 140 |
| 130 } // namespace | 141 } // namespace |
| 131 | 142 |
| 132 void OnAccessTokenRetrieved( | 143 void OnAccessTokenRetrieved( |
| 133 base::Closure done_closure, | 144 base::Closure done_closure, |
| 134 const std::string& access_token, | 145 std::string* access_token, |
| 135 const std::string& refresh_token) { | 146 const std::string& retrieved_access_token, |
| 147 const std::string& retrieved_refresh_token) { | |
| 136 | 148 |
| 137 DVLOG(1) << "OnAccessTokenRetrieved() Called"; | 149 DVLOG(1) << "OnAccessTokenRetrieved() Called"; |
| 150 DVLOG(1) << "Access Token: " << retrieved_access_token; | |
| 138 | 151 |
| 139 DVLOG(1) << "Access Token: " << access_token; | 152 *access_token = retrieved_access_token; |
| 140 | 153 |
| 141 done_closure.Run(); | 154 done_closure.Run(); |
| 142 } | 155 } |
| 156 | |
| 157 void OnHostlistRetrieved( | |
| 158 base::Closure done_closure, | |
| 159 std::vector<remoting::test::ChromotingHostInfo>* hostlist, | |
| 160 std::vector<remoting::test::ChromotingHostInfo>* retrieved_hostlist) { | |
|
joedow
2015/07/06 22:19:15
retrieved_hostlist should be const ref
tonychun
2015/07/08 03:12:15
Done.
| |
| 161 | |
| 162 DVLOG(1) << "OnHostlistRetrieved() Called"; | |
|
joedow
2015/07/06 22:19:14
FYI, I've switched over to using VLOG instead of D
tonychun
2015/07/08 03:12:15
Done.
| |
| 163 | |
| 164 DCHECK(hostlist); | |
| 165 | |
| 166 *hostlist = *retrieved_hostlist; | |
| 167 | |
| 168 DVLOG(1) << "There are " << hostlist->size() << " hosts in the hostlist"; | |
| 169 | |
| 170 done_closure.Run(); | |
| 171 } | |
| 143 | 172 |
| 144 int main(int argc, char* argv[]) { | 173 int main(int argc, char* argv[]) { |
| 145 testing::InitGoogleTest(&argc, argv); | 174 testing::InitGoogleTest(&argc, argv); |
| 146 base::TestSuite test_suite(argc, argv); | 175 base::TestSuite test_suite(argc, argv); |
| 147 | 176 |
| 148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 177 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 149 DCHECK(command_line); | 178 DCHECK(command_line); |
| 150 | 179 |
| 151 // Do not retry if tests fails. | 180 // Do not retry if tests fails. |
| 152 command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0"); | 181 command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0"); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 return -1; | 243 return -1; |
| 215 } | 244 } |
| 216 | 245 |
| 217 // Used for running network request tasks. | 246 // Used for running network request tasks. |
| 218 // TODO(TonyChun): Move this logic into a shared environment class. | 247 // TODO(TonyChun): Move this logic into a shared environment class. |
| 219 base::MessageLoopForIO message_loop; | 248 base::MessageLoopForIO message_loop; |
| 220 | 249 |
| 221 // Uses the refresh token to get the access token from GAIA. | 250 // Uses the refresh token to get the access token from GAIA. |
| 222 remoting::test::AccessTokenFetcher access_token_fetcher; | 251 remoting::test::AccessTokenFetcher access_token_fetcher; |
| 223 | 252 |
| 224 base::RunLoop run_loop; | 253 // A RunLoop that yields to the thread's MessageLoopForIO |
| 254 scoped_ptr<base::RunLoop> run_loop; | |
| 255 | |
| 256 // RunLoop to handle callback from GAIA. | |
| 257 run_loop.reset(new base::RunLoop()); | |
| 258 | |
| 259 std::string access_token; | |
| 225 | 260 |
|
joedow
2015/07/06 22:19:14
remove newline
tonychun
2015/07/08 03:12:15
Done.
| |
| 226 remoting::test::AccessTokenCallback access_token_callback = | 261 remoting::test::AccessTokenCallback access_token_callback = |
| 227 base::Bind(&OnAccessTokenRetrieved, run_loop.QuitClosure()); | 262 base::Bind(&OnAccessTokenRetrieved, |
| 263 run_loop->QuitClosure(), | |
| 264 &access_token); | |
| 228 | 265 |
| 229 if (!auth_code.empty()) { | 266 if (!auth_code.empty()) { |
| 230 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, | 267 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, |
| 231 access_token_callback); | 268 access_token_callback); |
| 232 } else { | 269 } else { |
| 233 DCHECK(!refresh_token.empty()); | 270 DCHECK(!refresh_token.empty()); |
| 234 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token, | 271 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token, |
| 235 access_token_callback); | 272 access_token_callback); |
| 236 } | 273 } |
| 237 | 274 |
| 238 run_loop.Run(); | 275 run_loop->Run(); |
| 276 | |
| 277 // RunLoop to handle callback from Directory service. | |
|
joedow
2015/07/06 22:19:14
update comment "Reset runloop to use it to retriev
tonychun
2015/07/08 03:12:15
Done.
| |
| 278 run_loop.reset(new base::RunLoop()); | |
| 279 | |
| 280 std::vector<remoting::test::ChromotingHostInfo> hostlist; | |
| 281 | |
|
joedow
2015/07/06 22:19:14
remove newline
tonychun
2015/07/08 03:12:16
Done.
| |
| 282 remoting::test::HostlistCallback hostlist_fetch_callback = base::Bind( | |
|
joedow
2015/07/06 22:19:14
hostlist_fetch_callback can be rename hostlist_req
tonychun
2015/07/08 03:12:16
Done.
| |
| 283 &OnHostlistRetrieved, run_loop->QuitClosure(), &hostlist); | |
|
joedow
2015/07/06 22:19:14
base::ConstRef(hostlist)
tonychun
2015/07/08 03:12:16
If you look at my new function,
void OnHostlistRe
| |
| 284 | |
| 285 // Uses the access token to get the hostlist from the Directory service. | |
| 286 remoting::test::ChromotingHostListFetcher hostlist_fetcher; | |
| 287 | |
|
joedow
2015/07/06 22:19:14
Remove newline
tonychun
2015/07/08 03:12:16
Done.
| |
| 288 hostlist_fetcher.RetrieveHostlist(access_token, hostlist_fetch_callback); | |
| 289 | |
| 290 run_loop->Run(); | |
| 239 | 291 |
| 240 return 0; | 292 return 0; |
| 241 } | 293 } |
| OLD | NEW |