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

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: 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"
12 #include "remoting/test/access_token_fetcher.h" 16 #include "remoting/test/access_token_fetcher.h"
13 #include "remoting/test/refresh_token_store.h" 17 #include "remoting/test/refresh_token_store.h"
18 #include "remoting/test/remote_application_data.h"
14 #include "remoting/test/remote_host_info.h" 19 #include "remoting/test/remote_host_info.h"
15 20
21 namespace {
22 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.
23 }
24
16 namespace remoting { 25 namespace remoting {
17 namespace test { 26 namespace test {
18 27
19 AppRemotingTestDriverEnvironment* AppRemotingSharedData; 28 AppRemotingTestDriverEnvironment* AppRemotingSharedData;
20 29
21 AppRemotingTestDriverEnvironment::AppRemotingTestDriverEnvironment( 30 AppRemotingTestDriverEnvironment::AppRemotingTestDriverEnvironment(
22 const std::string& user_name, 31 const std::string& user_name,
23 ServiceEnvironment service_environment) 32 ServiceEnvironment service_environment)
24 : user_name_(user_name), 33 : user_name_(user_name),
25 service_environment_(service_environment), 34 service_environment_(service_environment),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 101
93 scoped_ptr<base::MessageLoopForIO> message_loop; 102 scoped_ptr<base::MessageLoopForIO> message_loop;
94 if (!base::MessageLoop::current()) { 103 if (!base::MessageLoop::current()) {
95 // Create a temporary message loop if the current thread does not already 104 // 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. 105 // have one so we can use its task runner for our network request.
97 message_loop.reset(new base::MessageLoopForIO); 106 message_loop.reset(new base::MessageLoopForIO);
98 } 107 }
99 108
100 base::RunLoop run_loop; 109 base::RunLoop run_loop;
101 110
102 RemoteHostInfoCallback remote_host_info_fetch_callback = 111 RemoteHostInfoCallback remote_host_info_fetch_callback = base::Bind(
103 base::Bind(&AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved, 112 &AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved,
104 base::Unretained(this), 113 base::Unretained(this), run_loop.QuitClosure(), remote_host_info);
105 run_loop.QuitClosure(),
106 remote_host_info);
107 114
108 // If a unit test has set |test_remote_host_info_fetcher_| then we should use 115 // 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 116 // 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. 117 // of the function which is why we have the dance below.
111 scoped_ptr<RemoteHostInfoFetcher> temporary_remote_host_info_fetcher; 118 scoped_ptr<RemoteHostInfoFetcher> temporary_remote_host_info_fetcher;
112 RemoteHostInfoFetcher* remote_host_info_fetcher = 119 RemoteHostInfoFetcher* remote_host_info_fetcher =
113 test_remote_host_info_fetcher_; 120 test_remote_host_info_fetcher_;
114 if (!remote_host_info_fetcher) { 121 if (!remote_host_info_fetcher) {
115 temporary_remote_host_info_fetcher.reset(new RemoteHostInfoFetcher()); 122 temporary_remote_host_info_fetcher.reset(new RemoteHostInfoFetcher());
116 remote_host_info_fetcher = temporary_remote_host_info_fetcher.get(); 123 remote_host_info_fetcher = temporary_remote_host_info_fetcher.get();
117 } 124 }
118 125
119 remote_host_info_fetcher->RetrieveRemoteHostInfo( 126 remote_host_info_fetcher->RetrieveRemoteHostInfo(
120 application_id, 127 application_id, access_token_, service_environment_,
121 access_token_,
122 service_environment_,
123 remote_host_info_fetch_callback); 128 remote_host_info_fetch_callback);
124 129
125 run_loop.Run(); 130 run_loop.Run();
126 131
127 return remote_host_info->IsReadyForConnection(); 132 return remote_host_info->IsReadyForConnection();
128 } 133 }
129 134
135 void AppRemotingTestDriverEnvironment::ShowHostAvailability() {
136 std::vector<std::string> app_names = GetRemoteApplicationNames();
137 std::map<std::string, ApplicationInfo> app_info =
138 GetRemoteApplicationInfoMap();
139 std::vector<std::string>::const_iterator it = app_names.begin();
140
141 printf(kHostAvailabilityFormatString, "Application Name", "Application ID",
142 "Status");
143
144 while (it != app_names.end()) {
145 std::string application_name = *it;
146
147 DCHECK_GT(app_info.count(application_name), 0UL);
148 ApplicationInfo& info = app_info.at(application_name);
149
150 RemoteHostInfo remote_host_info;
151 GetRemoteHostInfoForApplicationId(info.application_id, &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 printf(kHostAvailabilityFormatString, application_name.c_str(),
164 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.
165
166 ++it;
167 }
168 }
169
130 void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest( 170 void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest(
131 AccessTokenFetcher* access_token_fetcher) { 171 AccessTokenFetcher* access_token_fetcher) {
132 DCHECK(access_token_fetcher); 172 DCHECK(access_token_fetcher);
133 173
134 test_access_token_fetcher_ = access_token_fetcher; 174 test_access_token_fetcher_ = access_token_fetcher;
135 } 175 }
136 176
137 void AppRemotingTestDriverEnvironment::SetRefreshTokenStoreForTest( 177 void AppRemotingTestDriverEnvironment::SetRefreshTokenStoreForTest(
138 RefreshTokenStore* refresh_token_store) { 178 RefreshTokenStore* refresh_token_store) {
139 DCHECK(refresh_token_store); 179 DCHECK(refresh_token_store);
(...skipping 17 matching lines...) Expand all
157 // have one so we can use its task runner for our network request. 197 // have one so we can use its task runner for our network request.
158 message_loop.reset(new base::MessageLoopForIO); 198 message_loop.reset(new base::MessageLoopForIO);
159 } 199 }
160 200
161 base::RunLoop run_loop; 201 base::RunLoop run_loop;
162 202
163 access_token_.clear(); 203 access_token_.clear();
164 204
165 AccessTokenCallback access_token_callback = 205 AccessTokenCallback access_token_callback =
166 base::Bind(&AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved, 206 base::Bind(&AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved,
167 base::Unretained(this), 207 base::Unretained(this), run_loop.QuitClosure());
168 run_loop.QuitClosure());
169 208
170 // If a unit test has set |test_access_token_fetcher_| then we should use it 209 // 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 210 // 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. 211 // the function which is why we have the dance below.
173 scoped_ptr<AccessTokenFetcher> temporary_access_token_fetcher; 212 scoped_ptr<AccessTokenFetcher> temporary_access_token_fetcher;
174 AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_; 213 AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_;
175 if (!access_token_fetcher) { 214 if (!access_token_fetcher) {
176 temporary_access_token_fetcher.reset(new AccessTokenFetcher()); 215 temporary_access_token_fetcher.reset(new AccessTokenFetcher());
177 access_token_fetcher = temporary_access_token_fetcher.get(); 216 access_token_fetcher = temporary_access_token_fetcher.get();
178 } 217 }
179 218
180 if (!auth_code.empty()) { 219 if (!auth_code.empty()) {
181 // If the user passed in an authcode, then use it to retrieve an 220 // If the user passed in an authcode, then use it to retrieve an
182 // updated access/refresh token. 221 // updated access/refresh token.
183 access_token_fetcher->GetAccessTokenFromAuthCode( 222 access_token_fetcher->GetAccessTokenFromAuthCode(auth_code,
184 auth_code, 223 access_token_callback);
185 access_token_callback);
186 } else { 224 } else {
187 DCHECK(!refresh_token_.empty()); 225 DCHECK(!refresh_token_.empty());
188 226
189 access_token_fetcher->GetAccessTokenFromRefreshToken( 227 access_token_fetcher->GetAccessTokenFromRefreshToken(refresh_token_,
190 refresh_token_, 228 access_token_callback);
191 access_token_callback);
192 } 229 }
193 230
194 run_loop.Run(); 231 run_loop.Run();
195 232
196 // If we were using an auth_code and received a valid refresh token, 233 // 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 234 // 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. 235 // receive a refresh token, then we should let the user know and exit.
199 if (!auth_code.empty()) { 236 if (!auth_code.empty()) {
200 if (!refresh_token_.empty()) { 237 if (!refresh_token_.empty()) {
201 // If a unit test has set |test_refresh_token_store_| then we should use 238 // 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 273
237 done_closure.Run(); 274 done_closure.Run();
238 } 275 }
239 276
240 void AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved( 277 void AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved(
241 base::Closure done_closure, 278 base::Closure done_closure,
242 RemoteHostInfo* remote_host_info, 279 RemoteHostInfo* remote_host_info,
243 const RemoteHostInfo& retrieved_remote_host_info) { 280 const RemoteHostInfo& retrieved_remote_host_info) {
244 DCHECK(remote_host_info); 281 DCHECK(remote_host_info);
245 282
246 if (retrieved_remote_host_info.IsReadyForConnection()) { 283 *remote_host_info = retrieved_remote_host_info;
247 *remote_host_info = retrieved_remote_host_info;
248 }
249 284
250 done_closure.Run(); 285 done_closure.Run();
251 } 286 }
252 287
253 } // namespace test 288 } // namespace test
254 } // namespace remoting 289 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698