Chromium Code Reviews| Index: remoting/test/chromoting_test_driver.cc |
| diff --git a/remoting/test/chromoting_test_driver.cc b/remoting/test/chromoting_test_driver.cc |
| index 5641f1c15164b06feebd6c6149659956d4d44298..6b948682aba848684afc15802fe313b57e4820de 100644 |
| --- a/remoting/test/chromoting_test_driver.cc |
| +++ b/remoting/test/chromoting_test_driver.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include <string> |
| +#include <vector> |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| @@ -16,6 +17,8 @@ |
| #include "google_apis/google_api_keys.h" |
| #include "net/base/escape.h" |
| #include "remoting/test/access_token_fetcher.h" |
| +#include "remoting/test/chromoting_host_info.h" |
| +#include "remoting/test/chromoting_host_list_fetcher.h" |
| #include "remoting/test/refresh_token_store.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -59,17 +62,23 @@ void PrintUsage() { |
| printf("************************************\n"); |
| printf("\nUsage:\n"); |
| - printf(" chromoting_test_driver --username=<example@gmail.com> [options]\n"); |
| + printf(" chromoting_test_driver --username=<example@gmail.com> [options]" |
| + " --hostname=<example hostname>\n"); |
| printf("\nRequired Parameters:\n"); |
| printf(" %s: Specifies which account to use when running tests\n", |
| switches::kUserNameSwitchName); |
| + printf(" %s: Specifies which host to connect to when running tests\n", |
| + switches::kHostNameSwitchName); |
| printf("\nOptional Parameters:\n"); |
| printf(" %s: Exchanged for a refresh and access token for authentication\n", |
| switches::kAuthCodeSwitchName); |
| - printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", |
| - switches::kRefreshTokenPathSwitchName); |
| printf(" %s: Displays additional usage information\n", |
| switches::kHelpSwitchName); |
| + printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n", |
| + switches::kRefreshTokenPathSwitchName); |
| + printf(" %s: Specifies the optional logging level of the tool (0-3)." |
| + " [default: off]\n", |
| + switches::kLoggingLevelSwitchName); |
| } |
| void PrintAuthCodeInfo() { |
| @@ -88,24 +97,25 @@ void PrintAuthCodeInfo() { |
| printf("\n has been revoked or expired.\n"); |
| printf(" Passing in the same auth code twice will result in an error\n"); |
| - printf( |
| - "\nFollow these steps to produce an auth code:\n" |
| - " - Open the Authorization URL link shown below in your browser\n" |
| - " - Approve the requested permissions for the tool\n" |
| - " - Copy the 'code' value in the redirected URL\n" |
| - " - Run the tool and pass in copied auth code as a parameter\n"); |
| + printf("\nFollow these steps to produce an auth code:\n" |
| + " - Open the Authorization URL link shown below in your browser\n" |
| + " - Approve the requested permissions for the tool\n" |
| + " - Copy the 'code' value in the redirected URL\n" |
| + " - Run the tool and pass in copied auth code as a parameter\n"); |
| printf("\nAuthorization URL:\n"); |
| printf("%s\n", GetAuthorizationCodeUri().c_str()); |
| printf("\nRedirected URL Example:\n"); |
| - printf( |
| - "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" |
| - "chrome-remote-desktop/dev?code=4/AKtf...\n"); |
| + printf("https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" |
| + "chrome-remote-desktop/dev?code=4/AKtf...\n"); |
| printf("\nTool usage example with the newly created auth code:\n"); |
| - printf("chromoting_test_driver --%s=example@gmail.com --%s=4/AKtf...\n\n", |
| - switches::kUserNameSwitchName, switches::kAuthCodeSwitchName); |
| + printf("chromoting_test_driver --%s=example@gmail.com --%s=example_host_name" |
| + " --%s=4/AKtf...\n\n", |
| + switches::kUserNameSwitchName, |
| + switches::kHostNameSwitchName, |
| + switches::kAuthCodeSwitchName); |
| } |
| void PrintJsonFileInfo() { |
| @@ -122,25 +132,50 @@ void PrintJsonFileInfo() { |
| printf("}\n\n"); |
| printf("\nTool usage example:\n"); |
| - printf("chromoting_test_driver --%s=%s --%s=./example_file.json\n\n", |
| + printf("chromoting_test_driver --%s=%s --%s=example_host_name" |
| + " --%s=./example_file.json\n\n", |
| switches::kUserNameSwitchName, "username1@fauxdomain.com", |
| - switches::kRefreshTokenPathSwitchName); |
| + switches::kHostNameSwitchName, switches::kRefreshTokenPathSwitchName); |
| } |
| -} // namespace |
| +} // namespace |
| void OnAccessTokenRetrieved( |
| base::Closure done_closure, |
| - const std::string& access_token, |
| - const std::string& refresh_token) { |
| + std::string* access_token, |
| + const std::string& retrieved_access_token, |
| + const std::string& retrieved_refresh_token) { |
| - DVLOG(1) << "OnAccessTokenRetrieved() Called"; |
| + VLOG(1) << "OnAccessTokenRetrieved() Called"; |
| + DVLOG(1) << "Access Token: " << retrieved_access_token; |
| - DVLOG(1) << "Access Token: " << access_token; |
| + *access_token = retrieved_access_token; |
| done_closure.Run(); |
| } |
| +void OnHostlistRetrieved( |
| + base::Closure done_closure, |
| + std::vector<remoting::test::ChromotingHostInfo>* hostlist, |
| + const std::vector<remoting::test::ChromotingHostInfo>& retrieved_hostlist, |
| + 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.
|
| + |
| + VLOG(1) << "OnHostlistRetrieved() Called"; |
| + |
| + DCHECK(hostlist); |
| + |
| + if (!request_success) { |
| + DVLOG(1) << "There was an error requesting for the host list"; |
| + done_closure.Run(); |
| + return; |
| + } |
| + |
| + *hostlist = retrieved_hostlist; |
| + |
| + DVLOG(1) << "There are " << hostlist->size() << " hosts in the hostlist"; |
| + done_closure.Run(); |
| +} |
| + |
| int main(int argc, char* argv[]) { |
| testing::InitGoogleTest(&argc, argv); |
| base::TestSuite test_suite(argc, argv); |
| @@ -221,10 +256,17 @@ int main(int argc, char* argv[]) { |
| // Uses the refresh token to get the access token from GAIA. |
| remoting::test::AccessTokenFetcher access_token_fetcher; |
| - base::RunLoop run_loop; |
| + // 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.
|
| + scoped_ptr<base::RunLoop> run_loop; |
| + // RunLoop to handle callback from GAIA. |
| + run_loop.reset(new base::RunLoop()); |
| + |
| + std::string access_token; |
| remoting::test::AccessTokenCallback access_token_callback = |
| - base::Bind(&OnAccessTokenRetrieved, run_loop.QuitClosure()); |
| + base::Bind(&OnAccessTokenRetrieved, |
| + run_loop->QuitClosure(), |
| + &access_token); |
| if (!auth_code.empty()) { |
| access_token_fetcher.GetAccessTokenFromAuthCode(auth_code, |
| @@ -235,7 +277,22 @@ int main(int argc, char* argv[]) { |
| access_token_callback); |
| } |
| - run_loop.Run(); |
| + run_loop->Run(); |
| + |
| + // Reset runloop to use it to retrieve hostlist from directory service. |
| + run_loop.reset(new base::RunLoop()); |
| + |
| + std::vector<remoting::test::ChromotingHostInfo> hostlist; |
| + remoting::test::ChromotingHostListFetcher::HostlistCallback |
| + hostlist_request_callback = base::Bind(&OnHostlistRetrieved, |
| + run_loop->QuitClosure(), |
| + &hostlist); |
| + |
| + // Uses the access token to get the hostlist from the Directory service. |
| + remoting::test::ChromotingHostListFetcher hostlist_fetcher; |
| + hostlist_fetcher.RetrieveHostlist(access_token, hostlist_request_callback); |
| + |
| + run_loop->Run(); |
| return 0; |
| } |