Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: remoting/test/chromoting_test_driver.cc

Issue 1237093004: Support for connecting to localhost on the chromoting test driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/test/test_suite.h" 15 #include "base/test/test_suite.h"
16 #include "base/test/test_switches.h" 16 #include "base/test/test_switches.h"
17 #include "google_apis/google_api_keys.h" 17 #include "google_apis/google_api_keys.h"
18 #include "net/base/escape.h" 18 #include "net/base/escape.h"
19 #include "remoting/test/access_token_fetcher.h" 19 #include "remoting/test/access_token_fetcher.h"
20 #include "remoting/test/host_info.h" 20 #include "remoting/test/host_info.h"
21 #include "remoting/test/host_list_fetcher.h" 21 #include "remoting/test/host_list_fetcher.h"
22 #include "remoting/test/refresh_token_store.h" 22 #include "remoting/test/refresh_token_store.h"
23 #include "remoting/test/test_chromoting_client.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace switches { 26 namespace switches {
26 const char kAuthCodeSwitchName[] = "authcode"; 27 const char kAuthCodeSwitchName[] = "authcode";
28 const char kClientPINSwitchName[] = "client-pin";
joedow 2015/07/14 19:58:44 kClientPinSwitchName, also, is this a client pin?
tonychun 2015/07/15 17:32:50 Changed it to kPinSwitchName.
27 const char kHelpSwitchName[] = "help"; 29 const char kHelpSwitchName[] = "help";
28 const char kHostNameSwitchName[] = "hostname"; 30 const char kHostNameSwitchName[] = "hostname";
29 const char kLoggingLevelSwitchName[] = "verbosity"; 31 const char kLoggingLevelSwitchName[] = "verbosity";
30 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; 32 const char kRefreshTokenPathSwitchName[] = "refresh-token-path";
31 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; 33 const char kSingleProcessTestsSwitchName[] = "single-process-tests";
32 const char kUserNameSwitchName[] = "username"; 34 const char kUserNameSwitchName[] = "username";
33 } 35 }
34 36
35 namespace { 37 namespace {
36 const char kChromotingAuthScopeValues[] = 38 const char kChromotingAuthScopeValues[] =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 switches::kUserNameSwitchName); 71 switches::kUserNameSwitchName);
70 printf(" %s: Specifies which host to connect to when running tests\n", 72 printf(" %s: Specifies which host to connect to when running tests\n",
71 switches::kHostNameSwitchName); 73 switches::kHostNameSwitchName);
72 printf("\nOptional Parameters:\n"); 74 printf("\nOptional Parameters:\n");
73 printf(" %s: Exchanged for a refresh and access token for authentication\n", 75 printf(" %s: Exchanged for a refresh and access token for authentication\n",
74 switches::kAuthCodeSwitchName); 76 switches::kAuthCodeSwitchName);
75 printf(" %s: Displays additional usage information\n", 77 printf(" %s: Displays additional usage information\n",
76 switches::kHelpSwitchName); 78 switches::kHelpSwitchName);
77 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", 79 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n",
78 switches::kRefreshTokenPathSwitchName); 80 switches::kRefreshTokenPathSwitchName);
81 printf(" %s: Used to authenticate a chromoting connection with the host\n",
82 switches::kClientPINSwitchName);
79 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)."
80 " [default: off]\n", 84 " [default: off]\n",
81 switches::kLoggingLevelSwitchName); 85 switches::kLoggingLevelSwitchName);
82 } 86 }
83 87
84 void PrintAuthCodeInfo() { 88 void PrintAuthCodeInfo() {
85 printf("\n*******************************\n"); 89 printf("\n*******************************\n");
86 printf("*** Auth Code Example Usage ***\n"); 90 printf("*** Auth Code Example Usage ***\n");
87 printf("*******************************\n\n"); 91 printf("*******************************\n\n");
88 92
89 printf("If this is the first time you are running the tool,\n"); 93 printf("If this is the first time you are running the tool,\n");
90 printf("you will need to provide an authorization code.\n"); 94 printf("you will need to provide an authorization code.\n");
91 printf("This code will be exchanged for a long term refresh token which\n"); 95 printf("This code will be exchanged for a long term refresh token which\n");
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Turn on logging for the test_driver and remoting components. 202 // Turn on logging for the test_driver and remoting components.
199 // This switch is parsed during logging::InitLogging. 203 // This switch is parsed during logging::InitLogging.
200 command_line->AppendSwitchASCII("vmodule", 204 command_line->AppendSwitchASCII("vmodule",
201 "*/remoting/*=" + verbosity_level); 205 "*/remoting/*=" + verbosity_level);
202 logging::LoggingSettings logging_settings; 206 logging::LoggingSettings logging_settings;
203 logging::InitLogging(logging_settings); 207 logging::InitLogging(logging_settings);
204 } 208 }
205 209
206 // The username is used to run the tests and determines which refresh token to 210 // The username is used to run the tests and determines which refresh token to
207 // select in the refresh token file. 211 // select in the refresh token file.
208 std::string username = 212 const std::string username =
209 command_line->GetSwitchValueASCII(switches::kUserNameSwitchName); 213 command_line->GetSwitchValueASCII(switches::kUserNameSwitchName);
210
211 if (username.empty()) { 214 if (username.empty()) {
212 LOG(ERROR) << "No username passed in, can't authenticate or run tests!"; 215 LOG(ERROR) << "No username passed in, can't authenticate or run tests!";
213 return -1; 216 return -1;
214 } 217 }
215 VLOG(1) << "Running chromoting tests as: " << username; 218 VLOG(1) << "Running chromoting tests as: " << username;
216 219
217 // Check to see if the user passed in a one time use auth_code for 220 // Check to see if the user passed in a one time use auth_code for
218 // refreshing their credentials. 221 // refreshing their credentials.
219 std::string auth_code = 222 std::string auth_code =
220 command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName); 223 command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName);
221 224
222 base::FilePath refresh_token_path = 225 const base::FilePath refresh_token_path =
223 command_line->GetSwitchValuePath(switches::kRefreshTokenPathSwitchName); 226 command_line->GetSwitchValuePath(switches::kRefreshTokenPathSwitchName);
224 227
225 // The hostname determines which host to initiate a session with from the list 228 // The hostname determines which host to initiate a session with from the list
226 // returned from the directory service. 229 // returned from the directory service.
227 std::string hostname = 230 const std::string hostname =
228 command_line->GetSwitchValueASCII(switches::kHostNameSwitchName); 231 command_line->GetSwitchValueASCII(switches::kHostNameSwitchName);
229
230 if (hostname.empty()) { 232 if (hostname.empty()) {
231 LOG(ERROR) << "No hostname passed in, connect to host requires hostname!"; 233 LOG(ERROR) << "No hostname passed in, finding the host requires hostname!";
232 return -1; 234 return -1;
233 } 235 }
234 VLOG(1) << "Chromoting tests will connect to: " << hostname; 236 VLOG(1) << "Chromoting tests will connect to: " << hostname;
235 237
238 // For some connection, a client_pin is not required. Thus, I did not make it
joedow 2015/07/14 19:58:44 s/connection/connections
tonychun 2015/07/15 17:32:50 Done.
239 // a requirement.
joedow 2015/07/14 19:58:44 Actually, I'm wondering if this comment is needed.
tonychun 2015/07/15 17:32:50 Removed.
240 const std::string client_pin =
241 command_line->GetSwitchValueASCII(switches::kClientPINSwitchName);
242
236 // TODO(TonyChun): Move this logic into a shared environment class. 243 // TODO(TonyChun): Move this logic into a shared environment class.
237 scoped_ptr<remoting::test::RefreshTokenStore> refresh_token_store = 244 scoped_ptr<remoting::test::RefreshTokenStore> refresh_token_store =
238 remoting::test::RefreshTokenStore::OnDisk(username, refresh_token_path); 245 remoting::test::RefreshTokenStore::OnDisk(username, refresh_token_path);
239 246
240 std::string refresh_token = refresh_token_store->FetchRefreshToken(); 247 std::string refresh_token = refresh_token_store->FetchRefreshToken();
241 if (auth_code.empty() && refresh_token.empty()) { 248 if (auth_code.empty() && refresh_token.empty()) {
242 // RefreshTokenStore already logs which specific error occured. 249 // RefreshTokenStore already logs which specific error occured.
243 return -1; 250 return -1;
244 } 251 }
245 252
(...skipping 20 matching lines...) Expand all
266 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, 273 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code,
267 access_token_callback); 274 access_token_callback);
268 } else { 275 } else {
269 DCHECK(!refresh_token.empty()); 276 DCHECK(!refresh_token.empty());
270 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token, 277 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token,
271 access_token_callback); 278 access_token_callback);
272 } 279 }
273 280
274 run_loop->Run(); 281 run_loop->Run();
275 282
276 // RunLoop to handle callback from directory service. 283 // Reset runloop to use it to retrieve hostlist from directory service.
277 run_loop.reset(new base::RunLoop()); 284 run_loop.reset(new base::RunLoop());
278 285
279 std::vector<remoting::test::HostInfo> hostlist; 286 std::vector<remoting::test::HostInfo> hostlist;
280 remoting::test::HostListFetcher::HostlistCallback hostlist_request_callback = 287 remoting::test::HostListFetcher::HostlistCallback hostlist_request_callback =
281 base::Bind(&OnHostlistRetrieved, run_loop->QuitClosure(), &hostlist); 288 base::Bind(&OnHostlistRetrieved, run_loop->QuitClosure(), &hostlist);
282 289
283 // Uses the access token to get the hostlist from the directory service. 290 // Uses the access token to get the hostlist from the directory service.
284 remoting::test::HostListFetcher hostlist_fetcher; 291 remoting::test::HostListFetcher hostlist_fetcher;
285 hostlist_fetcher.RetrieveHostlist(access_token, hostlist_request_callback); 292 hostlist_fetcher.RetrieveHostlist(access_token, hostlist_request_callback);
286 293
287 run_loop->Run(); 294 run_loop->Run();
288 295
296 run_loop.reset(new base::RunLoop());
297
298 base::Timer* timer = new base::Timer(true, false);
joedow 2015/07/14 19:58:44 If this needs to be a pointer then use a scoped_pt
tonychun 2015/07/15 17:32:50 Done.
299
300 remoting::test::TestChromotingClient test_chromoting_client;
301
302 // Find the requested online host info and initiate a session.
303 for (auto host_info : hostlist) {
joedow 2015/07/14 19:58:44 Instead of using a loop here, just use find() on h
tonychun 2015/07/15 17:32:50 Done.
304 if (host_info.IsReadyForConnection() && host_info.host_name == hostname) {
305 // Total time to connect to a remote host before aborting the connection.
306 timer->Start(FROM_HERE, base::TimeDelta::FromSeconds(10),
307 run_loop->QuitClosure());
308 test_chromoting_client.StartConnection(username, access_token,
309 client_pin, host_info);
310 run_loop->Run();
311 timer->Stop();
312 break;
313 }
314 }
315
316 test_chromoting_client.EndConnection();
317
289 return 0; 318 return 0;
290 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698