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

Unified 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: Added unittests and cleaned up format of C++ code. 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 side-by-side diff with in-line comments
Download patch
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..e0a219510bec40e39ff49cf0ba07cd11ec117f06 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,21 +132,40 @@ 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";
+ 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,
+ std::vector<remoting::test::ChromotingHostInfo>* retrieved_hostlist) {
joedow 2015/07/06 22:19:15 retrieved_hostlist should be const ref
tonychun 2015/07/08 03:12:15 Done.
+
+ DVLOG(1) << "OnHostlistRetrieved() Called";
joedow 2015/07/06 22:19:14 FYI, I've switched over to using VLOG instead of D
tonychun 2015/07/08 03:12:15 Done.
+
+ DCHECK(hostlist);
+
+ *hostlist = *retrieved_hostlist;
+
+ DVLOG(1) << "There are " << hostlist->size() << " hosts in the hostlist";
done_closure.Run();
}
@@ -221,10 +250,18 @@ 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
+ scoped_ptr<base::RunLoop> run_loop;
+
+ // RunLoop to handle callback from GAIA.
+ run_loop.reset(new base::RunLoop());
+
+ std::string access_token;
joedow 2015/07/06 22:19:14 remove newline
tonychun 2015/07/08 03:12:15 Done.
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 +272,22 @@ int main(int argc, char* argv[]) {
access_token_callback);
}
- run_loop.Run();
+ run_loop->Run();
+
+ // RunLoop to handle callback from Directory service.
joedow 2015/07/06 22:19:14 update comment "Reset runloop to use it to retriev
tonychun 2015/07/08 03:12:15 Done.
+ run_loop.reset(new base::RunLoop());
+
+ std::vector<remoting::test::ChromotingHostInfo> hostlist;
+
joedow 2015/07/06 22:19:14 remove newline
tonychun 2015/07/08 03:12:16 Done.
+ remoting::test::HostlistCallback hostlist_fetch_callback = base::Bind(
joedow 2015/07/06 22:19:14 hostlist_fetch_callback can be rename hostlist_req
tonychun 2015/07/08 03:12:16 Done.
+ &OnHostlistRetrieved, run_loop->QuitClosure(), &hostlist);
joedow 2015/07/06 22:19:14 base::ConstRef(hostlist)
tonychun 2015/07/08 03:12:16 If you look at my new function, void OnHostlistRe
+
+ // Uses the access token to get the hostlist from the Directory service.
+ remoting::test::ChromotingHostListFetcher hostlist_fetcher;
+
joedow 2015/07/06 22:19:14 Remove newline
tonychun 2015/07/08 03:12:16 Done.
+ hostlist_fetcher.RetrieveHostlist(access_token, hostlist_fetch_callback);
+
+ run_loop->Run();
return 0;
}

Powered by Google App Engine
This is Rietveld 408576698