| 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/component_loader.h" | 9 #include "chrome/browser/extensions/component_loader.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 func.get(), "[{}]", browser()); | 376 func.get(), "[{}]", browser()); |
| 377 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 377 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 378 EXPECT_FALSE(func->login_ui_shown()); | 378 EXPECT_FALSE(func->login_ui_shown()); |
| 379 EXPECT_FALSE(func->scope_ui_shown()); | 379 EXPECT_FALSE(func->scope_ui_shown()); |
| 380 } | 380 } |
| 381 | 381 |
| 382 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 382 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 383 NonInteractiveMintAdviceSuccess) { | 383 NonInteractiveMintAdviceSuccess) { |
| 384 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 384 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 385 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 385 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 386 func->set_extension(extension); | 386 func->set_extension(extension.get()); |
| 387 EXPECT_CALL(*func.get(), HasLoginToken()) | 387 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 388 .WillOnce(Return(true)); | |
| 389 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 388 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 390 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 389 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 391 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 390 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 392 std::string error = utils::RunFunctionAndReturnError( | 391 std::string error = utils::RunFunctionAndReturnError( |
| 393 func.get(), "[{}]", browser()); | 392 func.get(), "[{}]", browser()); |
| 394 EXPECT_EQ(std::string(errors::kNoGrant), error); | 393 EXPECT_EQ(std::string(errors::kNoGrant), error); |
| 395 EXPECT_FALSE(func->login_ui_shown()); | 394 EXPECT_FALSE(func->login_ui_shown()); |
| 396 EXPECT_FALSE(func->scope_ui_shown()); | 395 EXPECT_FALSE(func->scope_ui_shown()); |
| 397 | 396 |
| 398 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 397 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 399 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_ADVICE, | 398 EXPECT_EQ( |
| 400 id_api()->GetCachedToken(extension->id(), | 399 IdentityTokenCacheValue::CACHE_STATUS_ADVICE, |
| 401 oauth2_info.scopes).status()); | 400 id_api()->GetCachedToken(extension->id(), oauth2_info.scopes).status()); |
| 402 } | 401 } |
| 403 | 402 |
| 404 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 403 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 405 NonInteractiveMintBadCredentials) { | 404 NonInteractiveMintBadCredentials) { |
| 406 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 405 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 407 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 406 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 408 EXPECT_CALL(*func.get(), HasLoginToken()) | 407 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 409 .WillOnce(Return(true)); | 408 .WillOnce(Return(true)); |
| 410 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 409 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 411 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 410 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
| 412 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 411 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 413 std::string error = utils::RunFunctionAndReturnError( | 412 std::string error = utils::RunFunctionAndReturnError( |
| 414 func.get(), "[{}]", browser()); | 413 func.get(), "[{}]", browser()); |
| 415 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 414 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 416 EXPECT_FALSE(func->login_ui_shown()); | 415 EXPECT_FALSE(func->login_ui_shown()); |
| 417 EXPECT_FALSE(func->scope_ui_shown()); | 416 EXPECT_FALSE(func->scope_ui_shown()); |
| 418 } | 417 } |
| 419 | 418 |
| 420 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 419 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 421 NonInteractiveSuccess) { | 420 NonInteractiveSuccess) { |
| 422 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 421 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 423 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 422 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 424 func->set_extension(extension); | 423 func->set_extension(extension.get()); |
| 425 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 424 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 426 EXPECT_CALL(*func.get(), HasLoginToken()) | 425 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 427 .WillOnce(Return(true)); | |
| 428 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 426 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 429 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 427 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
| 430 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 428 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 431 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 429 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 432 func.get(), "[{}]", browser())); | 430 func.get(), "[{}]", browser())); |
| 433 std::string access_token; | 431 std::string access_token; |
| 434 EXPECT_TRUE(value->GetAsString(&access_token)); | 432 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 435 EXPECT_EQ(std::string(kAccessToken), access_token); | 433 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 436 EXPECT_FALSE(func->login_ui_shown()); | 434 EXPECT_FALSE(func->login_ui_shown()); |
| 437 EXPECT_FALSE(func->scope_ui_shown()); | 435 EXPECT_FALSE(func->scope_ui_shown()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 func.get(), "[{\"interactive\": true}]", browser()); | 532 func.get(), "[{\"interactive\": true}]", browser()); |
| 535 EXPECT_EQ(std::string(errors::kUserRejected), error); | 533 EXPECT_EQ(std::string(errors::kUserRejected), error); |
| 536 EXPECT_TRUE(func->login_ui_shown()); | 534 EXPECT_TRUE(func->login_ui_shown()); |
| 537 EXPECT_TRUE(func->scope_ui_shown()); | 535 EXPECT_TRUE(func->scope_ui_shown()); |
| 538 } | 536 } |
| 539 | 537 |
| 540 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 538 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 541 InteractiveLoginSuccessApprovalSuccess) { | 539 InteractiveLoginSuccessApprovalSuccess) { |
| 542 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 540 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 543 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 541 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 544 func->set_extension(extension); | 542 func->set_extension(extension.get()); |
| 545 EXPECT_CALL(*func.get(), HasLoginToken()) | 543 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); |
| 546 .WillOnce(Return(false)); | |
| 547 func->set_login_ui_result(true); | 544 func->set_login_ui_result(true); |
| 548 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 545 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 549 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 546 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 550 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 547 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
| 551 .WillOnce(Return(flow)); | 548 .WillOnce(Return(flow)); |
| 552 | 549 |
| 553 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 550 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 554 func.get(), "[{\"interactive\": true}]", browser())); | 551 func.get(), "[{\"interactive\": true}]", browser())); |
| 555 std::string access_token; | 552 std::string access_token; |
| 556 EXPECT_TRUE(value->GetAsString(&access_token)); | 553 EXPECT_TRUE(value->GetAsString(&access_token)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 error_map.insert(std::make_pair("invalid_scope", errors::kInvalidScopes)); | 633 error_map.insert(std::make_pair("invalid_scope", errors::kInvalidScopes)); |
| 637 error_map.insert(std::make_pair( | 634 error_map.insert(std::make_pair( |
| 638 "unmapped_error", std::string(errors::kAuthFailure) + "unmapped_error")); | 635 "unmapped_error", std::string(errors::kAuthFailure) + "unmapped_error")); |
| 639 | 636 |
| 640 for (std::map<std::string, std::string>::const_iterator | 637 for (std::map<std::string, std::string>::const_iterator |
| 641 it = error_map.begin(); | 638 it = error_map.begin(); |
| 642 it != error_map.end(); | 639 it != error_map.end(); |
| 643 ++it) { | 640 ++it) { |
| 644 scoped_refptr<MockGetAuthTokenFunction> func( | 641 scoped_refptr<MockGetAuthTokenFunction> func( |
| 645 new MockGetAuthTokenFunction()); | 642 new MockGetAuthTokenFunction()); |
| 646 func->set_extension(extension); | 643 func->set_extension(extension.get()); |
| 647 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 644 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 648 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 645 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 649 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 646 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 650 ON_CALL(*func.get(), CreateMintTokenFlow(_)).WillByDefault(Return(flow)); | 647 ON_CALL(*func.get(), CreateMintTokenFlow(_)).WillByDefault(Return(flow)); |
| 651 func->set_scope_ui_oauth_error(it->first); | 648 func->set_scope_ui_oauth_error(it->first); |
| 652 std::string error = utils::RunFunctionAndReturnError( | 649 std::string error = utils::RunFunctionAndReturnError( |
| 653 func.get(), "[{\"interactive\": true}]", browser()); | 650 func.get(), "[{\"interactive\": true}]", browser()); |
| 654 EXPECT_EQ(it->second, error); | 651 EXPECT_EQ(it->second, error); |
| 655 EXPECT_FALSE(func->login_ui_shown()); | 652 EXPECT_FALSE(func->login_ui_shown()); |
| 656 EXPECT_TRUE(func->scope_ui_shown()); | 653 EXPECT_TRUE(func->scope_ui_shown()); |
| 657 } | 654 } |
| 658 } | 655 } |
| 659 | 656 |
| 660 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 657 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 661 InteractiveApprovalSuccess) { | 658 InteractiveApprovalSuccess) { |
| 662 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 659 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 663 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 660 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 664 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 661 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 665 func->set_extension(extension); | 662 func->set_extension(extension.get()); |
| 666 EXPECT_CALL(*func.get(), HasLoginToken()) | 663 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 667 .WillOnce(Return(true)); | |
| 668 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 664 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 669 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 665 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 670 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 666 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
| 671 .WillOnce(Return(flow)); | 667 .WillOnce(Return(flow)); |
| 672 | 668 |
| 673 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 669 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 674 func.get(), "[{\"interactive\": true}]", browser())); | 670 func.get(), "[{\"interactive\": true}]", browser())); |
| 675 std::string access_token; | 671 std::string access_token; |
| 676 EXPECT_TRUE(value->GetAsString(&access_token)); | 672 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 677 EXPECT_EQ(std::string(kAccessToken), access_token); | 673 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 678 EXPECT_FALSE(func->login_ui_shown()); | 674 EXPECT_FALSE(func->login_ui_shown()); |
| 679 EXPECT_TRUE(func->scope_ui_shown()); | 675 EXPECT_TRUE(func->scope_ui_shown()); |
| 680 | 676 |
| 681 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 677 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 682 id_api()->GetCachedToken(extension->id(), | 678 id_api()->GetCachedToken(extension->id(), |
| 683 oauth2_info.scopes).status()); | 679 oauth2_info.scopes).status()); |
| 684 } | 680 } |
| 685 | 681 |
| 686 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { | 682 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveQueue) { |
| 687 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 683 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 688 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 684 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 689 func->set_extension(extension); | 685 func->set_extension(extension.get()); |
| 690 | 686 |
| 691 // Create a fake request to block the queue. | 687 // Create a fake request to block the queue. |
| 692 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 688 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 693 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 689 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
| 694 oauth2_info.scopes.end()); | 690 oauth2_info.scopes.end()); |
| 695 IdentityAPI* id_api = | 691 IdentityAPI* id_api = |
| 696 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | 692 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( |
| 697 browser()->profile()); | 693 browser()->profile()); |
| 698 IdentityMintRequestQueue* queue = id_api->mint_queue(); | 694 IdentityMintRequestQueue* queue = id_api->mint_queue(); |
| 699 MockQueuedMintRequest queued_request; | 695 MockQueuedMintRequest queued_request; |
| 700 IdentityMintRequestQueue::MintType type = | 696 IdentityMintRequestQueue::MintType type = |
| 701 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE; | 697 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE; |
| 702 | 698 |
| 703 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 699 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
| 704 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 700 queue->RequestStart(type, extension->id(), scopes, &queued_request); |
| 705 | 701 |
| 706 // The real request will start processing, but wait in the queue behind | 702 // The real request will start processing, but wait in the queue behind |
| 707 // the blocker. | 703 // the blocker. |
| 708 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 704 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 709 RunFunctionAsync(func, "[{}]"); | 705 RunFunctionAsync(func.get(), "[{}]"); |
| 710 // Verify that we have fetched the login token at this point. | 706 // Verify that we have fetched the login token at this point. |
| 711 testing::Mock::VerifyAndClearExpectations(func); | 707 testing::Mock::VerifyAndClearExpectations(func.get()); |
| 712 | 708 |
| 713 // The flow will be created after the first queued request clears. | 709 // The flow will be created after the first queued request clears. |
| 714 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 710 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 715 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 711 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
| 716 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 712 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 717 | 713 |
| 718 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 714 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
| 719 | 715 |
| 720 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 716 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 721 std::string access_token; | 717 std::string access_token; |
| 722 EXPECT_TRUE(value->GetAsString(&access_token)); | 718 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 723 EXPECT_EQ(std::string(kAccessToken), access_token); | 719 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 724 EXPECT_FALSE(func->login_ui_shown()); | 720 EXPECT_FALSE(func->login_ui_shown()); |
| 725 EXPECT_FALSE(func->scope_ui_shown()); | 721 EXPECT_FALSE(func->scope_ui_shown()); |
| 726 } | 722 } |
| 727 | 723 |
| 728 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { | 724 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { |
| 729 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 725 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 730 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 726 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 731 func->set_extension(extension); | 727 func->set_extension(extension.get()); |
| 732 | 728 |
| 733 // Create a fake request to block the queue. | 729 // Create a fake request to block the queue. |
| 734 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 730 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 735 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 731 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
| 736 oauth2_info.scopes.end()); | 732 oauth2_info.scopes.end()); |
| 737 IdentityAPI* id_api = | 733 IdentityAPI* id_api = |
| 738 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | 734 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( |
| 739 browser()->profile()); | 735 browser()->profile()); |
| 740 IdentityMintRequestQueue* queue = id_api->mint_queue(); | 736 IdentityMintRequestQueue* queue = id_api->mint_queue(); |
| 741 MockQueuedMintRequest queued_request; | 737 MockQueuedMintRequest queued_request; |
| 742 IdentityMintRequestQueue::MintType type = | 738 IdentityMintRequestQueue::MintType type = |
| 743 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; | 739 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; |
| 744 | 740 |
| 745 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 741 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
| 746 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 742 queue->RequestStart(type, extension->id(), scopes, &queued_request); |
| 747 | 743 |
| 748 // The real request will start processing, but wait in the queue behind | 744 // The real request will start processing, but wait in the queue behind |
| 749 // the blocker. | 745 // the blocker. |
| 750 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 746 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 751 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 747 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
| 752 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 748 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 753 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); | 749 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow1)); |
| 754 RunFunctionAsync(func, "[{\"interactive\": true}]"); | 750 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); |
| 755 // Verify that we have fetched the login token and run the first flow. | 751 // Verify that we have fetched the login token and run the first flow. |
| 756 testing::Mock::VerifyAndClearExpectations(func); | 752 testing::Mock::VerifyAndClearExpectations(func.get()); |
| 757 EXPECT_FALSE(func->scope_ui_shown()); | 753 EXPECT_FALSE(func->scope_ui_shown()); |
| 758 | 754 |
| 759 // The UI will be displayed and a token retrieved after the first | 755 // The UI will be displayed and a token retrieved after the first |
| 760 // queued request clears. | 756 // queued request clears. |
| 761 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 757 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
| 762 | 758 |
| 763 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 759 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 764 std::string access_token; | 760 std::string access_token; |
| 765 EXPECT_TRUE(value->GetAsString(&access_token)); | 761 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 766 EXPECT_EQ(std::string(kAccessToken), access_token); | 762 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 767 EXPECT_FALSE(func->login_ui_shown()); | 763 EXPECT_FALSE(func->login_ui_shown()); |
| 768 EXPECT_TRUE(func->scope_ui_shown()); | 764 EXPECT_TRUE(func->scope_ui_shown()); |
| 769 } | 765 } |
| 770 | 766 |
| 771 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 767 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 772 InteractiveQueuedNoninteractiveFails) { | 768 InteractiveQueuedNoninteractiveFails) { |
| 773 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 769 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 774 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 770 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 775 func->set_extension(extension); | 771 func->set_extension(extension.get()); |
| 776 | 772 |
| 777 // Create a fake request to block the interactive queue. | 773 // Create a fake request to block the interactive queue. |
| 778 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 774 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 779 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 775 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
| 780 oauth2_info.scopes.end()); | 776 oauth2_info.scopes.end()); |
| 781 IdentityAPI* id_api = | 777 IdentityAPI* id_api = |
| 782 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | 778 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( |
| 783 browser()->profile()); | 779 browser()->profile()); |
| 784 IdentityMintRequestQueue* queue = id_api->mint_queue(); | 780 IdentityMintRequestQueue* queue = id_api->mint_queue(); |
| 785 MockQueuedMintRequest queued_request; | 781 MockQueuedMintRequest queued_request; |
| 786 IdentityMintRequestQueue::MintType type = | 782 IdentityMintRequestQueue::MintType type = |
| 787 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; | 783 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; |
| 788 | 784 |
| 789 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 785 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
| 790 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 786 queue->RequestStart(type, extension->id(), scopes, &queued_request); |
| 791 | 787 |
| 792 // Non-interactive requests fail without hitting GAIA, because a | 788 // Non-interactive requests fail without hitting GAIA, because a |
| 793 // consent UI is known to be up. | 789 // consent UI is known to be up. |
| 794 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 790 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 795 std::string error = utils::RunFunctionAndReturnError( | 791 std::string error = utils::RunFunctionAndReturnError( |
| 796 func.get(), "[{}]", browser()); | 792 func.get(), "[{}]", browser()); |
| 797 EXPECT_EQ(std::string(errors::kNoGrant), error); | 793 EXPECT_EQ(std::string(errors::kNoGrant), error); |
| 798 EXPECT_FALSE(func->login_ui_shown()); | 794 EXPECT_FALSE(func->login_ui_shown()); |
| 799 EXPECT_FALSE(func->scope_ui_shown()); | 795 EXPECT_FALSE(func->scope_ui_shown()); |
| 800 | 796 |
| 801 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 797 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
| 802 } | 798 } |
| 803 | 799 |
| 804 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 800 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 805 NonInteractiveCacheHit) { | 801 NonInteractiveCacheHit) { |
| 806 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 802 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 807 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 803 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 808 func->set_extension(extension); | 804 func->set_extension(extension.get()); |
| 809 | 805 |
| 810 // pre-populate the cache with a token | 806 // pre-populate the cache with a token |
| 811 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 807 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 812 IdentityTokenCacheValue token(kAccessToken, | 808 IdentityTokenCacheValue token(kAccessToken, |
| 813 base::TimeDelta::FromSeconds(3600)); | 809 base::TimeDelta::FromSeconds(3600)); |
| 814 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 810 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
| 815 | 811 |
| 816 // Get a token. Should not require a GAIA request. | 812 // Get a token. Should not require a GAIA request. |
| 817 EXPECT_CALL(*func.get(), HasLoginToken()) | 813 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 818 .WillOnce(Return(true)); | 814 .WillOnce(Return(true)); |
| 819 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 815 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 820 func.get(), "[{}]", browser())); | 816 func.get(), "[{}]", browser())); |
| 821 std::string access_token; | 817 std::string access_token; |
| 822 EXPECT_TRUE(value->GetAsString(&access_token)); | 818 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 823 EXPECT_EQ(std::string(kAccessToken), access_token); | 819 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 824 EXPECT_FALSE(func->login_ui_shown()); | 820 EXPECT_FALSE(func->login_ui_shown()); |
| 825 EXPECT_FALSE(func->scope_ui_shown()); | 821 EXPECT_FALSE(func->scope_ui_shown()); |
| 826 } | 822 } |
| 827 | 823 |
| 828 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 824 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 829 NonInteractiveIssueAdviceCacheHit) { | 825 NonInteractiveIssueAdviceCacheHit) { |
| 830 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 826 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 831 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 827 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 832 func->set_extension(extension); | 828 func->set_extension(extension.get()); |
| 833 | 829 |
| 834 // pre-populate the cache with advice | 830 // pre-populate the cache with advice |
| 835 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 831 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 836 IssueAdviceInfo info; | 832 IssueAdviceInfo info; |
| 837 IdentityTokenCacheValue token(info); | 833 IdentityTokenCacheValue token(info); |
| 838 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 834 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
| 839 | 835 |
| 840 // Should return an error without a GAIA request. | 836 // Should return an error without a GAIA request. |
| 841 EXPECT_CALL(*func.get(), HasLoginToken()) | 837 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 842 .WillOnce(Return(true)); | 838 .WillOnce(Return(true)); |
| 843 std::string error = utils::RunFunctionAndReturnError( | 839 std::string error = utils::RunFunctionAndReturnError( |
| 844 func.get(), "[{}]", browser()); | 840 func.get(), "[{}]", browser()); |
| 845 EXPECT_EQ(std::string(errors::kNoGrant), error); | 841 EXPECT_EQ(std::string(errors::kNoGrant), error); |
| 846 EXPECT_FALSE(func->login_ui_shown()); | 842 EXPECT_FALSE(func->login_ui_shown()); |
| 847 EXPECT_FALSE(func->scope_ui_shown()); | 843 EXPECT_FALSE(func->scope_ui_shown()); |
| 848 } | 844 } |
| 849 | 845 |
| 850 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 846 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 851 InteractiveCacheHit) { | 847 InteractiveCacheHit) { |
| 852 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 848 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 853 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 849 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 854 func->set_extension(extension); | 850 func->set_extension(extension.get()); |
| 855 | 851 |
| 856 // Create a fake request to block the queue. | 852 // Create a fake request to block the queue. |
| 857 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 853 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 858 std::set<std::string> scopes(oauth2_info.scopes.begin(), | 854 std::set<std::string> scopes(oauth2_info.scopes.begin(), |
| 859 oauth2_info.scopes.end()); | 855 oauth2_info.scopes.end()); |
| 860 IdentityMintRequestQueue* queue = id_api()->mint_queue(); | 856 IdentityMintRequestQueue* queue = id_api()->mint_queue(); |
| 861 MockQueuedMintRequest queued_request; | 857 MockQueuedMintRequest queued_request; |
| 862 IdentityMintRequestQueue::MintType type = | 858 IdentityMintRequestQueue::MintType type = |
| 863 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; | 859 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE; |
| 864 | 860 |
| 865 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); | 861 EXPECT_CALL(queued_request, StartMintToken(type)).Times(1); |
| 866 queue->RequestStart(type, extension->id(), scopes, &queued_request); | 862 queue->RequestStart(type, extension->id(), scopes, &queued_request); |
| 867 | 863 |
| 868 // The real request will start processing, but wait in the queue behind | 864 // The real request will start processing, but wait in the queue behind |
| 869 // the blocker. | 865 // the blocker. |
| 870 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 866 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 871 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 867 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 872 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 868 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 873 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 869 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 874 RunFunctionAsync(func, "[{\"interactive\": true}]"); | 870 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); |
| 875 | 871 |
| 876 // Populate the cache with a token while the request is blocked. | 872 // Populate the cache with a token while the request is blocked. |
| 877 IdentityTokenCacheValue token(kAccessToken, | 873 IdentityTokenCacheValue token(kAccessToken, |
| 878 base::TimeDelta::FromSeconds(3600)); | 874 base::TimeDelta::FromSeconds(3600)); |
| 879 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 875 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
| 880 | 876 |
| 881 // When we wake up the request, it returns the cached token without | 877 // When we wake up the request, it returns the cached token without |
| 882 // displaying a UI, or hitting GAIA. | 878 // displaying a UI, or hitting GAIA. |
| 883 | 879 |
| 884 queue->RequestComplete(type, extension->id(), scopes, &queued_request); | 880 queue->RequestComplete(type, extension->id(), scopes, &queued_request); |
| 885 | 881 |
| 886 scoped_ptr<base::Value> value(WaitForSingleResult(func)); | 882 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 887 std::string access_token; | 883 std::string access_token; |
| 888 EXPECT_TRUE(value->GetAsString(&access_token)); | 884 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 889 EXPECT_EQ(std::string(kAccessToken), access_token); | 885 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 890 EXPECT_FALSE(func->login_ui_shown()); | 886 EXPECT_FALSE(func->login_ui_shown()); |
| 891 EXPECT_FALSE(func->scope_ui_shown()); | 887 EXPECT_FALSE(func->scope_ui_shown()); |
| 892 } | 888 } |
| 893 | 889 |
| 894 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 890 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 895 LoginInvalidatesTokenCache) { | 891 LoginInvalidatesTokenCache) { |
| 896 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 892 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 897 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 893 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 898 func->set_extension(extension); | 894 func->set_extension(extension.get()); |
| 899 | 895 |
| 900 // pre-populate the cache with a token | 896 // pre-populate the cache with a token |
| 901 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); | 897 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension.get()); |
| 902 IdentityTokenCacheValue token(kAccessToken, | 898 IdentityTokenCacheValue token(kAccessToken, |
| 903 base::TimeDelta::FromSeconds(3600)); | 899 base::TimeDelta::FromSeconds(3600)); |
| 904 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); | 900 id_api()->SetCachedToken(extension->id(), oauth2_info.scopes, token); |
| 905 | 901 |
| 906 // Because the user is not signed in, the token will be removed, | 902 // Because the user is not signed in, the token will be removed, |
| 907 // and we'll hit GAIA for new tokens. | 903 // and we'll hit GAIA for new tokens. |
| 908 EXPECT_CALL(*func.get(), HasLoginToken()) | 904 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 909 .WillOnce(Return(false)); | 905 .WillOnce(Return(false)); |
| 910 func->set_login_ui_result(true); | 906 func->set_login_ui_result(true); |
| 911 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 907 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 925 oauth2_info.scopes).status()); | 921 oauth2_info.scopes).status()); |
| 926 } | 922 } |
| 927 | 923 |
| 928 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { | 924 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { |
| 929 protected: | 925 protected: |
| 930 bool InvalidateDefaultToken() { | 926 bool InvalidateDefaultToken() { |
| 931 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( | 927 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( |
| 932 new IdentityRemoveCachedAuthTokenFunction); | 928 new IdentityRemoveCachedAuthTokenFunction); |
| 933 func->set_extension(utils::CreateEmptyExtension(kExtensionId)); | 929 func->set_extension(utils::CreateEmptyExtension(kExtensionId)); |
| 934 return utils::RunFunction( | 930 return utils::RunFunction( |
| 935 func, std::string("[{\"token\": \"") + kAccessToken + "\"}]", browser(), | 931 func.get(), |
| 932 std::string("[{\"token\": \"") + kAccessToken + "\"}]", |
| 933 browser(), |
| 936 extension_function_test_utils::NONE); | 934 extension_function_test_utils::NONE); |
| 937 } | 935 } |
| 938 | 936 |
| 939 IdentityAPI* id_api() { | 937 IdentityAPI* id_api() { |
| 940 return IdentityAPI::GetFactoryInstance()->GetForProfile( | 938 return IdentityAPI::GetFactoryInstance()->GetForProfile( |
| 941 browser()->profile()); | 939 browser()->profile()); |
| 942 } | 940 } |
| 943 | 941 |
| 944 void SetCachedToken(IdentityTokenCacheValue& token_data) { | 942 void SetCachedToken(IdentityTokenCacheValue& token_data) { |
| 945 id_api()->SetCachedToken(extensions::id_util::GenerateId(kExtensionId), | 943 id_api()->SetCachedToken(extensions::id_util::GenerateId(kExtensionId), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1005 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1008 new IdentityLaunchWebAuthFlowFunction()); | 1006 new IdentityLaunchWebAuthFlowFunction()); |
| 1009 scoped_refptr<Extension> empty_extension( | 1007 scoped_refptr<Extension> empty_extension( |
| 1010 utils::CreateEmptyExtension()); | 1008 utils::CreateEmptyExtension()); |
| 1011 function->set_extension(empty_extension.get()); | 1009 function->set_extension(empty_extension.get()); |
| 1012 | 1010 |
| 1013 WaitForGURLAndCloseWindow popup_observer(auth_url); | 1011 WaitForGURLAndCloseWindow popup_observer(auth_url); |
| 1014 | 1012 |
| 1015 std::string args = "[{\"interactive\": true, \"url\": \"" + | 1013 std::string args = "[{\"interactive\": true, \"url\": \"" + |
| 1016 auth_url.spec() + "\"}]"; | 1014 auth_url.spec() + "\"}]"; |
| 1017 RunFunctionAsync(function, args); | 1015 RunFunctionAsync(function.get(), args); |
| 1018 | 1016 |
| 1019 popup_observer.Wait(); | 1017 popup_observer.Wait(); |
| 1020 | 1018 |
| 1021 EXPECT_EQ(std::string(errors::kUserRejected), WaitForError(function)); | 1019 EXPECT_EQ(std::string(errors::kUserRejected), WaitForError(function.get())); |
| 1022 } | 1020 } |
| 1023 | 1021 |
| 1024 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, InteractionRequired) { | 1022 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, InteractionRequired) { |
| 1025 net::SpawnedTestServer https_server( | 1023 net::SpawnedTestServer https_server( |
| 1026 net::SpawnedTestServer::TYPE_HTTPS, | 1024 net::SpawnedTestServer::TYPE_HTTPS, |
| 1027 net::SpawnedTestServer::kLocalhost, | 1025 net::SpawnedTestServer::kLocalhost, |
| 1028 base::FilePath(FILE_PATH_LITERAL( | 1026 base::FilePath(FILE_PATH_LITERAL( |
| 1029 "chrome/test/data/extensions/api_test/identity"))); | 1027 "chrome/test/data/extensions/api_test/identity"))); |
| 1030 ASSERT_TRUE(https_server.Start()); | 1028 ASSERT_TRUE(https_server.Start()); |
| 1031 GURL auth_url(https_server.GetURL("files/interaction_required.html")); | 1029 GURL auth_url(https_server.GetURL("files/interaction_required.html")); |
| 1032 | 1030 |
| 1033 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1031 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1034 new IdentityLaunchWebAuthFlowFunction()); | 1032 new IdentityLaunchWebAuthFlowFunction()); |
| 1035 scoped_refptr<Extension> empty_extension( | 1033 scoped_refptr<Extension> empty_extension( |
| 1036 utils::CreateEmptyExtension()); | 1034 utils::CreateEmptyExtension()); |
| 1037 function->set_extension(empty_extension.get()); | 1035 function->set_extension(empty_extension.get()); |
| 1038 | 1036 |
| 1039 std::string args = "[{\"interactive\": false, \"url\": \"" + | 1037 std::string args = "[{\"interactive\": false, \"url\": \"" + |
| 1040 auth_url.spec() + "\"}]"; | 1038 auth_url.spec() + "\"}]"; |
| 1041 std::string error = utils::RunFunctionAndReturnError(function, args, | 1039 std::string error = |
| 1042 browser()); | 1040 utils::RunFunctionAndReturnError(function.get(), args, browser()); |
| 1043 | 1041 |
| 1044 EXPECT_EQ(std::string(errors::kInteractionRequired), error); | 1042 EXPECT_EQ(std::string(errors::kInteractionRequired), error); |
| 1045 } | 1043 } |
| 1046 | 1044 |
| 1047 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, LoadFailed) { | 1045 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, LoadFailed) { |
| 1048 net::SpawnedTestServer https_server( | 1046 net::SpawnedTestServer https_server( |
| 1049 net::SpawnedTestServer::TYPE_HTTPS, | 1047 net::SpawnedTestServer::TYPE_HTTPS, |
| 1050 net::SpawnedTestServer::kLocalhost, | 1048 net::SpawnedTestServer::kLocalhost, |
| 1051 base::FilePath(FILE_PATH_LITERAL( | 1049 base::FilePath(FILE_PATH_LITERAL( |
| 1052 "chrome/test/data/extensions/api_test/identity"))); | 1050 "chrome/test/data/extensions/api_test/identity"))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1069 | 1067 |
| 1070 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, NonInteractiveSuccess) { | 1068 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, NonInteractiveSuccess) { |
| 1071 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1069 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1072 new IdentityLaunchWebAuthFlowFunction()); | 1070 new IdentityLaunchWebAuthFlowFunction()); |
| 1073 scoped_refptr<Extension> empty_extension( | 1071 scoped_refptr<Extension> empty_extension( |
| 1074 utils::CreateEmptyExtension()); | 1072 utils::CreateEmptyExtension()); |
| 1075 function->set_extension(empty_extension.get()); | 1073 function->set_extension(empty_extension.get()); |
| 1076 | 1074 |
| 1077 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1075 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1078 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1076 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1079 function, | 1077 function.get(), |
| 1080 "[{\"interactive\": false," | 1078 "[{\"interactive\": false," |
| 1081 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", | 1079 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", |
| 1082 browser())); | 1080 browser())); |
| 1083 | 1081 |
| 1084 std::string url; | 1082 std::string url; |
| 1085 EXPECT_TRUE(value->GetAsString(&url)); | 1083 EXPECT_TRUE(value->GetAsString(&url)); |
| 1086 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1084 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1087 url); | 1085 url); |
| 1088 } | 1086 } |
| 1089 | 1087 |
| 1090 IN_PROC_BROWSER_TEST_F( | 1088 IN_PROC_BROWSER_TEST_F( |
| 1091 LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { | 1089 LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { |
| 1092 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1090 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1093 new IdentityLaunchWebAuthFlowFunction()); | 1091 new IdentityLaunchWebAuthFlowFunction()); |
| 1094 scoped_refptr<Extension> empty_extension( | 1092 scoped_refptr<Extension> empty_extension( |
| 1095 utils::CreateEmptyExtension()); | 1093 utils::CreateEmptyExtension()); |
| 1096 function->set_extension(empty_extension.get()); | 1094 function->set_extension(empty_extension.get()); |
| 1097 | 1095 |
| 1098 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1096 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1099 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1097 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1100 function, | 1098 function.get(), |
| 1101 "[{\"interactive\": true," | 1099 "[{\"interactive\": true," |
| 1102 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", | 1100 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", |
| 1103 browser())); | 1101 browser())); |
| 1104 | 1102 |
| 1105 std::string url; | 1103 std::string url; |
| 1106 EXPECT_TRUE(value->GetAsString(&url)); | 1104 EXPECT_TRUE(value->GetAsString(&url)); |
| 1107 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1105 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1108 url); | 1106 url); |
| 1109 } | 1107 } |
| 1110 | 1108 |
| 1111 IN_PROC_BROWSER_TEST_F( | 1109 IN_PROC_BROWSER_TEST_F( |
| 1112 LaunchWebAuthFlowFunctionTest, InteractiveSecondNavigationSuccess) { | 1110 LaunchWebAuthFlowFunctionTest, InteractiveSecondNavigationSuccess) { |
| 1113 net::SpawnedTestServer https_server( | 1111 net::SpawnedTestServer https_server( |
| 1114 net::SpawnedTestServer::TYPE_HTTPS, | 1112 net::SpawnedTestServer::TYPE_HTTPS, |
| 1115 net::SpawnedTestServer::kLocalhost, | 1113 net::SpawnedTestServer::kLocalhost, |
| 1116 base::FilePath(FILE_PATH_LITERAL( | 1114 base::FilePath(FILE_PATH_LITERAL( |
| 1117 "chrome/test/data/extensions/api_test/identity"))); | 1115 "chrome/test/data/extensions/api_test/identity"))); |
| 1118 ASSERT_TRUE(https_server.Start()); | 1116 ASSERT_TRUE(https_server.Start()); |
| 1119 GURL auth_url(https_server.GetURL("files/redirect_to_chromiumapp.html")); | 1117 GURL auth_url(https_server.GetURL("files/redirect_to_chromiumapp.html")); |
| 1120 | 1118 |
| 1121 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1119 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1122 new IdentityLaunchWebAuthFlowFunction()); | 1120 new IdentityLaunchWebAuthFlowFunction()); |
| 1123 scoped_refptr<Extension> empty_extension( | 1121 scoped_refptr<Extension> empty_extension( |
| 1124 utils::CreateEmptyExtension()); | 1122 utils::CreateEmptyExtension()); |
| 1125 function->set_extension(empty_extension.get()); | 1123 function->set_extension(empty_extension.get()); |
| 1126 | 1124 |
| 1127 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1125 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1128 std::string args = "[{\"interactive\": true, \"url\": \"" + | 1126 std::string args = "[{\"interactive\": true, \"url\": \"" + |
| 1129 auth_url.spec() + "\"}]"; | 1127 auth_url.spec() + "\"}]"; |
| 1130 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1128 scoped_ptr<base::Value> value( |
| 1131 function, args, browser())); | 1129 utils::RunFunctionAndReturnSingleResult(function.get(), args, browser())); |
| 1132 | 1130 |
| 1133 std::string url; | 1131 std::string url; |
| 1134 EXPECT_TRUE(value->GetAsString(&url)); | 1132 EXPECT_TRUE(value->GetAsString(&url)); |
| 1135 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1133 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1136 url); | 1134 url); |
| 1137 } | 1135 } |
| 1138 | 1136 |
| 1139 } // namespace extensions | 1137 } // namespace extensions |
| OLD | NEW |