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

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

Issue 976233003: Adding the base ChromotingInstance implementation and unittests. This class will be used by the ap… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Sergey'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/access_token_fetcher.h" 5 #include "remoting/test/access_token_fetcher.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 namespace remoting { 49 namespace remoting {
50 namespace test { 50 namespace test {
51 51
52 // Provides base functionality for the AccessTokenFetcher Tests below. The 52 // Provides base functionality for the AccessTokenFetcher Tests below. The
53 // FakeURLFetcherFactory allows us to override the response data and payload for 53 // FakeURLFetcherFactory allows us to override the response data and payload for
54 // specified URLs. We use this to stub out network calls made by the 54 // specified URLs. We use this to stub out network calls made by the
55 // AccessTokenFetcher. This fixture also creates an IO MessageLoop, if 55 // AccessTokenFetcher. This fixture also creates an IO MessageLoop, if
56 // necessary, for use by the AccessTokenFetcher. 56 // necessary, for use by the AccessTokenFetcher.
57 class AccessTokenFetcherTest : public ::testing::Test { 57 class AccessTokenFetcherTest : public ::testing::Test {
58 public: 58 public:
59 AccessTokenFetcherTest() : 59 AccessTokenFetcherTest();
60 url_fetcher_factory_(nullptr) {} 60 ~AccessTokenFetcherTest() override;
61 ~AccessTokenFetcherTest() override {}
62 61
63 void OnAccessTokenRetrieved( 62 void OnAccessTokenRetrieved(base::Closure done_closure,
64 base::Closure done_closure, 63 const std::string& access_token,
65 const std::string& access_token, 64 const std::string& refresh_token);
66 const std::string& refresh_token) {
67 access_token_retrieved_ = access_token;
68 refresh_token_retrieved_ = refresh_token;
69
70 done_closure.Run();
71 }
72 65
73 protected: 66 protected:
74 // Test interface. 67 // Test interface.
75 void SetUp() override { 68 void SetUp() override;
76 if (!base::MessageLoop::current()) {
77 // Create a temporary message loop if the current thread does not already
78 // have one so we can use its task runner to create a request object.
79 message_loop_.reset(new base::MessageLoopForIO);
80 }
81 }
82 69
83 void SetFakeResponse(const GURL& url, 70 void SetFakeResponse(const GURL& url,
84 const std::string& data, 71 const std::string& data,
85 net::HttpStatusCode code, 72 net::HttpStatusCode code,
86 net::URLRequestStatus::Status status) { 73 net::URLRequestStatus::Status status);
87 url_fetcher_factory_.SetFakeResponse(url, data, code, status);
88 }
89 74
90 // Used for result verification 75 // Used for result verification
91 std::string access_token_retrieved_; 76 std::string access_token_retrieved_;
92 std::string refresh_token_retrieved_; 77 std::string refresh_token_retrieved_;
93 78
94 private: 79 private:
95 net::FakeURLFetcherFactory url_fetcher_factory_; 80 net::FakeURLFetcherFactory url_fetcher_factory_;
96 scoped_ptr<base::MessageLoopForIO> message_loop_; 81 scoped_ptr<base::MessageLoopForIO> message_loop_;
97 82
98 DISALLOW_COPY_AND_ASSIGN(AccessTokenFetcherTest); 83 DISALLOW_COPY_AND_ASSIGN(AccessTokenFetcherTest);
99 }; 84 };
100 85
86 AccessTokenFetcherTest::AccessTokenFetcherTest()
87 : url_fetcher_factory_(nullptr) {
88 }
89
90 AccessTokenFetcherTest::~AccessTokenFetcherTest() {
91 }
92
93 void AccessTokenFetcherTest::OnAccessTokenRetrieved(
94 base::Closure done_closure,
95 const std::string& access_token,
96 const std::string& refresh_token) {
97 access_token_retrieved_ = access_token;
98 refresh_token_retrieved_ = refresh_token;
99
100 done_closure.Run();
101 }
102
103 void AccessTokenFetcherTest::SetUp() {
104 if (!base::MessageLoop::current()) {
105 // Create a temporary message loop if the current thread does not already
106 // have one so we can use its task runner to create a request object.
107 message_loop_.reset(new base::MessageLoopForIO);
108 }
109 }
110
111 void AccessTokenFetcherTest::SetFakeResponse(
112 const GURL& url,
113 const std::string& data,
114 net::HttpStatusCode code,
115 net::URLRequestStatus::Status status) {
116 url_fetcher_factory_.SetFakeResponse(url, data, code, status);
117 }
118
101 TEST_F(AccessTokenFetcherTest, ExchangeAuthCodeForAccessToken) { 119 TEST_F(AccessTokenFetcherTest, ExchangeAuthCodeForAccessToken) {
102 SetFakeResponse( 120 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
103 GaiaUrls::GetInstance()->oauth2_token_url(), 121 kAuthCodeExchangeValidResponse, net::HTTP_OK,
104 kAuthCodeExchangeValidResponse, 122 net::URLRequestStatus::SUCCESS);
105 net::HTTP_OK,
106 net::URLRequestStatus::SUCCESS);
107 123
108 SetFakeResponse( 124 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_info_url(),
109 GaiaUrls::GetInstance()->oauth2_token_info_url(), 125 kValidTokenInfoResponse, net::HTTP_OK,
110 kValidTokenInfoResponse, 126 net::URLRequestStatus::SUCCESS);
111 net::HTTP_OK,
112 net::URLRequestStatus::SUCCESS);
113 127
114 base::RunLoop run_loop; 128 base::RunLoop run_loop;
115 AccessTokenCallback access_token_callback = 129 AccessTokenCallback access_token_callback =
116 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 130 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
117 base::Unretained(this), 131 base::Unretained(this), run_loop.QuitClosure());
118 run_loop.QuitClosure());
119 132
120 AccessTokenFetcher access_token_fetcher; 133 AccessTokenFetcher access_token_fetcher;
121 access_token_fetcher.GetAccessTokenFromAuthCode( 134 access_token_fetcher.GetAccessTokenFromAuthCode(kAuthCodeValue,
122 kAuthCodeValue, 135 access_token_callback);
123 access_token_callback);
124 136
125 run_loop.Run(); 137 run_loop.Run();
126 138
127 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0); 139 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0);
128 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0); 140 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0);
129 } 141 }
130 142
131 TEST_F(AccessTokenFetcherTest, ExchangeRefreshTokenForAccessToken) { 143 TEST_F(AccessTokenFetcherTest, ExchangeRefreshTokenForAccessToken) {
132 SetFakeResponse( 144 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
133 GaiaUrls::GetInstance()->oauth2_token_url(), 145 kRefreshTokenExchangeValidResponse, net::HTTP_OK,
134 kRefreshTokenExchangeValidResponse, 146 net::URLRequestStatus::SUCCESS);
135 net::HTTP_OK,
136 net::URLRequestStatus::SUCCESS);
137 147
138 SetFakeResponse( 148 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_info_url(),
139 GaiaUrls::GetInstance()->oauth2_token_info_url(), 149 kValidTokenInfoResponse, net::HTTP_OK,
140 kValidTokenInfoResponse, 150 net::URLRequestStatus::SUCCESS);
141 net::HTTP_OK,
142 net::URLRequestStatus::SUCCESS);
143 151
144 base::RunLoop run_loop; 152 base::RunLoop run_loop;
145 AccessTokenCallback access_token_callback = 153 AccessTokenCallback access_token_callback =
146 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 154 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
147 base::Unretained(this), 155 base::Unretained(this), run_loop.QuitClosure());
148 run_loop.QuitClosure());
149 156
150 AccessTokenFetcher access_token_fetcher; 157 AccessTokenFetcher access_token_fetcher;
151 access_token_fetcher.GetAccessTokenFromRefreshToken( 158 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
152 kRefreshTokenValue, 159 access_token_callback);
153 access_token_callback);
154 160
155 run_loop.Run(); 161 run_loop.Run();
156 162
157 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0); 163 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0);
158 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0); 164 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0);
159 } 165 }
160 166
161 TEST_F(AccessTokenFetcherTest, MultipleAccessTokenCalls) { 167 TEST_F(AccessTokenFetcherTest, MultipleAccessTokenCalls) {
162 SetFakeResponse( 168 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
163 GaiaUrls::GetInstance()->oauth2_token_url(), 169 kAuthCodeExchangeValidResponse, net::HTTP_OK,
164 kAuthCodeExchangeValidResponse, 170 net::URLRequestStatus::SUCCESS);
165 net::HTTP_OK,
166 net::URLRequestStatus::SUCCESS);
167 171
168 SetFakeResponse( 172 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_info_url(),
169 GaiaUrls::GetInstance()->oauth2_token_info_url(), 173 kValidTokenInfoResponse, net::HTTP_OK,
170 kValidTokenInfoResponse, 174 net::URLRequestStatus::SUCCESS);
171 net::HTTP_OK,
172 net::URLRequestStatus::SUCCESS);
173 175
174 scoped_ptr<base::RunLoop> run_loop; 176 scoped_ptr<base::RunLoop> run_loop;
175 run_loop.reset(new base::RunLoop()); 177 run_loop.reset(new base::RunLoop());
176 AccessTokenCallback access_token_callback = 178 AccessTokenCallback access_token_callback =
177 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 179 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
178 base::Unretained(this), 180 base::Unretained(this), run_loop->QuitClosure());
179 run_loop->QuitClosure());
180 181
181 AccessTokenFetcher access_token_fetcher; 182 AccessTokenFetcher access_token_fetcher;
182 access_token_fetcher.GetAccessTokenFromAuthCode( 183 access_token_fetcher.GetAccessTokenFromAuthCode(kAuthCodeValue,
183 kAuthCodeValue, 184 access_token_callback);
184 access_token_callback);
185 185
186 run_loop->Run(); 186 run_loop->Run();
187 187
188 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0); 188 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0);
189 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0); 189 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0);
190 190
191 // Reset our token data for the next iteration. 191 // Reset our token data for the next iteration.
192 access_token_retrieved_.clear(); 192 access_token_retrieved_.clear();
193 refresh_token_retrieved_.clear(); 193 refresh_token_retrieved_.clear();
194 194
195 // Update the response since we will call the refresh token method next. 195 // Update the response since we will call the refresh token method next.
196 SetFakeResponse( 196 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
197 GaiaUrls::GetInstance()->oauth2_token_url(), 197 kRefreshTokenExchangeValidResponse, net::HTTP_OK,
198 kRefreshTokenExchangeValidResponse, 198 net::URLRequestStatus::SUCCESS);
199 net::HTTP_OK,
200 net::URLRequestStatus::SUCCESS);
201 199
202 run_loop.reset(new base::RunLoop()); 200 run_loop.reset(new base::RunLoop());
203 access_token_callback = 201 access_token_callback =
204 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 202 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
205 base::Unretained(this), 203 base::Unretained(this), run_loop->QuitClosure());
206 run_loop->QuitClosure());
207 204
208 access_token_fetcher.GetAccessTokenFromRefreshToken( 205 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
209 kRefreshTokenValue, 206 access_token_callback);
210 access_token_callback);
211 207
212 run_loop->Run(); 208 run_loop->Run();
213 209
214 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0); 210 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0);
215 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0); 211 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0);
216 212
217 run_loop.reset(new base::RunLoop()); 213 run_loop.reset(new base::RunLoop());
218 access_token_callback = 214 access_token_callback =
219 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 215 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
220 base::Unretained(this), 216 base::Unretained(this), run_loop->QuitClosure());
221 run_loop->QuitClosure());
222 217
223 // Reset our token data for the next iteration. 218 // Reset our token data for the next iteration.
224 access_token_retrieved_.clear(); 219 access_token_retrieved_.clear();
225 refresh_token_retrieved_.clear(); 220 refresh_token_retrieved_.clear();
226 221
227 access_token_fetcher.GetAccessTokenFromRefreshToken( 222 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
228 kRefreshTokenValue, 223 access_token_callback);
229 access_token_callback);
230 224
231 run_loop->Run(); 225 run_loop->Run();
232 226
233 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0); 227 EXPECT_EQ(access_token_retrieved_.compare(kAccessTokenValue), 0);
234 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0); 228 EXPECT_EQ(refresh_token_retrieved_.compare(kRefreshTokenValue), 0);
235 } 229 }
236 230
237 TEST_F(AccessTokenFetcherTest, ExchangeAuthCode_Unauthorized_Error) { 231 TEST_F(AccessTokenFetcherTest, ExchangeAuthCode_Unauthorized_Error) {
238 SetFakeResponse( 232 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
239 GaiaUrls::GetInstance()->oauth2_token_url(), 233 kAuthCodeExchangeValidResponse, net::HTTP_UNAUTHORIZED,
240 kAuthCodeExchangeValidResponse, 234 net::URLRequestStatus::FAILED);
241 net::HTTP_UNAUTHORIZED,
242 net::URLRequestStatus::FAILED);
243 235
244 base::RunLoop run_loop; 236 base::RunLoop run_loop;
245 AccessTokenCallback access_token_callback = 237 AccessTokenCallback access_token_callback =
246 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 238 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
247 base::Unretained(this), 239 base::Unretained(this), run_loop.QuitClosure());
248 run_loop.QuitClosure());
249 240
250 AccessTokenFetcher access_token_fetcher; 241 AccessTokenFetcher access_token_fetcher;
251 access_token_fetcher.GetAccessTokenFromAuthCode( 242 access_token_fetcher.GetAccessTokenFromAuthCode(kAuthCodeValue,
252 kAuthCodeValue, 243 access_token_callback);
253 access_token_callback);
254 244
255 run_loop.Run(); 245 run_loop.Run();
256 246
257 // Our callback should have been called with empty strings. 247 // Our callback should have been called with empty strings.
258 EXPECT_TRUE(access_token_retrieved_.empty()); 248 EXPECT_TRUE(access_token_retrieved_.empty());
259 EXPECT_TRUE(refresh_token_retrieved_.empty()); 249 EXPECT_TRUE(refresh_token_retrieved_.empty());
260 } 250 }
261 251
262 TEST_F(AccessTokenFetcherTest, ExchangeRefreshToken_Unauthorized_Error) { 252 TEST_F(AccessTokenFetcherTest, ExchangeRefreshToken_Unauthorized_Error) {
263 SetFakeResponse( 253 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
264 GaiaUrls::GetInstance()->oauth2_token_url(), 254 kRefreshTokenExchangeValidResponse, net::HTTP_UNAUTHORIZED,
265 kRefreshTokenExchangeValidResponse, 255 net::URLRequestStatus::FAILED);
266 net::HTTP_UNAUTHORIZED,
267 net::URLRequestStatus::FAILED);
268 256
269 base::RunLoop run_loop; 257 base::RunLoop run_loop;
270 AccessTokenCallback access_token_callback = 258 AccessTokenCallback access_token_callback =
271 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 259 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
272 base::Unretained(this), 260 base::Unretained(this), run_loop.QuitClosure());
273 run_loop.QuitClosure());
274 261
275 AccessTokenFetcher access_token_fetcher; 262 AccessTokenFetcher access_token_fetcher;
276 access_token_fetcher.GetAccessTokenFromRefreshToken( 263 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
277 kRefreshTokenValue, 264 access_token_callback);
278 access_token_callback);
279 265
280 run_loop.Run(); 266 run_loop.Run();
281 267
282 // Our callback should have been called with empty strings. 268 // Our callback should have been called with empty strings.
283 EXPECT_TRUE(access_token_retrieved_.empty()); 269 EXPECT_TRUE(access_token_retrieved_.empty());
284 EXPECT_TRUE(refresh_token_retrieved_.empty()); 270 EXPECT_TRUE(refresh_token_retrieved_.empty());
285 } 271 }
286 272
287 TEST_F(AccessTokenFetcherTest, ExchangeAuthCode_NetworkError) { 273 TEST_F(AccessTokenFetcherTest, ExchangeAuthCode_NetworkError) {
288 SetFakeResponse( 274 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
289 GaiaUrls::GetInstance()->oauth2_token_url(), 275 kAuthCodeExchangeValidResponse, net::HTTP_NOT_FOUND,
290 kAuthCodeExchangeValidResponse, 276 net::URLRequestStatus::FAILED);
291 net::HTTP_NOT_FOUND,
292 net::URLRequestStatus::FAILED);
293 277
294 base::RunLoop run_loop; 278 base::RunLoop run_loop;
295 AccessTokenCallback access_token_callback = 279 AccessTokenCallback access_token_callback =
296 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 280 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
297 base::Unretained(this), 281 base::Unretained(this), run_loop.QuitClosure());
298 run_loop.QuitClosure());
299 282
300 AccessTokenFetcher access_token_fetcher; 283 AccessTokenFetcher access_token_fetcher;
301 access_token_fetcher.GetAccessTokenFromAuthCode( 284 access_token_fetcher.GetAccessTokenFromAuthCode(kAuthCodeValue,
302 kAuthCodeValue, 285 access_token_callback);
303 access_token_callback);
304 286
305 run_loop.Run(); 287 run_loop.Run();
306 288
307 // Our callback should have been called with empty strings. 289 // Our callback should have been called with empty strings.
308 EXPECT_TRUE(access_token_retrieved_.empty()); 290 EXPECT_TRUE(access_token_retrieved_.empty());
309 EXPECT_TRUE(refresh_token_retrieved_.empty()); 291 EXPECT_TRUE(refresh_token_retrieved_.empty());
310 } 292 }
311 293
312 TEST_F(AccessTokenFetcherTest, ExchangeRefreshToken_NetworkError) { 294 TEST_F(AccessTokenFetcherTest, ExchangeRefreshToken_NetworkError) {
313 SetFakeResponse( 295 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
314 GaiaUrls::GetInstance()->oauth2_token_url(), 296 kRefreshTokenExchangeValidResponse, net::HTTP_NOT_FOUND,
315 kRefreshTokenExchangeValidResponse, 297 net::URLRequestStatus::FAILED);
316 net::HTTP_NOT_FOUND,
317 net::URLRequestStatus::FAILED);
318 298
319 base::RunLoop run_loop; 299 base::RunLoop run_loop;
320 AccessTokenCallback access_token_callback = 300 AccessTokenCallback access_token_callback =
321 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 301 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
322 base::Unretained(this), 302 base::Unretained(this), run_loop.QuitClosure());
323 run_loop.QuitClosure());
324 303
325 AccessTokenFetcher access_token_fetcher; 304 AccessTokenFetcher access_token_fetcher;
326 access_token_fetcher.GetAccessTokenFromRefreshToken( 305 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
327 kRefreshTokenValue, 306 access_token_callback);
328 access_token_callback);
329 307
330 run_loop.Run(); 308 run_loop.Run();
331 309
332 // Our callback should have been called with empty strings. 310 // Our callback should have been called with empty strings.
333 EXPECT_TRUE(access_token_retrieved_.empty()); 311 EXPECT_TRUE(access_token_retrieved_.empty());
334 EXPECT_TRUE(refresh_token_retrieved_.empty()); 312 EXPECT_TRUE(refresh_token_retrieved_.empty());
335 } 313 }
336 314
337 TEST_F(AccessTokenFetcherTest, AuthCode_GetTokenInfoResponse_InvalidToken) { 315 TEST_F(AccessTokenFetcherTest, AuthCode_GetTokenInfoResponse_InvalidToken) {
338 SetFakeResponse( 316 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
339 GaiaUrls::GetInstance()->oauth2_token_url(), 317 kAuthCodeExchangeValidResponse, net::HTTP_OK,
340 kAuthCodeExchangeValidResponse, 318 net::URLRequestStatus::SUCCESS);
341 net::HTTP_OK,
342 net::URLRequestStatus::SUCCESS);
343 319
344 SetFakeResponse( 320 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_info_url(),
345 GaiaUrls::GetInstance()->oauth2_token_info_url(), 321 kInvalidTokenInfoResponse, net::HTTP_OK,
346 kInvalidTokenInfoResponse, 322 net::URLRequestStatus::SUCCESS);
347 net::HTTP_OK,
348 net::URLRequestStatus::SUCCESS);
349 323
350 base::RunLoop run_loop; 324 base::RunLoop run_loop;
351 AccessTokenCallback access_token_callback = 325 AccessTokenCallback access_token_callback =
352 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 326 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
353 base::Unretained(this), 327 base::Unretained(this), run_loop.QuitClosure());
354 run_loop.QuitClosure());
355 328
356 AccessTokenFetcher access_token_fetcher; 329 AccessTokenFetcher access_token_fetcher;
357 access_token_fetcher.GetAccessTokenFromAuthCode( 330 access_token_fetcher.GetAccessTokenFromAuthCode(kAuthCodeValue,
358 kAuthCodeValue, 331 access_token_callback);
359 access_token_callback);
360 332
361 run_loop.Run(); 333 run_loop.Run();
362 334
363 // Our callback should have been called with empty strings. 335 // Our callback should have been called with empty strings.
364 EXPECT_TRUE(access_token_retrieved_.empty()); 336 EXPECT_TRUE(access_token_retrieved_.empty());
365 EXPECT_TRUE(refresh_token_retrieved_.empty()); 337 EXPECT_TRUE(refresh_token_retrieved_.empty());
366 } 338 }
367 339
368 TEST_F(AccessTokenFetcherTest, ExchangeAuthCodeForAccessToken_EmptyToken) { 340 TEST_F(AccessTokenFetcherTest, ExchangeAuthCodeForAccessToken_EmptyToken) {
369 SetFakeResponse( 341 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
370 GaiaUrls::GetInstance()->oauth2_token_url(), 342 kAuthCodeExchangeEmptyResponse, net::HTTP_OK,
371 kAuthCodeExchangeEmptyResponse, 343 net::URLRequestStatus::SUCCESS);
372 net::HTTP_OK,
373 net::URLRequestStatus::SUCCESS);
374 344
375 base::RunLoop run_loop; 345 base::RunLoop run_loop;
376 AccessTokenCallback access_token_callback = 346 AccessTokenCallback access_token_callback =
377 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 347 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
378 base::Unretained(this), 348 base::Unretained(this), run_loop.QuitClosure());
379 run_loop.QuitClosure());
380 349
381 AccessTokenFetcher access_token_fetcher; 350 AccessTokenFetcher access_token_fetcher;
382 access_token_fetcher.GetAccessTokenFromAuthCode( 351 access_token_fetcher.GetAccessTokenFromAuthCode(kAuthCodeValue,
383 kAuthCodeValue, 352 access_token_callback);
384 access_token_callback);
385 353
386 run_loop.Run(); 354 run_loop.Run();
387 355
388 // Our callback should have been called with empty strings. 356 // Our callback should have been called with empty strings.
389 EXPECT_TRUE(access_token_retrieved_.empty()); 357 EXPECT_TRUE(access_token_retrieved_.empty());
390 EXPECT_TRUE(refresh_token_retrieved_.empty()); 358 EXPECT_TRUE(refresh_token_retrieved_.empty());
391 } 359 }
392 360
393 TEST_F(AccessTokenFetcherTest, RefreshToken_GetTokenInfoResponse_InvalidToken) { 361 TEST_F(AccessTokenFetcherTest, RefreshToken_GetTokenInfoResponse_InvalidToken) {
394 SetFakeResponse( 362 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
395 GaiaUrls::GetInstance()->oauth2_token_url(), 363 kRefreshTokenExchangeValidResponse, net::HTTP_OK,
396 kRefreshTokenExchangeValidResponse, 364 net::URLRequestStatus::SUCCESS);
397 net::HTTP_OK,
398 net::URLRequestStatus::SUCCESS);
399 365
400 SetFakeResponse( 366 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_info_url(),
401 GaiaUrls::GetInstance()->oauth2_token_info_url(), 367 kInvalidTokenInfoResponse, net::HTTP_OK,
402 kInvalidTokenInfoResponse, 368 net::URLRequestStatus::SUCCESS);
403 net::HTTP_OK,
404 net::URLRequestStatus::SUCCESS);
405 369
406 base::RunLoop run_loop; 370 base::RunLoop run_loop;
407 AccessTokenCallback access_token_callback = 371 AccessTokenCallback access_token_callback =
408 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 372 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
409 base::Unretained(this), 373 base::Unretained(this), run_loop.QuitClosure());
410 run_loop.QuitClosure());
411 374
412 AccessTokenFetcher access_token_fetcher; 375 AccessTokenFetcher access_token_fetcher;
413 access_token_fetcher.GetAccessTokenFromRefreshToken( 376 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
414 kRefreshTokenValue, 377 access_token_callback);
415 access_token_callback);
416 378
417 run_loop.Run(); 379 run_loop.Run();
418 380
419 // Our callback should have been called with empty strings. 381 // Our callback should have been called with empty strings.
420 EXPECT_TRUE(access_token_retrieved_.empty()); 382 EXPECT_TRUE(access_token_retrieved_.empty());
421 EXPECT_TRUE(refresh_token_retrieved_.empty()); 383 EXPECT_TRUE(refresh_token_retrieved_.empty());
422 } 384 }
423 385
424 TEST_F(AccessTokenFetcherTest, ExchangeRefreshTokenForAccessToken_EmptyToken) { 386 TEST_F(AccessTokenFetcherTest, ExchangeRefreshTokenForAccessToken_EmptyToken) {
425 SetFakeResponse( 387 SetFakeResponse(GaiaUrls::GetInstance()->oauth2_token_url(),
426 GaiaUrls::GetInstance()->oauth2_token_url(), 388 kRefreshTokenExchangeEmptyResponse, net::HTTP_OK,
427 kRefreshTokenExchangeEmptyResponse, 389 net::URLRequestStatus::SUCCESS);
428 net::HTTP_OK,
429 net::URLRequestStatus::SUCCESS);
430 390
431 base::RunLoop run_loop; 391 base::RunLoop run_loop;
432 AccessTokenCallback access_token_callback = 392 AccessTokenCallback access_token_callback =
433 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved, 393 base::Bind(&AccessTokenFetcherTest::OnAccessTokenRetrieved,
434 base::Unretained(this), 394 base::Unretained(this), run_loop.QuitClosure());
435 run_loop.QuitClosure());
436 395
437 AccessTokenFetcher access_token_fetcher; 396 AccessTokenFetcher access_token_fetcher;
438 access_token_fetcher.GetAccessTokenFromRefreshToken( 397 access_token_fetcher.GetAccessTokenFromRefreshToken(kRefreshTokenValue,
439 kRefreshTokenValue, 398 access_token_callback);
440 access_token_callback);
441 399
442 run_loop.Run(); 400 run_loop.Run();
443 401
444 // Our callback should have been called with empty strings. 402 // Our callback should have been called with empty strings.
445 EXPECT_TRUE(access_token_retrieved_.empty()); 403 EXPECT_TRUE(access_token_retrieved_.empty());
446 EXPECT_TRUE(refresh_token_retrieved_.empty()); 404 EXPECT_TRUE(refresh_token_retrieved_.empty());
447 } 405 }
448 406
449 } // namespace test 407 } // namespace test
450 } // namespace remoting 408 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698