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 VLOG(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 } |
143 | 156 |
157 void OnHostlistRetrieved( | |
158 base::Closure done_closure, | |
159 std::vector<remoting::test::ChromotingHostInfo>* hostlist, | |
160 const std::vector<remoting::test::ChromotingHostInfo>& retrieved_hostlist, | |
161 bool request_success) { | |
joedow
2015/07/08 17:19:08
I actually don't think the bool here provides much
tonychun
2015/07/08 22:38:16
Done.
| |
162 | |
163 VLOG(1) << "OnHostlistRetrieved() Called"; | |
164 | |
165 DCHECK(hostlist); | |
166 | |
167 if (!request_success) { | |
168 DVLOG(1) << "There was an error requesting for the host list"; | |
169 done_closure.Run(); | |
170 return; | |
171 } | |
172 | |
173 *hostlist = retrieved_hostlist; | |
174 | |
175 DVLOG(1) << "There are " << hostlist->size() << " hosts in the hostlist"; | |
176 done_closure.Run(); | |
177 } | |
178 | |
144 int main(int argc, char* argv[]) { | 179 int main(int argc, char* argv[]) { |
145 testing::InitGoogleTest(&argc, argv); | 180 testing::InitGoogleTest(&argc, argv); |
146 base::TestSuite test_suite(argc, argv); | 181 base::TestSuite test_suite(argc, argv); |
147 | 182 |
148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 183 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
149 DCHECK(command_line); | 184 DCHECK(command_line); |
150 | 185 |
151 // Do not retry if tests fails. | 186 // Do not retry if tests fails. |
152 command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0"); | 187 command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0"); |
153 | 188 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 return -1; | 249 return -1; |
215 } | 250 } |
216 | 251 |
217 // Used for running network request tasks. | 252 // Used for running network request tasks. |
218 // TODO(TonyChun): Move this logic into a shared environment class. | 253 // TODO(TonyChun): Move this logic into a shared environment class. |
219 base::MessageLoopForIO message_loop; | 254 base::MessageLoopForIO message_loop; |
220 | 255 |
221 // Uses the refresh token to get the access token from GAIA. | 256 // Uses the refresh token to get the access token from GAIA. |
222 remoting::test::AccessTokenFetcher access_token_fetcher; | 257 remoting::test::AccessTokenFetcher access_token_fetcher; |
223 | 258 |
224 base::RunLoop run_loop; | 259 // A RunLoop that yields to the thread's MessageLoopForIO |
joedow
2015/07/08 17:19:08
nit: MessageLoop, also, comments should end with p
tonychun
2015/07/08 22:38:16
Done.
| |
260 scoped_ptr<base::RunLoop> run_loop; | |
225 | 261 |
262 // RunLoop to handle callback from GAIA. | |
263 run_loop.reset(new base::RunLoop()); | |
264 | |
265 std::string access_token; | |
226 remoting::test::AccessTokenCallback access_token_callback = | 266 remoting::test::AccessTokenCallback access_token_callback = |
227 base::Bind(&OnAccessTokenRetrieved, run_loop.QuitClosure()); | 267 base::Bind(&OnAccessTokenRetrieved, |
268 run_loop->QuitClosure(), | |
269 &access_token); | |
228 | 270 |
229 if (!auth_code.empty()) { | 271 if (!auth_code.empty()) { |
230 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, | 272 access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, |
231 access_token_callback); | 273 access_token_callback); |
232 } else { | 274 } else { |
233 DCHECK(!refresh_token.empty()); | 275 DCHECK(!refresh_token.empty()); |
234 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token, | 276 access_token_fetcher.GetAccessTokenFromRefreshToken(refresh_token, |
235 access_token_callback); | 277 access_token_callback); |
236 } | 278 } |
237 | 279 |
238 run_loop.Run(); | 280 run_loop->Run(); |
281 | |
282 // Reset runloop to use it to retrieve hostlist from directory service. | |
283 run_loop.reset(new base::RunLoop()); | |
284 | |
285 std::vector<remoting::test::ChromotingHostInfo> hostlist; | |
286 remoting::test::ChromotingHostListFetcher::HostlistCallback | |
287 hostlist_request_callback = base::Bind(&OnHostlistRetrieved, | |
288 run_loop->QuitClosure(), | |
289 &hostlist); | |
290 | |
291 // Uses the access token to get the hostlist from the Directory service. | |
292 remoting::test::ChromotingHostListFetcher hostlist_fetcher; | |
293 hostlist_fetcher.RetrieveHostlist(access_token, hostlist_request_callback); | |
294 | |
295 run_loop->Run(); | |
239 | 296 |
240 return 0; | 297 return 0; |
241 } | 298 } |
OLD | NEW |