| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 35 #include "components/variations/variations_associated_data.h" | 35 #include "components/variations/variations_associated_data.h" |
| 36 #include "content/public/browser/navigation_details.h" | 36 #include "content/public/browser/navigation_details.h" |
| 37 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
| 38 #include "content/public/test/web_contents_tester.h" | 38 #include "content/public/test/web_contents_tester.h" |
| 39 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 41 | 41 |
| 42 using ::testing::DoAll; | 42 using ::testing::DoAll; |
| 43 using ::testing::ElementsAre; | 43 using ::testing::ElementsAre; |
| 44 using ::testing::IsEmpty; |
| 44 using ::testing::Pointee; | 45 using ::testing::Pointee; |
| 45 using ::testing::Return; | 46 using ::testing::Return; |
| 46 using ::testing::SaveArg; | 47 using ::testing::SaveArg; |
| 47 using ::testing::_; | 48 using ::testing::_; |
| 48 | 49 |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| 51 // Number of dismissals that for sure supresses the bubble. | 52 // Number of dismissals that for sure supresses the bubble. |
| 52 const int kGreatDissmisalCount = 10; | 53 const int kGreatDissmisalCount = 10; |
| 53 | 54 |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 // Simulate requesting a credential during prefetch. The tab has no associated | 620 // Simulate requesting a credential during prefetch. The tab has no associated |
| 620 // browser. Nothing should happen. | 621 // browser. Nothing should happen. |
| 621 EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(false)); | 622 EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(false)); |
| 622 EXPECT_FALSE(controller()->OnChooseCredentials( | 623 EXPECT_FALSE(controller()->OnChooseCredentials( |
| 623 std::move(local_credentials), std::move(federated_credentials), origin, | 624 std::move(local_credentials), std::move(federated_credentials), origin, |
| 624 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, | 625 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, |
| 625 base::Unretained(this)))); | 626 base::Unretained(this)))); |
| 626 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); | 627 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); |
| 627 } | 628 } |
| 628 | 629 |
| 630 TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialPSL) { |
| 631 test_local_form().is_public_suffix_match = true; |
| 632 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; |
| 633 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
| 634 std::vector<std::unique_ptr<autofill::PasswordForm>> federated_credentials; |
| 635 GURL origin("http://example.com"); |
| 636 PasswordDialogController* dialog_controller = nullptr; |
| 637 EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce( |
| 638 DoAll(SaveArg<0>(&dialog_controller), Return(&dialog_prompt()))); |
| 639 EXPECT_CALL(dialog_prompt(), ShowAccountChooser()); |
| 640 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 641 EXPECT_CALL(*controller(), HasBrowserWindow()).WillOnce(Return(true)); |
| 642 EXPECT_TRUE(controller()->OnChooseCredentials( |
| 643 std::move(local_credentials), std::move(federated_credentials), origin, |
| 644 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback, |
| 645 base::Unretained(this)))); |
| 646 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, |
| 647 controller()->GetState()); |
| 648 EXPECT_EQ(origin, controller()->GetOrigin()); |
| 649 EXPECT_THAT(controller()->GetCurrentForms(), IsEmpty()); |
| 650 ASSERT_THAT(dialog_controller->GetLocalForms(), |
| 651 ElementsAre(Pointee(test_local_form()))); |
| 652 EXPECT_THAT(dialog_controller->GetFederationsForms(), testing::IsEmpty()); |
| 653 ExpectIconStateIs(password_manager::ui::INACTIVE_STATE); |
| 654 |
| 655 EXPECT_CALL(dialog_prompt(), ControllerGone()); |
| 656 EXPECT_CALL(*this, CredentialCallback(Pointee(test_local_form()))); |
| 657 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 658 dialog_controller->OnChooseCredentials( |
| 659 *dialog_controller->GetLocalForms()[0], |
| 660 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 661 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->GetState()); |
| 662 EXPECT_THAT(controller()->GetCurrentForms(), IsEmpty()); |
| 663 } |
| 664 |
| 629 TEST_F(ManagePasswordsUIControllerTest, AutoSignin) { | 665 TEST_F(ManagePasswordsUIControllerTest, AutoSignin) { |
| 630 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; | 666 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; |
| 631 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); | 667 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
| 632 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 668 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 633 controller()->OnAutoSignin(std::move(local_credentials), | 669 controller()->OnAutoSignin(std::move(local_credentials), |
| 634 test_local_form().origin); | 670 test_local_form().origin); |
| 635 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); | 671 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); |
| 636 EXPECT_EQ(test_local_form().origin, controller()->GetOrigin()); | 672 EXPECT_EQ(test_local_form().origin, controller()->GetOrigin()); |
| 637 ASSERT_FALSE(controller()->GetCurrentForms().empty()); | 673 ASSERT_FALSE(controller()->GetCurrentForms().empty()); |
| 638 EXPECT_EQ(test_local_form(), *controller()->GetCurrentForms()[0]); | 674 EXPECT_EQ(test_local_form(), *controller()->GetCurrentForms()[0]); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 // Open the bubble again. | 809 // Open the bubble again. |
| 774 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); | 810 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
| 775 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 811 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 776 controller()->OnAutoSignin(std::move(local_credentials), | 812 controller()->OnAutoSignin(std::move(local_credentials), |
| 777 test_local_form().origin); | 813 test_local_form().origin); |
| 778 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); | 814 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); |
| 779 // Check the delegate is destroyed. Thus, the first bubble has no way to mess | 815 // Check the delegate is destroyed. Thus, the first bubble has no way to mess |
| 780 // up with the controller's state. | 816 // up with the controller's state. |
| 781 EXPECT_FALSE(proxy_delegate); | 817 EXPECT_FALSE(proxy_delegate); |
| 782 } | 818 } |
| OLD | NEW |