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

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

Issue 1008043003: Adding Test Fixture for initial test cases for the App Remoting Test Driver. Also includes the pub… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Wez's feedback Created 5 years, 9 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 "remoting/test/app_remoting_test_driver_environment.h" 5 #include "remoting/test/app_remoting_test_driver_environment.h"
6 6
7 #include <map>
8 #include <string>
9 #include <vector>
10
7 #include "base/bind.h" 11 #include "base/bind.h"
8 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
9 #include "base/logging.h" 13 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/stringprintf.h"
12 #include "remoting/test/access_token_fetcher.h" 17 #include "remoting/test/access_token_fetcher.h"
13 #include "remoting/test/refresh_token_store.h" 18 #include "remoting/test/refresh_token_store.h"
14 #include "remoting/test/remote_host_info.h" 19 #include "remoting/test/remote_host_info.h"
15 20
16 namespace remoting { 21 namespace remoting {
17 namespace test { 22 namespace test {
18 23
19 AppRemotingTestDriverEnvironment* AppRemotingSharedData; 24 AppRemotingTestDriverEnvironment* AppRemotingSharedData;
20 25
21 AppRemotingTestDriverEnvironment::AppRemotingTestDriverEnvironment( 26 AppRemotingTestDriverEnvironment::AppRemotingTestDriverEnvironment(
22 const std::string& user_name, 27 const std::string& user_name,
23 ServiceEnvironment service_environment) 28 ServiceEnvironment service_environment)
24 : user_name_(user_name), 29 : user_name_(user_name),
25 service_environment_(service_environment), 30 service_environment_(service_environment),
26 test_access_token_fetcher_(nullptr), 31 test_access_token_fetcher_(nullptr),
27 test_refresh_token_store_(nullptr), 32 test_refresh_token_store_(nullptr),
28 test_remote_host_info_fetcher_(nullptr) { 33 test_remote_host_info_fetcher_(nullptr) {
29 DCHECK(!user_name_.empty()); 34 DCHECK(!user_name_.empty());
30 DCHECK(service_environment < kUnknownEnvironment); 35 DCHECK(service_environment < kUnknownEnvironment);
36
37 PopulateApplicationNames();
38 PopulateApplicationDetailsMap();
31 } 39 }
32 40
33 AppRemotingTestDriverEnvironment::~AppRemotingTestDriverEnvironment() { 41 AppRemotingTestDriverEnvironment::~AppRemotingTestDriverEnvironment() {
34 } 42 }
35 43
36 bool AppRemotingTestDriverEnvironment::Initialize( 44 bool AppRemotingTestDriverEnvironment::Initialize(
37 const std::string& auth_code) { 45 const std::string& auth_code) {
38 if (!access_token_.empty()) { 46 if (!access_token_.empty()) {
39 return true; 47 return true;
40 } 48 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 100
93 scoped_ptr<base::MessageLoopForIO> message_loop; 101 scoped_ptr<base::MessageLoopForIO> message_loop;
94 if (!base::MessageLoop::current()) { 102 if (!base::MessageLoop::current()) {
95 // Create a temporary message loop if the current thread does not already 103 // Create a temporary message loop if the current thread does not already
96 // have one so we can use its task runner for our network request. 104 // have one so we can use its task runner for our network request.
97 message_loop.reset(new base::MessageLoopForIO); 105 message_loop.reset(new base::MessageLoopForIO);
98 } 106 }
99 107
100 base::RunLoop run_loop; 108 base::RunLoop run_loop;
101 109
102 RemoteHostInfoCallback remote_host_info_fetch_callback = 110 RemoteHostInfoCallback remote_host_info_fetch_callback = base::Bind(
103 base::Bind(&AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved, 111 &AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved,
104 base::Unretained(this), 112 base::Unretained(this), run_loop.QuitClosure(), remote_host_info);
105 run_loop.QuitClosure(),
106 remote_host_info);
107 113
108 // If a unit test has set |test_remote_host_info_fetcher_| then we should use 114 // If a unit test has set |test_remote_host_info_fetcher_| then we should use
109 // it below. Note that we do not want to destroy the test object at the end 115 // it below. Note that we do not want to destroy the test object at the end
110 // of the function which is why we have the dance below. 116 // of the function which is why we have the dance below.
111 scoped_ptr<RemoteHostInfoFetcher> temporary_remote_host_info_fetcher; 117 scoped_ptr<RemoteHostInfoFetcher> temporary_remote_host_info_fetcher;
112 RemoteHostInfoFetcher* remote_host_info_fetcher = 118 RemoteHostInfoFetcher* remote_host_info_fetcher =
113 test_remote_host_info_fetcher_; 119 test_remote_host_info_fetcher_;
114 if (!remote_host_info_fetcher) { 120 if (!remote_host_info_fetcher) {
115 temporary_remote_host_info_fetcher.reset(new RemoteHostInfoFetcher()); 121 temporary_remote_host_info_fetcher.reset(new RemoteHostInfoFetcher());
116 remote_host_info_fetcher = temporary_remote_host_info_fetcher.get(); 122 remote_host_info_fetcher = temporary_remote_host_info_fetcher.get();
117 } 123 }
118 124
119 remote_host_info_fetcher->RetrieveRemoteHostInfo( 125 remote_host_info_fetcher->RetrieveRemoteHostInfo(
120 application_id, 126 application_id, access_token_, service_environment_,
121 access_token_,
122 service_environment_,
123 remote_host_info_fetch_callback); 127 remote_host_info_fetch_callback);
124 128
125 run_loop.Run(); 129 run_loop.Run();
126 130
127 return remote_host_info->IsReadyForConnection(); 131 return remote_host_info->IsReadyForConnection();
128 } 132 }
129 133
134 void AppRemotingTestDriverEnvironment::ShowHostAvailability() {
135 const char kHostAvailabilityFormatString[] = "%-25s%-35s%-10s";
136 std::vector<std::string>::const_iterator it = application_names_.begin();
137
138 LOG(INFO) << base::StringPrintf(kHostAvailabilityFormatString,
139 "Application Name", "Application ID",
140 "Status");
141
142 while (it != application_names_.end()) {
143 std::string application_name = *it;
144
145 DCHECK_GT(application_details_map_.count(application_name), 0UL);
146 RemoteApplicationDetails& application_details =
147 application_details_map_.at(application_name);
Wez 2015/03/21 00:14:01 This DCHECK + fetch mirrors what GetDetailsFromApp
joedow 2015/03/21 01:23:59 Done.
148
149 RemoteHostInfo remote_host_info;
150 GetRemoteHostInfoForApplicationId(application_details.application_id,
151 &remote_host_info);
152
153 std::string status;
154 RemoteHostStatus remote_host_status = remote_host_info.remote_host_status;
155 if (remote_host_status == kRemoteHostStatusReady) {
156 status = "Ready :)";
157 } else if (remote_host_status == kRemoteHostStatusPending) {
158 status = "Pending :|";
159 } else {
160 status = "Unknown :(";
161 }
162
163 LOG(INFO) << base::StringPrintf(
164 kHostAvailabilityFormatString, application_name.c_str(),
165 application_details.application_id.c_str(), status.c_str());
166
167 ++it;
168 }
169 }
170
171 const RemoteApplicationDetails&
172 AppRemotingTestDriverEnvironment::GetDetailsFromAppName(
173 const std::string& application_name) {
174 DCHECK_GT(application_details_map_.count(application_name), 0UL);
175
176 return application_details_map_.at(application_name);
177 }
178
130 void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest( 179 void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest(
131 AccessTokenFetcher* access_token_fetcher) { 180 AccessTokenFetcher* access_token_fetcher) {
132 DCHECK(access_token_fetcher); 181 DCHECK(access_token_fetcher);
133 182
134 test_access_token_fetcher_ = access_token_fetcher; 183 test_access_token_fetcher_ = access_token_fetcher;
135 } 184 }
136 185
137 void AppRemotingTestDriverEnvironment::SetRefreshTokenStoreForTest( 186 void AppRemotingTestDriverEnvironment::SetRefreshTokenStoreForTest(
138 RefreshTokenStore* refresh_token_store) { 187 RefreshTokenStore* refresh_token_store) {
139 DCHECK(refresh_token_store); 188 DCHECK(refresh_token_store);
(...skipping 17 matching lines...) Expand all
157 // have one so we can use its task runner for our network request. 206 // have one so we can use its task runner for our network request.
158 message_loop.reset(new base::MessageLoopForIO); 207 message_loop.reset(new base::MessageLoopForIO);
159 } 208 }
160 209
161 base::RunLoop run_loop; 210 base::RunLoop run_loop;
162 211
163 access_token_.clear(); 212 access_token_.clear();
164 213
165 AccessTokenCallback access_token_callback = 214 AccessTokenCallback access_token_callback =
166 base::Bind(&AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved, 215 base::Bind(&AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved,
167 base::Unretained(this), 216 base::Unretained(this), run_loop.QuitClosure());
168 run_loop.QuitClosure());
169 217
170 // If a unit test has set |test_access_token_fetcher_| then we should use it 218 // If a unit test has set |test_access_token_fetcher_| then we should use it
171 // below. Note that we do not want to destroy the test object at the end of 219 // below. Note that we do not want to destroy the test object at the end of
172 // the function which is why we have the dance below. 220 // the function which is why we have the dance below.
173 scoped_ptr<AccessTokenFetcher> temporary_access_token_fetcher; 221 scoped_ptr<AccessTokenFetcher> temporary_access_token_fetcher;
174 AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_; 222 AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_;
175 if (!access_token_fetcher) { 223 if (!access_token_fetcher) {
176 temporary_access_token_fetcher.reset(new AccessTokenFetcher()); 224 temporary_access_token_fetcher.reset(new AccessTokenFetcher());
177 access_token_fetcher = temporary_access_token_fetcher.get(); 225 access_token_fetcher = temporary_access_token_fetcher.get();
178 } 226 }
179 227
180 if (!auth_code.empty()) { 228 if (!auth_code.empty()) {
181 // If the user passed in an authcode, then use it to retrieve an 229 // If the user passed in an authcode, then use it to retrieve an
182 // updated access/refresh token. 230 // updated access/refresh token.
183 access_token_fetcher->GetAccessTokenFromAuthCode( 231 access_token_fetcher->GetAccessTokenFromAuthCode(auth_code,
184 auth_code, 232 access_token_callback);
185 access_token_callback);
186 } else { 233 } else {
187 DCHECK(!refresh_token_.empty()); 234 DCHECK(!refresh_token_.empty());
188 235
189 access_token_fetcher->GetAccessTokenFromRefreshToken( 236 access_token_fetcher->GetAccessTokenFromRefreshToken(refresh_token_,
190 refresh_token_, 237 access_token_callback);
191 access_token_callback);
192 } 238 }
193 239
194 run_loop.Run(); 240 run_loop.Run();
195 241
196 // If we were using an auth_code and received a valid refresh token, 242 // If we were using an auth_code and received a valid refresh token,
197 // then we want to store it locally. If we had an auth code and did not 243 // then we want to store it locally. If we had an auth code and did not
198 // receive a refresh token, then we should let the user know and exit. 244 // receive a refresh token, then we should let the user know and exit.
199 if (!auth_code.empty()) { 245 if (!auth_code.empty()) {
200 if (!refresh_token_.empty()) { 246 if (!refresh_token_.empty()) {
201 // If a unit test has set |test_refresh_token_store_| then we should use 247 // If a unit test has set |test_refresh_token_store_| then we should use
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 282
237 done_closure.Run(); 283 done_closure.Run();
238 } 284 }
239 285
240 void AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved( 286 void AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved(
241 base::Closure done_closure, 287 base::Closure done_closure,
242 RemoteHostInfo* remote_host_info, 288 RemoteHostInfo* remote_host_info,
243 const RemoteHostInfo& retrieved_remote_host_info) { 289 const RemoteHostInfo& retrieved_remote_host_info) {
244 DCHECK(remote_host_info); 290 DCHECK(remote_host_info);
245 291
246 if (retrieved_remote_host_info.IsReadyForConnection()) { 292 *remote_host_info = retrieved_remote_host_info;
247 *remote_host_info = retrieved_remote_host_info;
248 }
249 293
250 done_closure.Run(); 294 done_closure.Run();
251 } 295 }
252 296
253 } // namespace test 297 } // namespace test
254 } // namespace remoting 298 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698