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

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

Issue 1212333011: Retrieved Hostlist information from Directory service. (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 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"
19 #include "remoting/test/refresh_token_store.h" 21 #include "remoting/test/refresh_token_store.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 namespace switches { 24 namespace switches {
23 const char kAuthCodeSwitchName[] = "authcode"; 25 const char kAuthCodeSwitchName[] = "authcode";
24 const char kHelpSwitchName[] = "help"; 26 const char kHelpSwitchName[] = "help";
25 const char kHostNameSwitchName[] = "hostname"; 27 const char kHostNameSwitchName[] = "hostname";
26 const char kLoggingLevelSwitchName[] = "verbosity"; 28 const char kLoggingLevelSwitchName[] = "verbosity";
27 const char kRefreshTokenPathSwitchName[] = "refresh-token-path"; 29 const char kRefreshTokenPathSwitchName[] = "refresh-token-path";
28 const char kSingleProcessTestsSwitchName[] = "single-process-tests"; 30 const char kSingleProcessTestsSwitchName[] = "single-process-tests";
(...skipping 23 matching lines...) Expand all
52 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), 54 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING),
53 use_plus).c_str()); 55 use_plus).c_str());
54 } 56 }
55 57
56 void PrintUsage() { 58 void PrintUsage() {
57 printf("\n************************************\n"); 59 printf("\n************************************\n");
58 printf("*** Chromoting Test Driver Usage ***\n"); 60 printf("*** Chromoting Test Driver Usage ***\n");
59 printf("************************************\n"); 61 printf("************************************\n");
60 62
61 printf("\nUsage:\n"); 63 printf("\nUsage:\n");
62 printf(" chromoting_test_driver --username=<example@gmail.com> [options]\n"); 64 printf(" chromoting_test_driver --username=<example@gmail.com> [options]\n");
joedow 2015/07/01 03:39:34 Doesn't hostname need to be included in the exampl
tonychun 2015/07/06 20:11:50 Done.
63 printf("\nRequired Parameters:\n"); 65 printf("\nRequired Parameters:\n");
64 printf(" %s: Specifies which account to use when running tests\n", 66 printf(" %s: Specifies which account to use when running tests\n",
65 switches::kUserNameSwitchName); 67 switches::kUserNameSwitchName);
68 printf(" %s: Specifies which host to connect to when running tests\n",
69 switches::kHostNameSwitchName);
66 printf("\nOptional Parameters:\n"); 70 printf("\nOptional Parameters:\n");
67 printf(" %s: Exchanged for a refresh and access token for authentication\n", 71 printf(" %s: Exchanged for a refresh and access token for authentication\n",
68 switches::kAuthCodeSwitchName); 72 switches::kAuthCodeSwitchName);
73 printf(" %s: Displays additional usage information\n",
74 switches::kHelpSwitchName);
69 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", 75 printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n",
70 switches::kRefreshTokenPathSwitchName); 76 switches::kRefreshTokenPathSwitchName);
71 printf(" %s: Displays additional usage information\n", 77 printf(
72 switches::kHelpSwitchName); 78 " %s: Specifies the optional logging level of the tool (0-3)."
joedow 2015/07/01 03:39:34 Why is this indented down? I think there is enoug
tonychun 2015/07/06 20:11:50 Done.
79 " [default: off]\n",
80 switches::kLoggingLevelSwitchName);
81
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");
(...skipping 15 matching lines...) Expand all
98 printf("\nAuthorization URL:\n"); 107 printf("\nAuthorization URL:\n");
99 printf("%s\n", GetAuthorizationCodeUri().c_str()); 108 printf("%s\n", GetAuthorizationCodeUri().c_str());
100 109
101 printf("\nRedirected URL Example:\n"); 110 printf("\nRedirected URL Example:\n");
102 printf( 111 printf(
103 "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" 112 "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/"
104 "chrome-remote-desktop/dev?code=4/AKtf...\n"); 113 "chrome-remote-desktop/dev?code=4/AKtf...\n");
105 114
106 printf("\nTool usage example with the newly created auth code:\n"); 115 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", 116 printf("chromoting_test_driver --%s=example@gmail.com --%s=4/AKtf...\n\n",
108 switches::kUserNameSwitchName, switches::kAuthCodeSwitchName); 117 switches::kUserNameSwitchName, switches::kAuthCodeSwitchName);
joedow 2015/07/01 03:39:34 hostname should be shown here, to reduce confusion
tonychun 2015/07/06 20:11:50 Done.
109 } 118 }
110 119
111 void PrintJsonFileInfo() { 120 void PrintJsonFileInfo() {
112 printf("\n****************************************\n"); 121 printf("\n****************************************\n");
113 printf("*** Refresh Token File Example Usage ***\n"); 122 printf("*** Refresh Token File Example Usage ***\n");
114 printf("****************************************\n\n"); 123 printf("****************************************\n\n");
115 124
116 printf("In order to use this option, a valid JSON file must exist, be\n"); 125 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"); 126 printf("properly formatted, and contain a username/token KVP.\n");
118 printf("Contents of example_file.json\n"); 127 printf("Contents of example_file.json\n");
119 printf("{\n"); 128 printf("{\n");
120 printf(" \"username1@fauxdomain.com\": \"1/3798Gsdf898shksdvfyi8sshad\",\n"); 129 printf(" \"username1@fauxdomain.com\": \"1/3798Gsdf898shksdvfyi8sshad\",\n");
121 printf(" \"username2@fauxdomain.com\": \"1/8974sdf87asdgadfgaerhfRsAa\",\n"); 130 printf(" \"username2@fauxdomain.com\": \"1/8974sdf87asdgadfgaerhfRsAa\",\n");
122 printf("}\n\n"); 131 printf("}\n\n");
123 132
124 printf("\nTool usage example:\n"); 133 printf("\nTool usage example:\n");
125 printf("chromoting_test_driver --%s=%s --%s=./example_file.json\n\n", 134 printf("chromoting_test_driver --%s=%s --%s=./example_file.json\n\n",
126 switches::kUserNameSwitchName, "username1@fauxdomain.com", 135 switches::kUserNameSwitchName, "username1@fauxdomain.com",
127 switches::kRefreshTokenPathSwitchName); 136 switches::kRefreshTokenPathSwitchName);
joedow 2015/07/01 03:39:34 hostname?
tonychun 2015/07/06 20:11:50 Done.
128 } 137 }
129 138
139 // TODO(TonyChun): Using a namespace global temp string variable that is used to
140 // save the access_token value in the callback. Will be removed once an
141 // environment is created.
142 std::string temp_access_token;
joedow 2015/07/01 03:39:34 A cleaner way to do this would be to add an extra
tonychun 2015/07/06 20:11:50 Done.
143
130 } // namespace 144 } // namespace
131 145
132 void OnAccessTokenRetrieved( 146 void OnAccessTokenRetrieved(
133 base::Closure done_closure, 147 base::Closure done_closure,
134 const std::string& access_token, 148 const std::string& access_token,
135 const std::string& refresh_token) { 149 const std::string& refresh_token) {
136 150
137 DVLOG(1) << "OnAccessTokenRetrieved() Called"; 151 DVLOG(1) << "OnAccessTokenRetrieved() Called";
152 DVLOG(1) << "Access Token: " << access_token;
138 153
139 DVLOG(1) << "Access Token: " << access_token; 154 temp_access_token = access_token;
140 155
141 done_closure.Run(); 156 done_closure.Run();
142 } 157 }
143 158
159 void OnHostlistRetrieved(
160 base::Closure done_closure,
161 std::vector<remoting::test::ChromotingHostInfo>* hostlist,
162 const std::vector<remoting::test::ChromotingHostInfo>& retrieved_hostlist) {
163 DVLOG(1) << "OnHostlistRetrieved() Called";
164
joedow 2015/07/01 03:39:34 DCHECK(hostlist);
tonychun 2015/07/06 20:11:50 Done.
165 *hostlist = retrieved_hostlist;
166
167 done_closure.Run();
168 }
169
144 int main(int argc, char* argv[]) { 170 int main(int argc, char* argv[]) {
145 testing::InitGoogleTest(&argc, argv); 171 testing::InitGoogleTest(&argc, argv);
146 base::TestSuite test_suite(argc, argv); 172 base::TestSuite test_suite(argc, argv);
147 173
148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 174 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
149 DCHECK(command_line); 175 DCHECK(command_line);
150 176
151 // Do not retry if tests fails. 177 // Do not retry if tests fails.
152 command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0"); 178 command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0");
153 179
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return -1; 240 return -1;
215 } 241 }
216 242
217 // Used for running network request tasks. 243 // Used for running network request tasks.
218 // TODO(TonyChun): Move this logic into a shared environment class. 244 // TODO(TonyChun): Move this logic into a shared environment class.
219 base::MessageLoopForIO message_loop; 245 base::MessageLoopForIO message_loop;
220 246
221 // Uses the refresh token to get the access token from GAIA. 247 // Uses the refresh token to get the access token from GAIA.
222 remoting::test::AccessTokenFetcher access_token_fetcher; 248 remoting::test::AccessTokenFetcher access_token_fetcher;
223 249
224 base::RunLoop run_loop; 250 // Thread to handle callback from GAIA.
251 base::RunLoop access_token_run_loop;
joedow 2015/07/01 03:39:34 nit: if you use a scoped_ptr<base::RunLoop> you ca
tonychun 2015/07/06 20:11:50 Done.
225 252
226 remoting::test::AccessTokenCallback access_token_callback = 253 remoting::test::AccessTokenCallback access_token_callback =
227 base::Bind(&OnAccessTokenRetrieved, run_loop.QuitClosure()); 254 base::Bind(&OnAccessTokenRetrieved, access_token_run_loop.QuitClosure());
228 255
229 if (!auth_code.empty()) { 256 if (!auth_code.empty()) {
230 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, 257 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code,
231 access_token_callback); 258 access_token_callback);
232 } else { 259 } else {
233 DCHECK(!refresh_token.empty()); 260 DCHECK(!refresh_token.empty());
234 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token, 261 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token,
235 access_token_callback); 262 access_token_callback);
236 } 263 }
237 264
238 run_loop.Run(); 265 access_token_run_loop.Run();
266
267 // Thread to handle callback from Directory service.
joedow 2015/07/01 03:39:34 This isn't a thread, it's a runloop which just yie
tonychun 2015/07/06 20:11:50 Done.
268 base::RunLoop hostlist_run_loop;
269
270 std::vector<remoting::test::ChromotingHostInfo> hostlist;
271
272 remoting::test::HostlistCallback hostlist_fetch_callback = base::Bind(
273 &OnHostlistRetrieved, hostlist_run_loop.QuitClosure(), &hostlist);
274
275 // Uses the access token to get the hostlist from the Directory service.
276 remoting::test::HostlistFetcher hostlist_fetcher;
277
278 hostlist_fetcher.RetrieveHostlist(
279 temp_access_token,
280 remoting::test::ServiceEnvironment::kProductionEnvironment,
281 hostlist_fetch_callback);
282
283 hostlist_run_loop.Run();
239 284
240 return 0; 285 return 0;
241 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698