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

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: Made changes to unittest to use ConnectionSetupInfo. 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
« no previous file with comments | « remoting/test/app_remoting_connection_helper.cc ('k') | remoting/test/connection_setup_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 kPinSwitchName[] = "pin";
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[] =
37 "https://www.googleapis.com/auth/chromoting " 39 "https://www.googleapis.com/auth/chromoting "
38 "https://www.googleapis.com/auth/googletalk " 40 "https://www.googleapis.com/auth/googletalk "
39 "https://www.googleapis.com/auth/userinfo.email"; 41 "https://www.googleapis.com/auth/userinfo.email";
40 42
43 const unsigned int kConnectionTimeoutSeconds = 10;
44
41 std::string GetAuthorizationCodeUri() { 45 std::string GetAuthorizationCodeUri() {
42 // Replace space characters with a '+' sign when formatting. 46 // Replace space characters with a '+' sign when formatting.
43 bool use_plus = true; 47 bool use_plus = true;
44 return base::StringPrintf( 48 return base::StringPrintf(
45 "https://accounts.google.com/o/oauth2/auth" 49 "https://accounts.google.com/o/oauth2/auth"
46 "?scope=%s" 50 "?scope=%s"
47 "&redirect_uri=https://chromoting-oauth.talkgadget.google.com/" 51 "&redirect_uri=https://chromoting-oauth.talkgadget.google.com/"
48 "talkgadget/oauth/chrome-remote-desktop/dev" 52 "talkgadget/oauth/chrome-remote-desktop/dev"
49 "&response_type=code" 53 "&response_type=code"
50 "&client_id=%s" 54 "&client_id=%s"
(...skipping 18 matching lines...) Expand all
69 switches::kUserNameSwitchName); 73 switches::kUserNameSwitchName);
70 printf(" %s: Specifies which host to connect to when running tests\n", 74 printf(" %s: Specifies which host to connect to when running tests\n",
71 switches::kHostNameSwitchName); 75 switches::kHostNameSwitchName);
72 printf("\nOptional Parameters:\n"); 76 printf("\nOptional Parameters:\n");
73 printf(" %s: Exchanged for a refresh and access token for authentication\n", 77 printf(" %s: Exchanged for a refresh and access token for authentication\n",
74 switches::kAuthCodeSwitchName); 78 switches::kAuthCodeSwitchName);
75 printf(" %s: Displays additional usage information\n", 79 printf(" %s: Displays additional usage information\n",
76 switches::kHelpSwitchName); 80 switches::kHelpSwitchName);
77 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", 81 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n",
78 switches::kRefreshTokenPathSwitchName); 82 switches::kRefreshTokenPathSwitchName);
83 printf(" %s: Used to authenticate a chromoting connection with the host\n",
84 switches::kPinSwitchName);
79 printf(" %s: Specifies the optional logging level of the tool (0-3)." 85 printf(" %s: Specifies the optional logging level of the tool (0-3)."
80 " [default: off]\n", 86 " [default: off]\n",
81 switches::kLoggingLevelSwitchName); 87 switches::kLoggingLevelSwitchName);
82 } 88 }
83 89
84 void PrintAuthCodeInfo() { 90 void PrintAuthCodeInfo() {
85 printf("\n*******************************\n"); 91 printf("\n*******************************\n");
86 printf("*** Auth Code Example Usage ***\n"); 92 printf("*** Auth Code Example Usage ***\n");
87 printf("*******************************\n\n"); 93 printf("*******************************\n\n");
88 94
89 printf("If this is the first time you are running the tool,\n"); 95 printf("If this is the first time you are running the tool,\n");
90 printf("you will need to provide an authorization code.\n"); 96 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"); 97 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. 204 // Turn on logging for the test_driver and remoting components.
199 // This switch is parsed during logging::InitLogging. 205 // This switch is parsed during logging::InitLogging.
200 command_line->AppendSwitchASCII("vmodule", 206 command_line->AppendSwitchASCII("vmodule",
201 "*/remoting/*=" + verbosity_level); 207 "*/remoting/*=" + verbosity_level);
202 logging::LoggingSettings logging_settings; 208 logging::LoggingSettings logging_settings;
203 logging::InitLogging(logging_settings); 209 logging::InitLogging(logging_settings);
204 } 210 }
205 211
206 // The username is used to run the tests and determines which refresh token to 212 // The username is used to run the tests and determines which refresh token to
207 // select in the refresh token file. 213 // select in the refresh token file.
208 std::string username = 214 const std::string username =
209 command_line->GetSwitchValueASCII(switches::kUserNameSwitchName); 215 command_line->GetSwitchValueASCII(switches::kUserNameSwitchName);
210
211 if (username.empty()) { 216 if (username.empty()) {
212 LOG(ERROR) << "No username passed in, can't authenticate or run tests!"; 217 LOG(ERROR) << "No username passed in, can't authenticate or run tests!";
213 return -1; 218 return -1;
214 } 219 }
215 VLOG(1) << "Running chromoting tests as: " << username; 220 VLOG(1) << "Running chromoting tests as: " << username;
216 221
217 // Check to see if the user passed in a one time use auth_code for 222 // Check to see if the user passed in a one time use auth_code for
218 // refreshing their credentials. 223 // refreshing their credentials.
219 std::string auth_code = 224 std::string auth_code =
220 command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName); 225 command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName);
221 226
222 base::FilePath refresh_token_path = 227 const base::FilePath refresh_token_path =
223 command_line->GetSwitchValuePath(switches::kRefreshTokenPathSwitchName); 228 command_line->GetSwitchValuePath(switches::kRefreshTokenPathSwitchName);
224 229
225 // The hostname determines which host to initiate a session with from the list 230 // The hostname determines which host to initiate a session with from the list
226 // returned from the directory service. 231 // returned from the directory service.
227 std::string hostname = 232 const std::string hostname =
228 command_line->GetSwitchValueASCII(switches::kHostNameSwitchName); 233 command_line->GetSwitchValueASCII(switches::kHostNameSwitchName);
229
230 if (hostname.empty()) { 234 if (hostname.empty()) {
231 LOG(ERROR) << "No hostname passed in, connect to host requires hostname!"; 235 LOG(ERROR) << "No hostname passed in, finding the host requires hostname!";
232 return -1; 236 return -1;
233 } 237 }
234 VLOG(1) << "Chromoting tests will connect to: " << hostname; 238 VLOG(1) << "Chromoting tests will connect to: " << hostname;
235 239
240 const std::string pin =
241 command_line->GetSwitchValueASCII(switches::kPinSwitchName);
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.
277 run_loop.reset(new base::RunLoop()); 283 run_loop.reset(new base::RunLoop());
278 284
279 std::vector<remoting::test::HostInfo> hostlist; 285 std::vector<remoting::test::HostInfo> hostlist;
280 remoting::test::HostListFetcher::HostlistCallback hostlist_request_callback = 286 remoting::test::HostListFetcher::HostlistCallback hostlist_request_callback =
281 base::Bind(&OnHostlistRetrieved, run_loop->QuitClosure(), &hostlist); 287 base::Bind(&OnHostlistRetrieved, run_loop->QuitClosure(), &hostlist);
282 288
283 // Uses the access token to get the hostlist from the directory service. 289 // Uses the access token to get the hostlist from the directory service.
284 remoting::test::HostListFetcher hostlist_fetcher; 290 remoting::test::HostListFetcher hostlist_fetcher;
285 hostlist_fetcher.RetrieveHostlist(access_token, hostlist_request_callback); 291 hostlist_fetcher.RetrieveHostlist(access_token, hostlist_request_callback);
286 292
287 run_loop->Run(); 293 run_loop->Run();
288 294
295 run_loop.reset(new base::RunLoop());
296
297 remoting::test::TestChromotingClient test_chromoting_client;
298
299 // Check if requested host is online and ready to receive connections.
300 auto it = std::find_if(hostlist.begin(), hostlist.end(),
301 [&hostname](const remoting::test::HostInfo& host_info) {
302 return host_info.host_name == hostname &&
303 host_info.IsReadyForConnection();
304 });
305 if (it != hostlist.end()) {
306 // Host is online and ready, initiate a remote session.
307 base::Timer timer(true, false);
308 timer.Start(FROM_HERE,
309 base::TimeDelta::FromSeconds(kConnectionTimeoutSeconds),
Sergey Ulanov 2015/07/20 19:19:29 nit: indentation.
310 run_loop->QuitClosure());
311 test_chromoting_client.StartConnection(
312 it->GenerateConnectionSetupInfo(access_token, username, pin));
313 run_loop->Run();
314 test_chromoting_client.EndConnection();
315 } else {
316 LOG(ERROR) << "Requested host not found or not ready to connect";
317 }
318
289 return 0; 319 return 0;
290 } 320 }
OLDNEW
« no previous file with comments | « remoting/test/app_remoting_connection_helper.cc ('k') | remoting/test/connection_setup_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698