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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // Open the bubble again. | 798 // Open the bubble again. |
799 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); | 799 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
800 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 800 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
801 controller()->OnAutoSignin(std::move(local_credentials), | 801 controller()->OnAutoSignin(std::move(local_credentials), |
802 test_local_form().origin); | 802 test_local_form().origin); |
803 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); | 803 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); |
804 // Check the delegate is destroyed. Thus, the first bubble has no way to mess | 804 // Check the delegate is destroyed. Thus, the first bubble has no way to mess |
805 // up with the controller's state. | 805 // up with the controller's state. |
806 EXPECT_FALSE(proxy_delegate); | 806 EXPECT_FALSE(proxy_delegate); |
807 } | 807 } |
| 808 |
| 809 TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_UseFallback) { |
| 810 for (bool is_update : {false, true}) { |
| 811 SCOPED_TRACE(testing::Message("is_update = ") << is_update); |
| 812 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
| 813 CreateFormManager()); |
| 814 test_form_manager->ProvisionallySave( |
| 815 test_local_form(), |
| 816 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
| 817 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 818 controller()->OnShowManualFallbackForSaving( |
| 819 std::move(test_form_manager), false /* has_generated_password */, |
| 820 is_update); |
| 821 ExpectIconAndControllerStateIs( |
| 822 is_update ? password_manager::ui::PENDING_PASSWORD_UPDATE_STATE |
| 823 : password_manager::ui::PENDING_PASSWORD_STATE); |
| 824 EXPECT_FALSE(controller()->opened_bubble()); |
| 825 |
| 826 // A user clicks on omnibox icon, opens the bubble and press Save/Update. |
| 827 if (is_update) { |
| 828 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 829 controller()->UpdatePassword(autofill::PasswordForm()); |
| 830 } else { |
| 831 controller()->SavePassword(test_local_form().username_value); |
| 832 } |
| 833 ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); |
| 834 testing::Mock::VerifyAndClearExpectations(controller()); |
| 835 } |
| 836 } |
| 837 |
| 838 TEST_F(ManagePasswordsUIControllerTest, ManualFallbackForSaving_HideFallback) { |
| 839 for (bool is_update : {false, true}) { |
| 840 SCOPED_TRACE(testing::Message("is_update = ") << is_update); |
| 841 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
| 842 CreateFormManager()); |
| 843 test_form_manager->ProvisionallySave( |
| 844 test_local_form(), |
| 845 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
| 846 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 847 controller()->OnShowManualFallbackForSaving( |
| 848 std::move(test_form_manager), false /* has_generated_password */, |
| 849 is_update); |
| 850 ExpectIconAndControllerStateIs( |
| 851 is_update ? password_manager::ui::PENDING_PASSWORD_UPDATE_STATE |
| 852 : password_manager::ui::PENDING_PASSWORD_STATE); |
| 853 EXPECT_FALSE(controller()->opened_bubble()); |
| 854 |
| 855 // A user clears the password field. It hides the fallback. |
| 856 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 857 controller()->OnHideManualFallbackForSaving(); |
| 858 ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); |
| 859 testing::Mock::VerifyAndClearExpectations(controller()); |
| 860 } |
| 861 } |
| 862 |
| 863 TEST_F(ManagePasswordsUIControllerTest, |
| 864 ManualFallbackForSaving_GeneratedPassword) { |
| 865 for (bool user_closed_bubble : {false, true}) { |
| 866 SCOPED_TRACE(testing::Message("user_closed_bubble = ") |
| 867 << user_closed_bubble); |
| 868 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
| 869 CreateFormManager()); |
| 870 test_form_manager->ProvisionallySave( |
| 871 test_local_form(), |
| 872 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
| 873 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 874 controller()->OnShowManualFallbackForSaving( |
| 875 std::move(test_form_manager), true /* has_generated_password */, false); |
| 876 ExpectIconAndControllerStateIs(password_manager::ui::CONFIRMATION_STATE); |
| 877 EXPECT_FALSE(controller()->opened_bubble()); |
| 878 |
| 879 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 880 if (user_closed_bubble) { |
| 881 // A user opens the confirmation bubble and presses OK. |
| 882 controller()->OnBubbleHidden(); |
| 883 } else { |
| 884 // The user removes the generated password. It hides the fallback. |
| 885 controller()->OnHideManualFallbackForSaving(); |
| 886 } |
| 887 ExpectIconAndControllerStateIs(password_manager::ui::MANAGE_STATE); |
| 888 testing::Mock::VerifyAndClearExpectations(controller()); |
| 889 } |
| 890 } |
OLD | NEW |