OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/api/identity/identity_api.h" | 8 #include "chrome/browser/extensions/api/identity/identity_api.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 ProfileKeyedService* IdentityAPITestFactory(content::BrowserContext* profile) { | 187 ProfileKeyedService* IdentityAPITestFactory(content::BrowserContext* profile) { |
188 return new IdentityAPI(static_cast<Profile*>(profile)); | 188 return new IdentityAPI(static_cast<Profile*>(profile)); |
189 } | 189 } |
190 | 190 |
191 } // namespace | 191 } // namespace |
192 | 192 |
193 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { | 193 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { |
194 public: | 194 public: |
195 MockGetAuthTokenFunction() : login_ui_result_(true), | 195 MockGetAuthTokenFunction() : login_ui_result_(true), |
196 install_ui_result_(false), | 196 scope_ui_result_(true), |
197 login_ui_shown_(false), | 197 login_ui_shown_(false), |
198 install_ui_shown_(false) { | 198 scope_ui_shown_(false) { |
199 } | 199 } |
200 | 200 |
201 void set_login_ui_result(bool result) { | 201 void set_login_ui_result(bool result) { |
202 login_ui_result_ = result; | 202 login_ui_result_ = result; |
203 } | 203 } |
204 | 204 |
205 void set_install_ui_result(bool result) { | 205 void set_scope_ui_failure(GaiaWebAuthFlow::Failure failure) { |
206 install_ui_result_ = result; | 206 scope_ui_result_ = false; |
| 207 scope_ui_failure_ = failure; |
| 208 } |
| 209 |
| 210 void set_scope_ui_oauth_error(const std::string& oauth_error) { |
| 211 scope_ui_result_ = false; |
| 212 scope_ui_failure_ = GaiaWebAuthFlow::OAUTH_ERROR; |
| 213 scope_ui_oauth_error_ = oauth_error; |
207 } | 214 } |
208 | 215 |
209 bool login_ui_shown() const { | 216 bool login_ui_shown() const { |
210 return login_ui_shown_; | 217 return login_ui_shown_; |
211 } | 218 } |
212 | 219 |
213 bool install_ui_shown() const { | 220 bool scope_ui_shown() const { |
214 return install_ui_shown_; | 221 return scope_ui_shown_; |
215 } | 222 } |
216 | 223 |
217 virtual void ShowLoginPopup() OVERRIDE { | 224 virtual void ShowLoginPopup() OVERRIDE { |
218 EXPECT_FALSE(login_ui_shown_); | 225 EXPECT_FALSE(login_ui_shown_); |
219 login_ui_shown_ = true; | 226 login_ui_shown_ = true; |
220 if (login_ui_result_) | 227 if (login_ui_result_) |
221 SigninSuccess("fake_refresh_token"); | 228 SigninSuccess("fake_refresh_token"); |
222 else | 229 else |
223 SigninFailed(); | 230 SigninFailed(); |
224 } | 231 } |
225 | 232 |
226 virtual void ShowOAuthApprovalDialog( | 233 virtual void ShowOAuthApprovalDialog( |
227 const IssueAdviceInfo& issue_advice) OVERRIDE { | 234 const IssueAdviceInfo& issue_advice) OVERRIDE { |
228 install_ui_shown_ = true; | 235 scope_ui_shown_ = true; |
229 // Call InstallUIProceed or InstallUIAbort based on the flag. | 236 |
230 if (install_ui_result_) | 237 if (scope_ui_result_) { |
231 InstallUIProceed(); | 238 OnGaiaFlowCompleted(kAccessToken, "3600"); |
232 else | 239 } else if (scope_ui_failure_ == GaiaWebAuthFlow::SERVICE_AUTH_ERROR) { |
233 InstallUIAbort(true); | 240 GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED); |
| 241 OnGaiaFlowFailure(scope_ui_failure_, error, ""); |
| 242 } else { |
| 243 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 244 OnGaiaFlowFailure(scope_ui_failure_, error, scope_ui_oauth_error_); |
| 245 } |
234 } | 246 } |
235 | 247 |
236 MOCK_CONST_METHOD0(HasLoginToken, bool()); | 248 MOCK_CONST_METHOD0(HasLoginToken, bool()); |
237 MOCK_METHOD1(CreateMintTokenFlow, | 249 MOCK_METHOD1(CreateMintTokenFlow, |
238 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); | 250 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); |
239 | 251 |
240 private: | 252 private: |
241 ~MockGetAuthTokenFunction() {} | 253 ~MockGetAuthTokenFunction() {} |
242 bool login_ui_result_; | 254 bool login_ui_result_; |
243 bool install_ui_result_; | 255 bool scope_ui_result_; |
| 256 GaiaWebAuthFlow::Failure scope_ui_failure_; |
| 257 std::string scope_ui_oauth_error_; |
244 bool login_ui_shown_; | 258 bool login_ui_shown_; |
245 bool install_ui_shown_; | 259 bool scope_ui_shown_; |
246 }; | 260 }; |
247 | 261 |
248 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { | 262 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { |
249 public: | 263 public: |
250 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); | 264 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); |
251 }; | 265 }; |
252 | 266 |
253 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { | 267 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { |
254 protected: | 268 protected: |
255 enum OAuth2Fields { | 269 enum OAuth2Fields { |
(...skipping 27 matching lines...) Expand all Loading... |
283 }; | 297 }; |
284 | 298 |
285 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 299 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
286 NoClientId) { | 300 NoClientId) { |
287 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 301 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
288 func->set_extension(CreateExtension(SCOPES)); | 302 func->set_extension(CreateExtension(SCOPES)); |
289 std::string error = utils::RunFunctionAndReturnError( | 303 std::string error = utils::RunFunctionAndReturnError( |
290 func.get(), "[{}]", browser()); | 304 func.get(), "[{}]", browser()); |
291 EXPECT_EQ(std::string(errors::kInvalidClientId), error); | 305 EXPECT_EQ(std::string(errors::kInvalidClientId), error); |
292 EXPECT_FALSE(func->login_ui_shown()); | 306 EXPECT_FALSE(func->login_ui_shown()); |
293 EXPECT_FALSE(func->install_ui_shown()); | 307 EXPECT_FALSE(func->scope_ui_shown()); |
294 } | 308 } |
295 | 309 |
296 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 310 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
297 NoScopes) { | 311 NoScopes) { |
298 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 312 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
299 func->set_extension(CreateExtension(CLIENT_ID)); | 313 func->set_extension(CreateExtension(CLIENT_ID)); |
300 std::string error = utils::RunFunctionAndReturnError( | 314 std::string error = utils::RunFunctionAndReturnError( |
301 func.get(), "[{}]", browser()); | 315 func.get(), "[{}]", browser()); |
302 EXPECT_EQ(std::string(errors::kInvalidScopes), error); | 316 EXPECT_EQ(std::string(errors::kInvalidScopes), error); |
303 EXPECT_FALSE(func->login_ui_shown()); | 317 EXPECT_FALSE(func->login_ui_shown()); |
304 EXPECT_FALSE(func->install_ui_shown()); | 318 EXPECT_FALSE(func->scope_ui_shown()); |
305 } | 319 } |
306 | 320 |
307 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 321 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
308 NonInteractiveNotSignedIn) { | 322 NonInteractiveNotSignedIn) { |
309 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 323 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
310 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 324 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
311 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 325 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
312 std::string error = utils::RunFunctionAndReturnError( | 326 std::string error = utils::RunFunctionAndReturnError( |
313 func.get(), "[{}]", browser()); | 327 func.get(), "[{}]", browser()); |
314 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 328 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
315 EXPECT_FALSE(func->login_ui_shown()); | 329 EXPECT_FALSE(func->login_ui_shown()); |
316 EXPECT_FALSE(func->install_ui_shown()); | 330 EXPECT_FALSE(func->scope_ui_shown()); |
317 } | 331 } |
318 | 332 |
319 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 333 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
320 NonInteractiveMintFailure) { | 334 NonInteractiveMintFailure) { |
321 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 335 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
322 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 336 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
323 EXPECT_CALL(*func.get(), HasLoginToken()) | 337 EXPECT_CALL(*func.get(), HasLoginToken()) |
324 .WillOnce(Return(true)); | 338 .WillOnce(Return(true)); |
325 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 339 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
326 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 340 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
327 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 341 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
328 std::string error = utils::RunFunctionAndReturnError( | 342 std::string error = utils::RunFunctionAndReturnError( |
329 func.get(), "[{}]", browser()); | 343 func.get(), "[{}]", browser()); |
330 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 344 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
331 EXPECT_FALSE(func->login_ui_shown()); | 345 EXPECT_FALSE(func->login_ui_shown()); |
332 EXPECT_FALSE(func->install_ui_shown()); | 346 EXPECT_FALSE(func->scope_ui_shown()); |
333 } | 347 } |
334 | 348 |
335 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 349 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
336 NonInteractiveMintAdviceSuccess) { | 350 NonInteractiveMintAdviceSuccess) { |
337 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 351 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
338 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 352 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
339 func->set_extension(extension); | 353 func->set_extension(extension); |
340 EXPECT_CALL(*func.get(), HasLoginToken()) | 354 EXPECT_CALL(*func.get(), HasLoginToken()) |
341 .WillOnce(Return(true)); | 355 .WillOnce(Return(true)); |
342 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 356 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
343 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 357 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
344 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 358 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
345 std::string error = utils::RunFunctionAndReturnError( | 359 std::string error = utils::RunFunctionAndReturnError( |
346 func.get(), "[{}]", browser()); | 360 func.get(), "[{}]", browser()); |
347 EXPECT_EQ(std::string(errors::kNoGrant), error); | 361 EXPECT_EQ(std::string(errors::kNoGrant), error); |
348 EXPECT_FALSE(func->login_ui_shown()); | 362 EXPECT_FALSE(func->login_ui_shown()); |
349 EXPECT_FALSE(func->install_ui_shown()); | 363 EXPECT_FALSE(func->scope_ui_shown()); |
350 | 364 |
351 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 365 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
352 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_ADVICE, | 366 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_ADVICE, |
353 id_api()->GetCachedToken(extension->id(), | 367 id_api()->GetCachedToken(extension->id(), |
354 oauth2_info.scopes).status()); | 368 oauth2_info.scopes).status()); |
355 } | 369 } |
356 | 370 |
357 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 371 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
358 NonInteractiveMintBadCredentials) { | 372 NonInteractiveMintBadCredentials) { |
359 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 373 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
360 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 374 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
361 EXPECT_CALL(*func.get(), HasLoginToken()) | 375 EXPECT_CALL(*func.get(), HasLoginToken()) |
362 .WillOnce(Return(true)); | 376 .WillOnce(Return(true)); |
363 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 377 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
364 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 378 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
365 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 379 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
366 std::string error = utils::RunFunctionAndReturnError( | 380 std::string error = utils::RunFunctionAndReturnError( |
367 func.get(), "[{}]", browser()); | 381 func.get(), "[{}]", browser()); |
368 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 382 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
369 EXPECT_FALSE(func->login_ui_shown()); | 383 EXPECT_FALSE(func->login_ui_shown()); |
370 EXPECT_FALSE(func->install_ui_shown()); | 384 EXPECT_FALSE(func->scope_ui_shown()); |
371 } | 385 } |
372 | 386 |
373 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 387 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
374 NonInteractiveSuccess) { | 388 NonInteractiveSuccess) { |
375 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 389 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
376 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 390 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
377 func->set_extension(extension); | 391 func->set_extension(extension); |
378 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 392 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
379 EXPECT_CALL(*func.get(), HasLoginToken()) | 393 EXPECT_CALL(*func.get(), HasLoginToken()) |
380 .WillOnce(Return(true)); | 394 .WillOnce(Return(true)); |
381 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 395 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
382 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 396 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
383 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 397 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
384 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 398 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
385 func.get(), "[{}]", browser())); | 399 func.get(), "[{}]", browser())); |
386 std::string access_token; | 400 std::string access_token; |
387 EXPECT_TRUE(value->GetAsString(&access_token)); | 401 EXPECT_TRUE(value->GetAsString(&access_token)); |
388 EXPECT_EQ(std::string(kAccessToken), access_token); | 402 EXPECT_EQ(std::string(kAccessToken), access_token); |
389 EXPECT_FALSE(func->login_ui_shown()); | 403 EXPECT_FALSE(func->login_ui_shown()); |
390 EXPECT_FALSE(func->install_ui_shown()); | 404 EXPECT_FALSE(func->scope_ui_shown()); |
391 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 405 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
392 id_api()->GetCachedToken(extension->id(), | 406 id_api()->GetCachedToken(extension->id(), |
393 oauth2_info.scopes).status()); | 407 oauth2_info.scopes).status()); |
394 } | 408 } |
395 | 409 |
396 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 410 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
397 InteractiveLoginCanceled) { | 411 InteractiveLoginCanceled) { |
398 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 412 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
399 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 413 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
400 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 414 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
401 func->set_login_ui_result(false); | 415 func->set_login_ui_result(false); |
402 std::string error = utils::RunFunctionAndReturnError( | 416 std::string error = utils::RunFunctionAndReturnError( |
403 func.get(), "[{\"interactive\": true}]", browser()); | 417 func.get(), "[{\"interactive\": true}]", browser()); |
404 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 418 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
405 EXPECT_TRUE(func->login_ui_shown()); | 419 EXPECT_TRUE(func->login_ui_shown()); |
406 EXPECT_FALSE(func->install_ui_shown()); | 420 EXPECT_FALSE(func->scope_ui_shown()); |
407 } | 421 } |
408 | 422 |
409 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 423 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
410 InteractiveMintBadCredentialsLoginCanceled) { | 424 InteractiveMintBadCredentialsLoginCanceled) { |
411 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 425 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
412 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 426 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
413 EXPECT_CALL(*func.get(), HasLoginToken()) | 427 EXPECT_CALL(*func.get(), HasLoginToken()) |
414 .WillOnce(Return(true)); | 428 .WillOnce(Return(true)); |
415 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 429 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
416 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 430 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
417 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 431 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
418 func->set_login_ui_result(false); | 432 func->set_login_ui_result(false); |
419 std::string error = utils::RunFunctionAndReturnError( | 433 std::string error = utils::RunFunctionAndReturnError( |
420 func.get(), "[{\"interactive\": true}]", browser()); | 434 func.get(), "[{\"interactive\": true}]", browser()); |
421 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 435 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
422 EXPECT_TRUE(func->login_ui_shown()); | 436 EXPECT_TRUE(func->login_ui_shown()); |
423 EXPECT_FALSE(func->install_ui_shown()); | 437 EXPECT_FALSE(func->scope_ui_shown()); |
424 } | 438 } |
425 | 439 |
426 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 440 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
427 InteractiveLoginSuccessNoToken) { | 441 InteractiveLoginSuccessNoToken) { |
428 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 442 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
429 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 443 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
430 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 444 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
431 func->set_login_ui_result(false); | 445 func->set_login_ui_result(false); |
432 std::string error = utils::RunFunctionAndReturnError( | 446 std::string error = utils::RunFunctionAndReturnError( |
433 func.get(), "[{\"interactive\": true}]", browser()); | 447 func.get(), "[{\"interactive\": true}]", browser()); |
434 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | 448 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
435 EXPECT_TRUE(func->login_ui_shown()); | 449 EXPECT_TRUE(func->login_ui_shown()); |
436 EXPECT_FALSE(func->install_ui_shown()); | 450 EXPECT_FALSE(func->scope_ui_shown()); |
437 } | 451 } |
438 | 452 |
439 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 453 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
440 InteractiveLoginSuccessMintFailure) { | 454 InteractiveLoginSuccessMintFailure) { |
441 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 455 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
442 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 456 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
443 EXPECT_CALL(*func.get(), HasLoginToken()) | 457 EXPECT_CALL(*func.get(), HasLoginToken()) |
444 .WillOnce(Return(false)); | 458 .WillOnce(Return(false)); |
445 func->set_login_ui_result(true); | 459 func->set_login_ui_result(true); |
446 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 460 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
447 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 461 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
448 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 462 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
449 std::string error = utils::RunFunctionAndReturnError( | 463 std::string error = utils::RunFunctionAndReturnError( |
450 func.get(), "[{\"interactive\": true}]", browser()); | 464 func.get(), "[{\"interactive\": true}]", browser()); |
451 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 465 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
452 EXPECT_TRUE(func->login_ui_shown()); | 466 EXPECT_TRUE(func->login_ui_shown()); |
453 EXPECT_FALSE(func->install_ui_shown()); | 467 EXPECT_FALSE(func->scope_ui_shown()); |
454 } | 468 } |
455 | 469 |
456 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 470 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
457 InteractiveLoginSuccessMintSuccess) { | 471 InteractiveLoginSuccessMintSuccess) { |
458 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 472 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
459 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 473 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
460 EXPECT_CALL(*func.get(), HasLoginToken()) | 474 EXPECT_CALL(*func.get(), HasLoginToken()) |
461 .WillOnce(Return(false)); | 475 .WillOnce(Return(false)); |
462 func->set_login_ui_result(true); | 476 func->set_login_ui_result(true); |
463 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 477 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
464 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 478 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
465 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 479 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
466 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 480 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
467 func.get(), "[{\"interactive\": true}]", browser())); | 481 func.get(), "[{\"interactive\": true}]", browser())); |
468 std::string access_token; | 482 std::string access_token; |
469 EXPECT_TRUE(value->GetAsString(&access_token)); | 483 EXPECT_TRUE(value->GetAsString(&access_token)); |
470 EXPECT_EQ(std::string(kAccessToken), access_token); | 484 EXPECT_EQ(std::string(kAccessToken), access_token); |
471 EXPECT_TRUE(func->login_ui_shown()); | 485 EXPECT_TRUE(func->login_ui_shown()); |
472 EXPECT_FALSE(func->install_ui_shown()); | 486 EXPECT_FALSE(func->scope_ui_shown()); |
473 } | 487 } |
474 | 488 |
475 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 489 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
476 InteractiveLoginSuccessApprovalAborted) { | 490 InteractiveLoginSuccessApprovalAborted) { |
477 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 491 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
478 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 492 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
479 EXPECT_CALL(*func.get(), HasLoginToken()) | 493 EXPECT_CALL(*func.get(), HasLoginToken()) |
480 .WillOnce(Return(false)); | 494 .WillOnce(Return(false)); |
481 func->set_login_ui_result(true); | 495 func->set_login_ui_result(true); |
482 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 496 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
483 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 497 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
484 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 498 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
485 func->set_install_ui_result(false); | 499 func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED); |
486 std::string error = utils::RunFunctionAndReturnError( | 500 std::string error = utils::RunFunctionAndReturnError( |
487 func.get(), "[{\"interactive\": true}]", browser()); | 501 func.get(), "[{\"interactive\": true}]", browser()); |
488 EXPECT_EQ(std::string(errors::kUserRejected), error); | 502 EXPECT_EQ(std::string(errors::kUserRejected), error); |
489 EXPECT_TRUE(func->login_ui_shown()); | 503 EXPECT_TRUE(func->login_ui_shown()); |
490 EXPECT_TRUE(func->install_ui_shown()); | 504 EXPECT_TRUE(func->scope_ui_shown()); |
491 } | 505 } |
492 | 506 |
493 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 507 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
494 InteractiveLoginSuccessApprovalDoneMintFailure) { | 508 InteractiveLoginSuccessApprovalSuccess) { |
| 509 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
495 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 510 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
496 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 511 func->set_extension(extension); |
497 EXPECT_CALL(*func.get(), HasLoginToken()) | 512 EXPECT_CALL(*func.get(), HasLoginToken()) |
498 .WillOnce(Return(false)); | 513 .WillOnce(Return(false)); |
499 func->set_login_ui_result(true); | 514 func->set_login_ui_result(true); |
500 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 515 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
501 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 516 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
502 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
503 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | |
504 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 517 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
505 .WillOnce(Return(flow1)) | 518 .WillOnce(Return(flow)); |
506 .WillOnce(Return(flow2)); | |
507 | 519 |
508 func->set_install_ui_result(true); | |
509 std::string error = utils::RunFunctionAndReturnError( | |
510 func.get(), "[{\"interactive\": true}]", browser()); | |
511 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | |
512 EXPECT_TRUE(func->login_ui_shown()); | |
513 EXPECT_TRUE(func->install_ui_shown()); | |
514 } | |
515 | |
516 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | |
517 InteractiveLoginSuccessApprovalDoneMintSuccess) { | |
518 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | |
519 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | |
520 func->set_extension(extension); | |
521 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | |
522 EXPECT_CALL(*func.get(), HasLoginToken()) | |
523 .WillOnce(Return(false)); | |
524 func->set_login_ui_result(true); | |
525 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | |
526 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | |
527 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
528 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | |
529 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | |
530 .WillOnce(Return(flow1)) | |
531 .WillOnce(Return(flow2)); | |
532 | |
533 func->set_install_ui_result(true); | |
534 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 520 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
535 func.get(), "[{\"interactive\": true}]", browser())); | 521 func.get(), "[{\"interactive\": true}]", browser())); |
536 std::string access_token; | 522 std::string access_token; |
537 EXPECT_TRUE(value->GetAsString(&access_token)); | 523 EXPECT_TRUE(value->GetAsString(&access_token)); |
538 EXPECT_EQ(std::string(kAccessToken), access_token); | 524 EXPECT_EQ(std::string(kAccessToken), access_token); |
539 EXPECT_TRUE(func->login_ui_shown()); | 525 EXPECT_TRUE(func->login_ui_shown()); |
540 EXPECT_TRUE(func->install_ui_shown()); | 526 EXPECT_TRUE(func->scope_ui_shown()); |
541 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | |
542 id_api()->GetCachedToken(extension->id(), | |
543 oauth2_info.scopes).status()); | |
544 } | 527 } |
545 | 528 |
546 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 529 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
547 InteractiveApprovalAborted) { | 530 InteractiveApprovalAborted) { |
548 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 531 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
549 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 532 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
550 EXPECT_CALL(*func.get(), HasLoginToken()) | 533 EXPECT_CALL(*func.get(), HasLoginToken()) |
551 .WillOnce(Return(true)); | 534 .WillOnce(Return(true)); |
552 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 535 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
553 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 536 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
554 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 537 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
555 func->set_install_ui_result(false); | 538 func->set_scope_ui_failure(GaiaWebAuthFlow::WINDOW_CLOSED); |
556 std::string error = utils::RunFunctionAndReturnError( | 539 std::string error = utils::RunFunctionAndReturnError( |
557 func.get(), "[{\"interactive\": true}]", browser()); | 540 func.get(), "[{\"interactive\": true}]", browser()); |
558 EXPECT_EQ(std::string(errors::kUserRejected), error); | 541 EXPECT_EQ(std::string(errors::kUserRejected), error); |
559 EXPECT_FALSE(func->login_ui_shown()); | 542 EXPECT_FALSE(func->login_ui_shown()); |
560 EXPECT_TRUE(func->install_ui_shown()); | 543 EXPECT_TRUE(func->scope_ui_shown()); |
561 } | 544 } |
562 | 545 |
563 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 546 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
564 InteractiveApprovalDoneMintSuccess) { | 547 InteractiveApprovalInvalidRedirect) { |
565 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 548 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
566 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 549 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
567 EXPECT_CALL(*func.get(), HasLoginToken()) | 550 EXPECT_CALL(*func.get(), HasLoginToken()) |
568 .WillOnce(Return(true)); | 551 .WillOnce(Return(true)); |
569 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 552 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
570 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 553 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
571 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 554 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
572 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 555 func->set_scope_ui_failure(GaiaWebAuthFlow::INVALID_REDIRECT); |
| 556 std::string error = utils::RunFunctionAndReturnError( |
| 557 func.get(), "[{\"interactive\": true}]", browser()); |
| 558 EXPECT_EQ(std::string(errors::kInvalidRedirect), error); |
| 559 EXPECT_FALSE(func->login_ui_shown()); |
| 560 EXPECT_TRUE(func->scope_ui_shown()); |
| 561 } |
| 562 |
| 563 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 564 InteractiveApprovalConnectionFailure) { |
| 565 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 566 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 567 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 568 .WillOnce(Return(true)); |
| 569 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 570 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 571 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 572 func->set_scope_ui_failure(GaiaWebAuthFlow::SERVICE_AUTH_ERROR); |
| 573 std::string error = utils::RunFunctionAndReturnError( |
| 574 func.get(), "[{\"interactive\": true}]", browser()); |
| 575 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 576 EXPECT_FALSE(func->login_ui_shown()); |
| 577 EXPECT_TRUE(func->scope_ui_shown()); |
| 578 } |
| 579 |
| 580 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 581 InteractiveApprovalOAuthErrors) { |
| 582 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 583 |
| 584 std::map<std::string, std::string> error_map; |
| 585 error_map.insert(std::make_pair("access_denied", errors::kUserRejected)); |
| 586 error_map.insert(std::make_pair("invalid_scope", errors::kInvalidScopes)); |
| 587 error_map.insert(std::make_pair( |
| 588 "unmapped_error", std::string(errors::kAuthFailure) + "unmapped_error")); |
| 589 |
| 590 for (std::map<std::string, std::string>::const_iterator |
| 591 it = error_map.begin(); |
| 592 it != error_map.end(); |
| 593 ++it) { |
| 594 scoped_refptr<MockGetAuthTokenFunction> func( |
| 595 new MockGetAuthTokenFunction()); |
| 596 func->set_extension(extension); |
| 597 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 598 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 599 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 600 ON_CALL(*func.get(), CreateMintTokenFlow(_)).WillByDefault(Return(flow)); |
| 601 func->set_scope_ui_oauth_error(it->first); |
| 602 std::string error = utils::RunFunctionAndReturnError( |
| 603 func.get(), "[{\"interactive\": true}]", browser()); |
| 604 EXPECT_EQ(it->second, error); |
| 605 EXPECT_FALSE(func->login_ui_shown()); |
| 606 EXPECT_TRUE(func->scope_ui_shown()); |
| 607 } |
| 608 } |
| 609 |
| 610 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 611 InteractiveApprovalSuccess) { |
| 612 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 613 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
| 614 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 615 func->set_extension(extension); |
| 616 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 617 .WillOnce(Return(true)); |
| 618 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 619 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
573 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 620 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
574 .WillOnce(Return(flow1)) | 621 .WillOnce(Return(flow)); |
575 .WillOnce(Return(flow2)); | |
576 | 622 |
577 func->set_install_ui_result(true); | |
578 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 623 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
579 func.get(), "[{\"interactive\": true}]", browser())); | 624 func.get(), "[{\"interactive\": true}]", browser())); |
580 std::string access_token; | 625 std::string access_token; |
581 EXPECT_TRUE(value->GetAsString(&access_token)); | 626 EXPECT_TRUE(value->GetAsString(&access_token)); |
582 EXPECT_EQ(std::string(kAccessToken), access_token); | 627 EXPECT_EQ(std::string(kAccessToken), access_token); |
583 EXPECT_FALSE(func->login_ui_shown()); | 628 EXPECT_FALSE(func->login_ui_shown()); |
584 EXPECT_TRUE(func->install_ui_shown()); | 629 EXPECT_TRUE(func->scope_ui_shown()); |
585 } | |
586 | 630 |
587 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 631 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
588 InteractiveApprovalDoneMintBadCredentials) { | 632 id_api()->GetCachedToken(extension->id(), |
589 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 633 oauth2_info.scopes).status()); |
590 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | |
591 EXPECT_CALL(*func.get(), HasLoginToken()) | |
592 .WillOnce(Return(true)); | |
593 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | |
594 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | |
595 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
596 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | |
597 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | |
598 .WillOnce(Return(flow1)) | |
599 .WillOnce(Return(flow2)); | |
600 | |
601 func->set_install_ui_result(true); | |
602 std::string error = utils::RunFunctionAndReturnError( | |
603 func.get(), "[{\"interactive\": true}]", browser()); | |
604 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | |
605 EXPECT_FALSE(func->login_ui_shown()); | |
606 EXPECT_TRUE(func->install_ui_shown()); | |
607 } | 634 } |
608 | 635 |
609 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { | 636 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { |
610 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 637 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
611 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 638 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
612 func->set_extension(extension); | 639 func->set_extension(extension); |
613 | 640 |
614 // Create a fake request to block the queue. | 641 // Create a fake request to block the queue. |
615 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 642 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
616 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 643 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
(...skipping 21 matching lines...) Expand all Loading... |
638 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 665 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
639 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 666 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
640 | 667 |
641 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 668 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
642 | 669 |
643 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 670 scoped_ptr<base::Value> value(WaitForSingleResult(func)); |
644 std::string access_token; | 671 std::string access_token; |
645 EXPECT_TRUE(value->GetAsString(&access_token)); | 672 EXPECT_TRUE(value->GetAsString(&access_token)); |
646 EXPECT_EQ(std::string(kAccessToken), access_token); | 673 EXPECT_EQ(std::string(kAccessToken), access_token); |
647 EXPECT_FALSE(func->login_ui_shown()); | 674 EXPECT_FALSE(func->login_ui_shown()); |
648 EXPECT_FALSE(func->install_ui_shown()); | 675 EXPECT_FALSE(func->scope_ui_shown()); |
649 } | 676 } |
650 | 677 |
651 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { | 678 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { |
652 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 679 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
653 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 680 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
654 func->set_extension(extension); | 681 func->set_extension(extension); |
655 | 682 |
656 // Create a fake request to block the queue. | 683 // Create a fake request to block the queue. |
657 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 684 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
658 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 685 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
(...skipping 11 matching lines...) Expand all Loading... |
670 | 697 |
671 // The real request will start processing, but wait in the queue behind | 698 // The real request will start processing, but wait in the queue behind |
672 // the blocker. | 699 // the blocker. |
673 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 700 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
674 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 701 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
675 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 702 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
676 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); | 703 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); |
677 RunFunctionAsync(func, "[{\"interactive\": true}]"); | 704 RunFunctionAsync(func, "[{\"interactive\": true}]"); |
678 // Verify that we have fetched the login token and run the first flow. | 705 // Verify that we have fetched the login token and run the first flow. |
679 testing::Mock::VerifyAndClearExpectations(func); | 706 testing::Mock::VerifyAndClearExpectations(func); |
680 EXPECT_FALSE(func->install_ui_shown()); | 707 EXPECT_FALSE(func->scope_ui_shown()); |
681 | 708 |
682 // The UI will be displayed and the second flow will be created | 709 // The UI will be displayed and a token retrieved after the first |
683 // after the first queued request clears. | 710 // queued request clears. |
684 func->set_install_ui_result(true); | |
685 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
686 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | |
687 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow2)); | |
688 | |
689 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 711 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
690 | 712 |
691 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 713 scoped_ptr<base::Value> value(WaitForSingleResult(func)); |
692 std::string access_token; | 714 std::string access_token; |
693 EXPECT_TRUE(value->GetAsString(&access_token)); | 715 EXPECT_TRUE(value->GetAsString(&access_token)); |
694 EXPECT_EQ(std::string(kAccessToken), access_token); | 716 EXPECT_EQ(std::string(kAccessToken), access_token); |
695 EXPECT_FALSE(func->login_ui_shown()); | 717 EXPECT_FALSE(func->login_ui_shown()); |
696 EXPECT_TRUE(func->install_ui_shown()); | 718 EXPECT_TRUE(func->scope_ui_shown()); |
697 } | 719 } |
698 | 720 |
699 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 721 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
700 InteractiveQueuedNoninteractiveFails) { | 722 InteractiveQueuedNoninteractiveFails) { |
701 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 723 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
702 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 724 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
703 func->set_extension(extension); | 725 func->set_extension(extension); |
704 | 726 |
705 // Create a fake request to block the interactive queue. | 727 // Create a fake request to block the interactive queue. |
706 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 728 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
(...skipping 10 matching lines...) Expand all Loading... |
717 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 739 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
718 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 740 queue->RequestStart(type, extension->id(), scopes, &queued_request); |
719 | 741 |
720 // Non-interactive requests fail without hitting GAIA, because a | 742 // Non-interactive requests fail without hitting GAIA, because a |
721 // consent UI is known to be up. | 743 // consent UI is known to be up. |
722 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 744 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
723 std::string error = utils::RunFunctionAndReturnError( | 745 std::string error = utils::RunFunctionAndReturnError( |
724 func.get(), "[{}]", browser()); | 746 func.get(), "[{}]", browser()); |
725 EXPECT_EQ(std::string(errors::kNoGrant), error); | 747 EXPECT_EQ(std::string(errors::kNoGrant), error); |
726 EXPECT_FALSE(func->login_ui_shown()); | 748 EXPECT_FALSE(func->login_ui_shown()); |
727 EXPECT_FALSE(func->install_ui_shown()); | 749 EXPECT_FALSE(func->scope_ui_shown()); |
728 | 750 |
729 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 751 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
730 } | 752 } |
731 | 753 |
732 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 754 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
733 NonInteractiveCacheHit) { | 755 NonInteractiveCacheHit) { |
734 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 756 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
735 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 757 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
736 func->set_extension(extension); | 758 func->set_extension(extension); |
737 | 759 |
738 // pre-populate the cache with a token | 760 // pre-populate the cache with a token |
739 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 761 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
740 IdentityTokenCacheValue token(kAccessToken, | 762 IdentityTokenCacheValue token(kAccessToken, |
741 base::TimeDelta::FromSeconds(3600)); | 763 base::TimeDelta::FromSeconds(3600)); |
742 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 764 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
743 | 765 |
744 // Get a token. Should not require a GAIA request. | 766 // Get a token. Should not require a GAIA request. |
745 EXPECT_CALL(*func.get(), HasLoginToken()) | 767 EXPECT_CALL(*func.get(), HasLoginToken()) |
746 .WillOnce(Return(true)); | 768 .WillOnce(Return(true)); |
747 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 769 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
748 func.get(), "[{}]", browser())); | 770 func.get(), "[{}]", browser())); |
749 std::string access_token; | 771 std::string access_token; |
750 EXPECT_TRUE(value->GetAsString(&access_token)); | 772 EXPECT_TRUE(value->GetAsString(&access_token)); |
751 EXPECT_EQ(std::string(kAccessToken), access_token); | 773 EXPECT_EQ(std::string(kAccessToken), access_token); |
752 EXPECT_FALSE(func->login_ui_shown()); | 774 EXPECT_FALSE(func->login_ui_shown()); |
753 EXPECT_FALSE(func->install_ui_shown()); | 775 EXPECT_FALSE(func->scope_ui_shown()); |
754 } | 776 } |
755 | 777 |
756 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 778 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
757 NonInteractiveIssueAdviceCacheHit) { | 779 NonInteractiveIssueAdviceCacheHit) { |
758 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 780 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
759 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 781 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
760 func->set_extension(extension); | 782 func->set_extension(extension); |
761 | 783 |
762 // pre-populate the cache with advice | 784 // pre-populate the cache with advice |
763 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 785 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
764 IssueAdviceInfo info; | 786 IssueAdviceInfo info; |
765 IdentityTokenCacheValue token(info); | 787 IdentityTokenCacheValue token(info); |
766 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 788 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
767 | 789 |
768 // Should return an error without a GAIA request. | 790 // Should return an error without a GAIA request. |
769 EXPECT_CALL(*func.get(), HasLoginToken()) | 791 EXPECT_CALL(*func.get(), HasLoginToken()) |
770 .WillOnce(Return(true)); | 792 .WillOnce(Return(true)); |
771 std::string error = utils::RunFunctionAndReturnError( | 793 std::string error = utils::RunFunctionAndReturnError( |
772 func.get(), "[{}]", browser()); | 794 func.get(), "[{}]", browser()); |
773 EXPECT_EQ(std::string(errors::kNoGrant), error); | 795 EXPECT_EQ(std::string(errors::kNoGrant), error); |
774 EXPECT_FALSE(func->login_ui_shown()); | 796 EXPECT_FALSE(func->login_ui_shown()); |
775 EXPECT_FALSE(func->install_ui_shown()); | 797 EXPECT_FALSE(func->scope_ui_shown()); |
776 } | 798 } |
777 | 799 |
778 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 800 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
779 InteractiveCacheHit) { | 801 InteractiveCacheHit) { |
780 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 802 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
781 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 803 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
782 func->set_extension(extension); | 804 func->set_extension(extension); |
783 | 805 |
784 // Create a fake request to block the queue. | 806 // Create a fake request to block the queue. |
785 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 807 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
(...skipping 23 matching lines...) Expand all Loading... |
809 // When we wake up the request, it returns the cached token without | 831 // When we wake up the request, it returns the cached token without |
810 // displaying a UI, or hitting GAIA. | 832 // displaying a UI, or hitting GAIA. |
811 | 833 |
812 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 834 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
813 | 835 |
814 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 836 scoped_ptr<base::Value> value(WaitForSingleResult(func)); |
815 std::string access_token; | 837 std::string access_token; |
816 EXPECT_TRUE(value->GetAsString(&access_token)); | 838 EXPECT_TRUE(value->GetAsString(&access_token)); |
817 EXPECT_EQ(std::string(kAccessToken), access_token); | 839 EXPECT_EQ(std::string(kAccessToken), access_token); |
818 EXPECT_FALSE(func->login_ui_shown()); | 840 EXPECT_FALSE(func->login_ui_shown()); |
819 EXPECT_FALSE(func->install_ui_shown()); | 841 EXPECT_FALSE(func->scope_ui_shown()); |
820 } | 842 } |
821 | 843 |
822 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 844 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
823 LoginInvalidatesTokenCache) { | 845 LoginInvalidatesTokenCache) { |
824 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 846 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
825 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 847 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
826 func->set_extension(extension); | 848 func->set_extension(extension); |
827 | 849 |
828 // pre-populate the cache with a token | 850 // pre-populate the cache with a token |
829 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 851 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
830 IdentityTokenCacheValue token(kAccessToken, | 852 IdentityTokenCacheValue token(kAccessToken, |
831 base::TimeDelta::FromSeconds(3600)); | 853 base::TimeDelta::FromSeconds(3600)); |
832 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 854 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
833 | 855 |
834 // Because the user is not signed in, the token will be removed, | 856 // Because the user is not signed in, the token will be removed, |
835 // and we'll hit GAIA for new tokens. | 857 // and we'll hit GAIA for new tokens. |
836 EXPECT_CALL(*func.get(), HasLoginToken()) | 858 EXPECT_CALL(*func.get(), HasLoginToken()) |
837 .WillOnce(Return(false)); | 859 .WillOnce(Return(false)); |
838 func->set_login_ui_result(true); | 860 func->set_login_ui_result(true); |
839 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 861 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
840 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 862 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
841 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
842 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | |
843 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 863 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
844 .WillOnce(Return(flow1)) | 864 .WillOnce(Return(flow)); |
845 .WillOnce(Return(flow2)); | |
846 | 865 |
847 func->set_install_ui_result(true); | |
848 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 866 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
849 func.get(), "[{\"interactive\": true}]", browser())); | 867 func.get(), "[{\"interactive\": true}]", browser())); |
850 std::string access_token; | 868 std::string access_token; |
851 EXPECT_TRUE(value->GetAsString(&access_token)); | 869 EXPECT_TRUE(value->GetAsString(&access_token)); |
852 EXPECT_EQ(std::string(kAccessToken), access_token); | 870 EXPECT_EQ(std::string(kAccessToken), access_token); |
853 EXPECT_TRUE(func->login_ui_shown()); | 871 EXPECT_TRUE(func->login_ui_shown()); |
854 EXPECT_TRUE(func->install_ui_shown()); | 872 EXPECT_TRUE(func->scope_ui_shown()); |
855 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 873 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
856 id_api()->GetCachedToken(extension->id(), | 874 id_api()->GetCachedToken(extension->id(), |
857 oauth2_info.scopes).status()); | 875 oauth2_info.scopes).status()); |
858 } | 876 } |
859 | 877 |
860 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { | 878 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { |
861 protected: | 879 protected: |
862 bool InvalidateDefaultToken() { | 880 bool InvalidateDefaultToken() { |
863 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( | 881 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( |
864 new IdentityRemoveCachedAuthTokenFunction); | 882 new IdentityRemoveCachedAuthTokenFunction); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1060 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
1043 function, args, browser())); | 1061 function, args, browser())); |
1044 | 1062 |
1045 std::string url; | 1063 std::string url; |
1046 EXPECT_TRUE(value->GetAsString(&url)); | 1064 EXPECT_TRUE(value->GetAsString(&url)); |
1047 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1065 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1048 url); | 1066 url); |
1049 } | 1067 } |
1050 | 1068 |
1051 } // namespace extensions | 1069 } // namespace extensions |
OLD | NEW |