Chromium Code Reviews| Index: remoting/test/app_remoting_test_driver_environment.cc |
| diff --git a/remoting/test/app_remoting_test_driver_environment.cc b/remoting/test/app_remoting_test_driver_environment.cc |
| index 874e46aea294e68e44fb6eae1638f0e7bc87c477..837fdb0db37fec99c1c3beda113b82e97832e6ff 100644 |
| --- a/remoting/test/app_remoting_test_driver_environment.cc |
| +++ b/remoting/test/app_remoting_test_driver_environment.cc |
| @@ -4,6 +4,10 @@ |
| #include "remoting/test/app_remoting_test_driver_environment.h" |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| #include "base/bind.h" |
| #include "base/callback_forward.h" |
| #include "base/logging.h" |
| @@ -11,8 +15,13 @@ |
| #include "base/run_loop.h" |
| #include "remoting/test/access_token_fetcher.h" |
| #include "remoting/test/refresh_token_store.h" |
| +#include "remoting/test/remote_application_data.h" |
| #include "remoting/test/remote_host_info.h" |
| +namespace { |
| +const char kHostAvailabilityFormatString[] = "%-25s%-40s%-10s\n"; |
|
Wez
2015/03/16 22:19:10
You can define this immediately before the printf
joedow
2015/03/18 20:13:09
Done.
|
| +} |
| + |
| namespace remoting { |
| namespace test { |
| @@ -99,11 +108,9 @@ bool AppRemotingTestDriverEnvironment::GetRemoteHostInfoForApplicationId( |
| base::RunLoop run_loop; |
| - RemoteHostInfoCallback remote_host_info_fetch_callback = |
| - base::Bind(&AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved, |
| - base::Unretained(this), |
| - run_loop.QuitClosure(), |
| - remote_host_info); |
| + RemoteHostInfoCallback remote_host_info_fetch_callback = base::Bind( |
| + &AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved, |
| + base::Unretained(this), run_loop.QuitClosure(), remote_host_info); |
| // If a unit test has set |test_remote_host_info_fetcher_| then we should use |
| // it below. Note that we do not want to destroy the test object at the end |
| @@ -117,9 +124,7 @@ bool AppRemotingTestDriverEnvironment::GetRemoteHostInfoForApplicationId( |
| } |
| remote_host_info_fetcher->RetrieveRemoteHostInfo( |
| - application_id, |
| - access_token_, |
| - service_environment_, |
| + application_id, access_token_, service_environment_, |
| remote_host_info_fetch_callback); |
| run_loop.Run(); |
| @@ -127,6 +132,41 @@ bool AppRemotingTestDriverEnvironment::GetRemoteHostInfoForApplicationId( |
| return remote_host_info->IsReadyForConnection(); |
| } |
| +void AppRemotingTestDriverEnvironment::ShowHostAvailability() { |
| + std::vector<std::string> app_names = GetRemoteApplicationNames(); |
| + std::map<std::string, ApplicationInfo> app_info = |
| + GetRemoteApplicationInfoMap(); |
| + std::vector<std::string>::const_iterator it = app_names.begin(); |
| + |
| + printf(kHostAvailabilityFormatString, "Application Name", "Application ID", |
| + "Status"); |
| + |
| + while (it != app_names.end()) { |
| + std::string application_name = *it; |
| + |
| + DCHECK_GT(app_info.count(application_name), 0UL); |
| + ApplicationInfo& info = app_info.at(application_name); |
| + |
| + RemoteHostInfo remote_host_info; |
| + GetRemoteHostInfoForApplicationId(info.application_id, &remote_host_info); |
| + |
| + std::string status; |
| + RemoteHostStatus remote_host_status = remote_host_info.remote_host_status; |
| + if (remote_host_status == kRemoteHostStatusReady) { |
| + status = "Ready :)"; |
| + } else if (remote_host_status == kRemoteHostStatusPending) { |
| + status = "Pending :|"; |
| + } else { |
| + status = "Unknown :("; |
| + } |
| + |
| + printf(kHostAvailabilityFormatString, application_name.c_str(), |
| + info.application_id.c_str(), status.c_str()); |
|
Wez
2015/03/16 22:19:10
Is it normal to use printf() in test fixtures, rat
joedow
2015/03/18 20:13:09
Done. I used printf in the main cc file and had f
Wez
2015/03/21 00:14:01
SGTM, although when I wrote that I hadn't realised
joedow
2015/03/21 01:23:59
Acknowledged.
|
| + |
| + ++it; |
| + } |
| +} |
| + |
| void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest( |
| AccessTokenFetcher* access_token_fetcher) { |
| DCHECK(access_token_fetcher); |
| @@ -164,8 +204,7 @@ bool AppRemotingTestDriverEnvironment::RetrieveAccessToken( |
| AccessTokenCallback access_token_callback = |
| base::Bind(&AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved, |
| - base::Unretained(this), |
| - run_loop.QuitClosure()); |
| + base::Unretained(this), run_loop.QuitClosure()); |
| // If a unit test has set |test_access_token_fetcher_| then we should use it |
| // below. Note that we do not want to destroy the test object at the end of |
| @@ -180,15 +219,13 @@ bool AppRemotingTestDriverEnvironment::RetrieveAccessToken( |
| if (!auth_code.empty()) { |
| // If the user passed in an authcode, then use it to retrieve an |
| // updated access/refresh token. |
| - access_token_fetcher->GetAccessTokenFromAuthCode( |
| - auth_code, |
| - access_token_callback); |
| + access_token_fetcher->GetAccessTokenFromAuthCode(auth_code, |
| + access_token_callback); |
| } else { |
| DCHECK(!refresh_token_.empty()); |
| - access_token_fetcher->GetAccessTokenFromRefreshToken( |
| - refresh_token_, |
| - access_token_callback); |
| + access_token_fetcher->GetAccessTokenFromRefreshToken(refresh_token_, |
| + access_token_callback); |
| } |
| run_loop.Run(); |
| @@ -243,9 +280,7 @@ void AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved( |
| const RemoteHostInfo& retrieved_remote_host_info) { |
| DCHECK(remote_host_info); |
| - if (retrieved_remote_host_info.IsReadyForConnection()) { |
| - *remote_host_info = retrieved_remote_host_info; |
| - } |
| + *remote_host_info = retrieved_remote_host_info; |
| done_closure.Run(); |
| } |