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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/api/identity/identity_api.h" | 10 #include "chrome/browser/extensions/api/identity/identity_api.h" |
11 #include "chrome/browser/extensions/component_loader.h" | 11 #include "chrome/browser/extensions/component_loader.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
14 #include "chrome/browser/extensions/extension_function_test_utils.h" | 14 #include "chrome/browser/extensions/extension_function_test_utils.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | 22 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/test_switches.h" | 24 #include "chrome/test/base/test_switches.h" |
23 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
25 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
26 #include "extensions/common/id_util.h" | 28 #include "extensions/common/id_util.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 else | 351 else |
350 ext = LoadExtensionAsComponent(component_manifest_path); | 352 ext = LoadExtensionAsComponent(component_manifest_path); |
351 OAuth2Info& oauth2_info = | 353 OAuth2Info& oauth2_info = |
352 const_cast<OAuth2Info&>(OAuth2Info::GetOAuth2Info(ext)); | 354 const_cast<OAuth2Info&>(OAuth2Info::GetOAuth2Info(ext)); |
353 if ((fields_to_set & CLIENT_ID) != 0) | 355 if ((fields_to_set & CLIENT_ID) != 0) |
354 oauth2_info.client_id = "client1"; | 356 oauth2_info.client_id = "client1"; |
355 if ((fields_to_set & SCOPES) != 0) { | 357 if ((fields_to_set & SCOPES) != 0) { |
356 oauth2_info.scopes.push_back("scope1"); | 358 oauth2_info.scopes.push_back("scope1"); |
357 oauth2_info.scopes.push_back("scope2"); | 359 oauth2_info.scopes.push_back("scope2"); |
358 } | 360 } |
| 361 |
| 362 extension_id_ = ext->id(); |
| 363 oauth_scopes_ = std::set<std::string>(oauth2_info.scopes.begin(), |
| 364 oauth2_info.scopes.end()); |
359 return ext; | 365 return ext; |
360 } | 366 } |
361 | 367 |
362 IdentityAPI* id_api() { | 368 IdentityAPI* id_api() { |
363 return IdentityAPI::GetFactoryInstance()->GetForProfile( | 369 return IdentityAPI::GetFactoryInstance()->GetForProfile( |
364 browser()->profile()); | 370 browser()->profile()); |
365 } | 371 } |
| 372 |
| 373 const std::string GetPrimaryAccountId() { |
| 374 ProfileOAuth2TokenService* token_service = |
| 375 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); |
| 376 return token_service->GetPrimaryAccountId(); |
| 377 } |
| 378 |
| 379 void SetCachedToken(const IdentityTokenCacheValue& token_data) { |
| 380 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); |
| 381 id_api()->SetCachedToken(key, token_data); |
| 382 } |
| 383 |
| 384 const IdentityTokenCacheValue& GetCachedToken() { |
| 385 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); |
| 386 return id_api()->GetCachedToken(key); |
| 387 } |
| 388 |
| 389 void QueueRequestStart(IdentityMintRequestQueue::MintType type, |
| 390 IdentityMintRequestQueue::Request* request) { |
| 391 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); |
| 392 id_api()->mint_queue()->RequestStart(type, key, request); |
| 393 } |
| 394 |
| 395 void QueueRequestComplete(IdentityMintRequestQueue::MintType type, |
| 396 IdentityMintRequestQueue::Request* request) { |
| 397 ExtensionTokenKey key(extension_id_, GetPrimaryAccountId(), oauth_scopes_); |
| 398 id_api()->mint_queue()->RequestComplete(type, key, request); |
| 399 } |
| 400 |
| 401 private: |
| 402 std::string extension_id_; |
| 403 std::set<std::string> oauth_scopes_; |
366 }; | 404 }; |
367 | 405 |
368 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 406 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
369 NoClientId) { | 407 NoClientId) { |
370 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 408 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
371 func->set_extension(CreateExtension(SCOPES)); | 409 func->set_extension(CreateExtension(SCOPES)); |
372 std::string error = utils::RunFunctionAndReturnError( | 410 std::string error = utils::RunFunctionAndReturnError( |
373 func.get(), "[{}]", browser()); | 411 func.get(), "[{}]", browser()); |
374 EXPECT_EQ(std::string(errors::kInvalidClientId), error); | 412 EXPECT_EQ(std::string(errors::kInvalidClientId), error); |
375 EXPECT_FALSE(func->login_ui_shown()); | 413 EXPECT_FALSE(func->login_ui_shown()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 473 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
436 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 474 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
437 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 475 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
438 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 476 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
439 std::string error = utils::RunFunctionAndReturnError( | 477 std::string error = utils::RunFunctionAndReturnError( |
440 func.get(), "[{}]", browser()); | 478 func.get(), "[{}]", browser()); |
441 EXPECT_EQ(std::string(errors::kNoGrant), error); | 479 EXPECT_EQ(std::string(errors::kNoGrant), error); |
442 EXPECT_FALSE(func->login_ui_shown()); | 480 EXPECT_FALSE(func->login_ui_shown()); |
443 EXPECT_FALSE(func->scope_ui_shown()); | 481 EXPECT_FALSE(func->scope_ui_shown()); |
444 | 482 |
445 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | 483 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_ADVICE, |
446 EXPECT_EQ( | 484 GetCachedToken().status()); |
447 IdentityTokenCacheValue::CACHE_STATUS_ADVICE, | |
448 id_api()->GetCachedToken(extension->id(), oauth2_info.scopes).status()); | |
449 } | 485 } |
450 | 486 |
451 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 487 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
452 NonInteractiveMintBadCredentials) { | 488 NonInteractiveMintBadCredentials) { |
453 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 489 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
454 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 490 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
455 EXPECT_CALL(*func.get(), HasLoginToken()) | 491 EXPECT_CALL(*func.get(), HasLoginToken()) |
456 .WillOnce(Return(true)); | 492 .WillOnce(Return(true)); |
457 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 493 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
458 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 494 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
459 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 495 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
460 std::string error = utils::RunFunctionAndReturnError( | 496 std::string error = utils::RunFunctionAndReturnError( |
461 func.get(), "[{}]", browser()); | 497 func.get(), "[{}]", browser()); |
462 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 498 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
463 EXPECT_FALSE(func->login_ui_shown()); | 499 EXPECT_FALSE(func->login_ui_shown()); |
464 EXPECT_FALSE(func->scope_ui_shown()); | 500 EXPECT_FALSE(func->scope_ui_shown()); |
465 } | 501 } |
466 | 502 |
467 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 503 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
468 NonInteractiveSuccess) { | 504 NonInteractiveSuccess) { |
469 #if defined(OS_WIN) && defined(USE_ASH) | 505 #if defined(OS_WIN) && defined(USE_ASH) |
470 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 506 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
471 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 507 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
472 return; | 508 return; |
473 #endif | 509 #endif |
474 | 510 |
475 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 511 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
476 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 512 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
477 func->set_extension(extension.get()); | 513 func->set_extension(extension.get()); |
478 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
479 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 514 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
480 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 515 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
481 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 516 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
482 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 517 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
483 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 518 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
484 func.get(), "[{}]", browser())); | 519 func.get(), "[{}]", browser())); |
485 std::string access_token; | 520 std::string access_token; |
486 EXPECT_TRUE(value->GetAsString(&access_token)); | 521 EXPECT_TRUE(value->GetAsString(&access_token)); |
487 EXPECT_EQ(std::string(kAccessToken), access_token); | 522 EXPECT_EQ(std::string(kAccessToken), access_token); |
488 EXPECT_FALSE(func->login_ui_shown()); | 523 EXPECT_FALSE(func->login_ui_shown()); |
489 EXPECT_FALSE(func->scope_ui_shown()); | 524 EXPECT_FALSE(func->scope_ui_shown()); |
490 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 525 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
491 id_api()->GetCachedToken(extension->id(), | 526 GetCachedToken().status()); |
492 oauth2_info.scopes).status()); | |
493 } | 527 } |
494 | 528 |
495 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 529 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
496 InteractiveLoginCanceled) { | 530 InteractiveLoginCanceled) { |
497 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 531 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
498 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 532 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
499 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | 533 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
500 func->set_login_ui_result(false); | 534 func->set_login_ui_result(false); |
501 std::string error = utils::RunFunctionAndReturnError( | 535 std::string error = utils::RunFunctionAndReturnError( |
502 func.get(), "[{\"interactive\": true}]", browser()); | 536 func.get(), "[{\"interactive\": true}]", browser()); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 func.get(), "[{\"interactive\": true}]", browser()); | 755 func.get(), "[{\"interactive\": true}]", browser()); |
722 EXPECT_EQ(it->second, error); | 756 EXPECT_EQ(it->second, error); |
723 EXPECT_FALSE(func->login_ui_shown()); | 757 EXPECT_FALSE(func->login_ui_shown()); |
724 EXPECT_TRUE(func->scope_ui_shown()); | 758 EXPECT_TRUE(func->scope_ui_shown()); |
725 } | 759 } |
726 } | 760 } |
727 | 761 |
728 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 762 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
729 InteractiveApprovalSuccess) { | 763 InteractiveApprovalSuccess) { |
730 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 764 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
731 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
732 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 765 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
733 func->set_extension(extension.get()); | 766 func->set_extension(extension.get()); |
734 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 767 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
735 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 768 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
736 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 769 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
737 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 770 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
738 .WillOnce(Return(flow)); | 771 .WillOnce(Return(flow)); |
739 | 772 |
740 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 773 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
741 func.get(), "[{\"interactive\": true}]", browser())); | 774 func.get(), "[{\"interactive\": true}]", browser())); |
742 std::string access_token; | 775 std::string access_token; |
743 EXPECT_TRUE(value->GetAsString(&access_token)); | 776 EXPECT_TRUE(value->GetAsString(&access_token)); |
744 EXPECT_EQ(std::string(kAccessToken), access_token); | 777 EXPECT_EQ(std::string(kAccessToken), access_token); |
745 EXPECT_FALSE(func->login_ui_shown()); | 778 EXPECT_FALSE(func->login_ui_shown()); |
746 EXPECT_TRUE(func->scope_ui_shown()); | 779 EXPECT_TRUE(func->scope_ui_shown()); |
747 | 780 |
748 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 781 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
749 id_api()->GetCachedToken(extension->id(), | 782 GetCachedToken().status()); |
750 oauth2_info.scopes).status()); | |
751 } | 783 } |
752 | 784 |
753 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { | 785 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { |
754 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 786 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
755 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 787 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
756 func->set_extension(extension.get()); | 788 func->set_extension(extension.get()); |
757 | 789 |
758 // Create a fake request to block the queue. | 790 // Create a fake request to block the queue. |
759 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
760 std::set<std::string> scopes(oauth2_info.scopes.begin(), | |
761 oauth2_info.scopes.end()); | |
762 IdentityAPI* id_api = | |
763 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | |
764 browser()->profile()); | |
765 IdentityMintRequestQueue* queue = id_api->mint_queue(); | |
766 MockQueuedMintRequest queued_request; | 791 MockQueuedMintRequest queued_request; |
767 IdentityMintRequestQueue::MintType type = | 792 IdentityMintRequestQueue::MintType type = |
768 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE; | 793 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE; |
769 | 794 |
770 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 795 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
771 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 796 QueueRequestStart(type, &queued_request); |
772 | 797 |
773 // The real request will start processing, but wait in the queue behind | 798 // The real request will start processing, but wait in the queue behind |
774 // the blocker. | 799 // the blocker. |
775 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 800 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
776 RunFunctionAsync(func.get(), "[{}]"); | 801 RunFunctionAsync(func.get(), "[{}]"); |
777 // Verify that we have fetched the login token at this point. | 802 // Verify that we have fetched the login token at this point. |
778 testing::Mock::VerifyAndClearExpectations(func.get()); | 803 testing::Mock::VerifyAndClearExpectations(func.get()); |
779 | 804 |
780 // The flow will be created after the first queued request clears. | 805 // The flow will be created after the first queued request clears. |
781 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 806 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
782 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 807 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
783 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 808 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
784 | 809 |
785 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 810 QueueRequestComplete(type, &queued_request); |
786 | 811 |
787 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 812 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); |
788 std::string access_token; | 813 std::string access_token; |
789 EXPECT_TRUE(value->GetAsString(&access_token)); | 814 EXPECT_TRUE(value->GetAsString(&access_token)); |
790 EXPECT_EQ(std::string(kAccessToken), access_token); | 815 EXPECT_EQ(std::string(kAccessToken), access_token); |
791 EXPECT_FALSE(func->login_ui_shown()); | 816 EXPECT_FALSE(func->login_ui_shown()); |
792 EXPECT_FALSE(func->scope_ui_shown()); | 817 EXPECT_FALSE(func->scope_ui_shown()); |
793 } | 818 } |
794 | 819 |
795 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { | 820 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { |
796 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 821 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
797 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 822 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
798 func->set_extension(extension.get()); | 823 func->set_extension(extension.get()); |
799 | 824 |
800 // Create a fake request to block the queue. | 825 // Create a fake request to block the queue. |
801 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
802 std::set<std::string> scopes(oauth2_info.scopes.begin(), | |
803 oauth2_info.scopes.end()); | |
804 IdentityAPI* id_api = | |
805 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | |
806 browser()->profile()); | |
807 IdentityMintRequestQueue* queue = id_api->mint_queue(); | |
808 MockQueuedMintRequest queued_request; | 826 MockQueuedMintRequest queued_request; |
809 IdentityMintRequestQueue::MintType type = | 827 IdentityMintRequestQueue::MintType type = |
810 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; | 828 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; |
811 | 829 |
812 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 830 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
813 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 831 QueueRequestStart(type, &queued_request); |
814 | 832 |
815 // The real request will start processing, but wait in the queue behind | 833 // The real request will start processing, but wait in the queue behind |
816 // the blocker. | 834 // the blocker. |
817 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 835 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
818 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 836 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
819 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 837 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
820 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); | 838 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); |
821 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); | 839 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); |
822 // Verify that we have fetched the login token and run the first flow. | 840 // Verify that we have fetched the login token and run the first flow. |
823 testing::Mock::VerifyAndClearExpectations(func.get()); | 841 testing::Mock::VerifyAndClearExpectations(func.get()); |
824 EXPECT_FALSE(func->scope_ui_shown()); | 842 EXPECT_FALSE(func->scope_ui_shown()); |
825 | 843 |
826 // The UI will be displayed and a token retrieved after the first | 844 // The UI will be displayed and a token retrieved after the first |
827 // queued request clears. | 845 // queued request clears. |
828 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 846 QueueRequestComplete(type, &queued_request); |
829 | 847 |
830 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 848 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); |
831 std::string access_token; | 849 std::string access_token; |
832 EXPECT_TRUE(value->GetAsString(&access_token)); | 850 EXPECT_TRUE(value->GetAsString(&access_token)); |
833 EXPECT_EQ(std::string(kAccessToken), access_token); | 851 EXPECT_EQ(std::string(kAccessToken), access_token); |
834 EXPECT_FALSE(func->login_ui_shown()); | 852 EXPECT_FALSE(func->login_ui_shown()); |
835 EXPECT_TRUE(func->scope_ui_shown()); | 853 EXPECT_TRUE(func->scope_ui_shown()); |
836 } | 854 } |
837 | 855 |
838 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 856 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
839 InteractiveQueuedNoninteractiveFails) { | 857 InteractiveQueuedNoninteractiveFails) { |
840 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 858 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
841 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 859 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
842 func->set_extension(extension.get()); | 860 func->set_extension(extension.get()); |
843 | 861 |
844 // Create a fake request to block the interactive queue. | 862 // Create a fake request to block the interactive queue. |
845 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
846 std::set<std::string> scopes(oauth2_info.scopes.begin(), | |
847 oauth2_info.scopes.end()); | |
848 IdentityAPI* id_api = | |
849 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | |
850 browser()->profile()); | |
851 IdentityMintRequestQueue* queue = id_api->mint_queue(); | |
852 MockQueuedMintRequest queued_request; | 863 MockQueuedMintRequest queued_request; |
853 IdentityMintRequestQueue::MintType type = | 864 IdentityMintRequestQueue::MintType type = |
854 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; | 865 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; |
855 | 866 |
856 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 867 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
857 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 868 QueueRequestStart(type, &queued_request); |
858 | 869 |
859 // Non-interactive requests fail without hitting GAIA, because a | 870 // Non-interactive requests fail without hitting GAIA, because a |
860 // consent UI is known to be up. | 871 // consent UI is known to be up. |
861 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 872 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
862 std::string error = utils::RunFunctionAndReturnError( | 873 std::string error = utils::RunFunctionAndReturnError( |
863 func.get(), "[{}]", browser()); | 874 func.get(), "[{}]", browser()); |
864 EXPECT_EQ(std::string(errors::kNoGrant), error); | 875 EXPECT_EQ(std::string(errors::kNoGrant), error); |
865 EXPECT_FALSE(func->login_ui_shown()); | 876 EXPECT_FALSE(func->login_ui_shown()); |
866 EXPECT_FALSE(func->scope_ui_shown()); | 877 EXPECT_FALSE(func->scope_ui_shown()); |
867 | 878 |
868 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 879 QueueRequestComplete(type, &queued_request); |
869 } | 880 } |
870 | 881 |
871 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 882 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
872 NonInteractiveCacheHit) { | 883 NonInteractiveCacheHit) { |
873 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 884 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
874 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 885 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
875 func->set_extension(extension.get()); | 886 func->set_extension(extension.get()); |
876 | 887 |
877 // pre-populate the cache with a token | 888 // pre-populate the cache with a token |
878 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
879 IdentityTokenCacheValue token(kAccessToken, | 889 IdentityTokenCacheValue token(kAccessToken, |
880 base::TimeDelta::FromSeconds(3600)); | 890 base::TimeDelta::FromSeconds(3600)); |
881 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 891 SetCachedToken(token); |
882 | 892 |
883 // Get a token. Should not require a GAIA request. | 893 // Get a token. Should not require a GAIA request. |
884 EXPECT_CALL(*func.get(), HasLoginToken()) | 894 EXPECT_CALL(*func.get(), HasLoginToken()) |
885 .WillOnce(Return(true)); | 895 .WillOnce(Return(true)); |
886 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 896 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
887 func.get(), "[{}]", browser())); | 897 func.get(), "[{}]", browser())); |
888 std::string access_token; | 898 std::string access_token; |
889 EXPECT_TRUE(value->GetAsString(&access_token)); | 899 EXPECT_TRUE(value->GetAsString(&access_token)); |
890 EXPECT_EQ(std::string(kAccessToken), access_token); | 900 EXPECT_EQ(std::string(kAccessToken), access_token); |
891 EXPECT_FALSE(func->login_ui_shown()); | 901 EXPECT_FALSE(func->login_ui_shown()); |
892 EXPECT_FALSE(func->scope_ui_shown()); | 902 EXPECT_FALSE(func->scope_ui_shown()); |
893 } | 903 } |
894 | 904 |
895 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 905 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
896 NonInteractiveIssueAdviceCacheHit) { | 906 NonInteractiveIssueAdviceCacheHit) { |
897 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 907 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
898 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 908 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
899 func->set_extension(extension.get()); | 909 func->set_extension(extension.get()); |
900 | 910 |
901 // pre-populate the cache with advice | 911 // pre-populate the cache with advice |
902 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
903 IssueAdviceInfo info; | 912 IssueAdviceInfo info; |
904 IdentityTokenCacheValue token(info); | 913 IdentityTokenCacheValue token(info); |
905 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 914 SetCachedToken(token); |
906 | 915 |
907 // Should return an error without a GAIA request. | 916 // Should return an error without a GAIA request. |
908 EXPECT_CALL(*func.get(), HasLoginToken()) | 917 EXPECT_CALL(*func.get(), HasLoginToken()) |
909 .WillOnce(Return(true)); | 918 .WillOnce(Return(true)); |
910 std::string error = utils::RunFunctionAndReturnError( | 919 std::string error = utils::RunFunctionAndReturnError( |
911 func.get(), "[{}]", browser()); | 920 func.get(), "[{}]", browser()); |
912 EXPECT_EQ(std::string(errors::kNoGrant), error); | 921 EXPECT_EQ(std::string(errors::kNoGrant), error); |
913 EXPECT_FALSE(func->login_ui_shown()); | 922 EXPECT_FALSE(func->login_ui_shown()); |
914 EXPECT_FALSE(func->scope_ui_shown()); | 923 EXPECT_FALSE(func->scope_ui_shown()); |
915 } | 924 } |
916 | 925 |
917 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 926 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
918 InteractiveCacheHit) { | 927 InteractiveCacheHit) { |
919 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 928 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
920 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 929 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
921 func->set_extension(extension.get()); | 930 func->set_extension(extension.get()); |
922 | 931 |
923 // Create a fake request to block the queue. | 932 // Create a fake request to block the queue. |
924 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
925 std::set<std::string> scopes(oauth2_info.scopes.begin(), | |
926 oauth2_info.scopes.end()); | |
927 IdentityMintRequestQueue* queue = id_api()->mint_queue(); | |
928 MockQueuedMintRequest queued_request; | 933 MockQueuedMintRequest queued_request; |
929 IdentityMintRequestQueue::MintType type = | 934 IdentityMintRequestQueue::MintType type = |
930 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; | 935 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; |
931 | 936 |
932 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 937 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
933 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 938 QueueRequestStart(type, &queued_request); |
934 | 939 |
935 // The real request will start processing, but wait in the queue behind | 940 // The real request will start processing, but wait in the queue behind |
936 // the blocker. | 941 // the blocker. |
937 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 942 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
938 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 943 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
939 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 944 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
940 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 945 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
941 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); | 946 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); |
942 | 947 |
943 // Populate the cache with a token while the request is blocked. | 948 // Populate the cache with a token while the request is blocked. |
944 IdentityTokenCacheValue token(kAccessToken, | 949 IdentityTokenCacheValue token(kAccessToken, |
945 base::TimeDelta::FromSeconds(3600)); | 950 base::TimeDelta::FromSeconds(3600)); |
946 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 951 SetCachedToken(token); |
947 | 952 |
948 // When we wake up the request, it returns the cached token without | 953 // When we wake up the request, it returns the cached token without |
949 // displaying a UI, or hitting GAIA. | 954 // displaying a UI, or hitting GAIA. |
950 | 955 |
951 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 956 QueueRequestComplete(type, &queued_request); |
952 | 957 |
953 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 958 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); |
954 std::string access_token; | 959 std::string access_token; |
955 EXPECT_TRUE(value->GetAsString(&access_token)); | 960 EXPECT_TRUE(value->GetAsString(&access_token)); |
956 EXPECT_EQ(std::string(kAccessToken), access_token); | 961 EXPECT_EQ(std::string(kAccessToken), access_token); |
957 EXPECT_FALSE(func->login_ui_shown()); | 962 EXPECT_FALSE(func->login_ui_shown()); |
958 EXPECT_FALSE(func->scope_ui_shown()); | 963 EXPECT_FALSE(func->scope_ui_shown()); |
959 } | 964 } |
960 | 965 |
961 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 966 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
962 LoginInvalidatesTokenCache) { | 967 LoginInvalidatesTokenCache) { |
963 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 968 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
964 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 969 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
965 func->set_extension(extension.get()); | 970 func->set_extension(extension.get()); |
966 | 971 |
967 // pre-populate the cache with a token | 972 // pre-populate the cache with a token |
968 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | |
969 IdentityTokenCacheValue token(kAccessToken, | 973 IdentityTokenCacheValue token(kAccessToken, |
970 base::TimeDelta::FromSeconds(3600)); | 974 base::TimeDelta::FromSeconds(3600)); |
971 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 975 SetCachedToken(token); |
972 | 976 |
973 // Because the user is not signed in, the token will be removed, | 977 // Because the user is not signed in, the token will be removed, |
974 // and we'll hit GAIA for new tokens. | 978 // and we'll hit GAIA for new tokens. |
975 EXPECT_CALL(*func.get(), HasLoginToken()) | 979 EXPECT_CALL(*func.get(), HasLoginToken()) |
976 .WillOnce(Return(false)); | 980 .WillOnce(Return(false)); |
977 func->set_login_ui_result(true); | 981 func->set_login_ui_result(true); |
978 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 982 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
979 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 983 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
980 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 984 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
981 .WillOnce(Return(flow)); | 985 .WillOnce(Return(flow)); |
982 | 986 |
983 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 987 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
984 func.get(), "[{\"interactive\": true}]", browser())); | 988 func.get(), "[{\"interactive\": true}]", browser())); |
985 std::string access_token; | 989 std::string access_token; |
986 EXPECT_TRUE(value->GetAsString(&access_token)); | 990 EXPECT_TRUE(value->GetAsString(&access_token)); |
987 EXPECT_EQ(std::string(kAccessToken), access_token); | 991 EXPECT_EQ(std::string(kAccessToken), access_token); |
988 EXPECT_TRUE(func->login_ui_shown()); | 992 EXPECT_TRUE(func->login_ui_shown()); |
989 EXPECT_TRUE(func->scope_ui_shown()); | 993 EXPECT_TRUE(func->scope_ui_shown()); |
990 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 994 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
991 id_api()->GetCachedToken(extension->id(), | 995 GetCachedToken().status()); |
992 oauth2_info.scopes).status()); | |
993 } | 996 } |
994 | 997 |
995 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ComponentWithChromeClientId) { | 998 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ComponentWithChromeClientId) { |
996 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 999 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
997 scoped_refptr<const Extension> extension( | 1000 scoped_refptr<const Extension> extension( |
998 CreateExtension(SCOPES | AS_COMPONENT)); | 1001 CreateExtension(SCOPES | AS_COMPONENT)); |
999 func->set_extension(extension.get()); | 1002 func->set_extension(extension.get()); |
1000 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); | 1003 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
1001 EXPECT_TRUE(oauth2_info.client_id.empty()); | 1004 EXPECT_TRUE(oauth2_info.client_id.empty()); |
1002 EXPECT_FALSE(func->GetOAuth2ClientId().empty()); | 1005 EXPECT_FALSE(func->GetOAuth2ClientId().empty()); |
(...skipping 20 matching lines...) Expand all Loading... |
1023 browser(), | 1026 browser(), |
1024 extension_function_test_utils::NONE); | 1027 extension_function_test_utils::NONE); |
1025 } | 1028 } |
1026 | 1029 |
1027 IdentityAPI* id_api() { | 1030 IdentityAPI* id_api() { |
1028 return IdentityAPI::GetFactoryInstance()->GetForProfile( | 1031 return IdentityAPI::GetFactoryInstance()->GetForProfile( |
1029 browser()->profile()); | 1032 browser()->profile()); |
1030 } | 1033 } |
1031 | 1034 |
1032 void SetCachedToken(IdentityTokenCacheValue& token_data) { | 1035 void SetCachedToken(IdentityTokenCacheValue& token_data) { |
1033 id_api()->SetCachedToken(extensions::id_util::GenerateId(kExtensionId), | 1036 ExtensionTokenKey key(extensions::id_util::GenerateId(kExtensionId), |
1034 std::vector<std::string>(), token_data); | 1037 "test@example.com", |
| 1038 std::set<std::string>()); |
| 1039 id_api()->SetCachedToken(key, token_data); |
1035 } | 1040 } |
1036 | 1041 |
1037 const IdentityTokenCacheValue& GetCachedToken() { | 1042 const IdentityTokenCacheValue& GetCachedToken() { |
1038 return id_api()->GetCachedToken( | 1043 return id_api()->GetCachedToken( |
1039 extensions::id_util::GenerateId(kExtensionId), | 1044 ExtensionTokenKey(extensions::id_util::GenerateId(kExtensionId), |
1040 std::vector<std::string>()); | 1045 "test@example.com", |
| 1046 std::set<std::string>())); |
1041 } | 1047 } |
1042 }; | 1048 }; |
1043 | 1049 |
1044 IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, NotFound) { | 1050 IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, NotFound) { |
1045 EXPECT_TRUE(InvalidateDefaultToken()); | 1051 EXPECT_TRUE(InvalidateDefaultToken()); |
1046 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND, | 1052 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND, |
1047 GetCachedToken().status()); | 1053 GetCachedToken().status()); |
1048 } | 1054 } |
1049 | 1055 |
1050 IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, Advice) { | 1056 IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, Advice) { |
(...skipping 12 matching lines...) Expand all Loading... |
1063 EXPECT_TRUE(InvalidateDefaultToken()); | 1069 EXPECT_TRUE(InvalidateDefaultToken()); |
1064 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1070 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
1065 GetCachedToken().status()); | 1071 GetCachedToken().status()); |
1066 EXPECT_EQ("non_matching_token", GetCachedToken().token()); | 1072 EXPECT_EQ("non_matching_token", GetCachedToken().token()); |
1067 } | 1073 } |
1068 | 1074 |
1069 IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, MatchingToken) { | 1075 IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, MatchingToken) { |
1070 IdentityTokenCacheValue token(kAccessToken, | 1076 IdentityTokenCacheValue token(kAccessToken, |
1071 base::TimeDelta::FromSeconds(3600)); | 1077 base::TimeDelta::FromSeconds(3600)); |
1072 SetCachedToken(token); | 1078 SetCachedToken(token); |
| 1079 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1080 GetCachedToken().status()); |
1073 EXPECT_TRUE(InvalidateDefaultToken()); | 1081 EXPECT_TRUE(InvalidateDefaultToken()); |
1074 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND, | 1082 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND, |
1075 GetCachedToken().status()); | 1083 GetCachedToken().status()); |
1076 } | 1084 } |
1077 | 1085 |
1078 class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { | 1086 class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { |
1079 public: | 1087 public: |
1080 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1088 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
1081 // Reduce performance test variance by disabling background networking. | 1089 // Reduce performance test variance by disabling background networking. |
1082 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); | 1090 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1244 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1237 url); | 1245 url); |
1238 } | 1246 } |
1239 | 1247 |
1240 } // namespace extensions | 1248 } // namespace extensions |
1241 | 1249 |
1242 // Tests the chrome.identity API implemented by custom JS bindings . | 1250 // Tests the chrome.identity API implemented by custom JS bindings . |
1243 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1251 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
1244 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1252 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
1245 } | 1253 } |
OLD | NEW |