| 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 16 matching lines...) Expand all Loading... |
| 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 28 #include "components/password_manager/core/browser/password_form_manager.h" | 28 #include "components/password_manager/core/browser/password_form_manager.h" |
| 29 #include "components/password_manager/core/browser/password_manager.h" | 29 #include "components/password_manager/core/browser/password_manager.h" |
| 30 #include "components/password_manager/core/browser/statistics_table.h" | 30 #include "components/password_manager/core/browser/statistics_table.h" |
| 31 #include "components/password_manager/core/browser/stub_form_saver.h" | 31 #include "components/password_manager/core/browser/stub_form_saver.h" |
| 32 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 32 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 33 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 33 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
| 34 #include "components/password_manager/core/common/password_manager_ui.h" | 34 #include "components/password_manager/core/common/password_manager_ui.h" |
| 35 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
| 36 #include "components/variations/variations_associated_data.h" | 36 #include "components/variations/variations_associated_data.h" |
| 37 #include "content/public/browser/navigation_details.h" | 37 #include "content/public/browser/navigation_handle.h" |
| 38 #include "content/public/test/test_browser_thread_bundle.h" | 38 #include "content/public/test/test_browser_thread_bundle.h" |
| 39 #include "content/public/test/web_contents_tester.h" | 39 #include "content/public/test/web_contents_tester.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 using ::testing::DoAll; | 43 using ::testing::DoAll; |
| 44 using ::testing::ElementsAre; | 44 using ::testing::ElementsAre; |
| 45 using ::testing::IsEmpty; | 45 using ::testing::IsEmpty; |
| 46 using ::testing::Pointee; | 46 using ::testing::Pointee; |
| 47 using ::testing::Return; | 47 using ::testing::Return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 ~TestManagePasswordsUIController() override; | 91 ~TestManagePasswordsUIController() override; |
| 92 | 92 |
| 93 bool opened_bubble() const { return opened_bubble_; } | 93 bool opened_bubble() const { return opened_bubble_; } |
| 94 | 94 |
| 95 MOCK_METHOD1(CreateAccountChooser, | 95 MOCK_METHOD1(CreateAccountChooser, |
| 96 AccountChooserPrompt*(PasswordDialogController*)); | 96 AccountChooserPrompt*(PasswordDialogController*)); |
| 97 MOCK_METHOD1(CreateAutoSigninPrompt, | 97 MOCK_METHOD1(CreateAutoSigninPrompt, |
| 98 AutoSigninFirstRunPrompt*(PasswordDialogController*)); | 98 AutoSigninFirstRunPrompt*(PasswordDialogController*)); |
| 99 MOCK_CONST_METHOD0(HasBrowserWindow, bool()); | 99 MOCK_CONST_METHOD0(HasBrowserWindow, bool()); |
| 100 MOCK_METHOD0(OnUpdateBubbleAndIconVisibility, void()); | 100 MOCK_METHOD0(OnUpdateBubbleAndIconVisibility, void()); |
| 101 using ManagePasswordsUIController::DidNavigateMainFrame; | 101 using ManagePasswordsUIController::DidFinishNavigation; |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 void UpdateBubbleAndIconVisibility() override; | 104 void UpdateBubbleAndIconVisibility() override; |
| 105 void SavePasswordInternal() override {} | 105 void SavePasswordInternal() override {} |
| 106 void UpdatePasswordInternal( | 106 void UpdatePasswordInternal( |
| 107 const autofill::PasswordForm& password_form) override {} | 107 const autofill::PasswordForm& password_form) override {} |
| 108 void NeverSavePasswordInternal() override; | 108 void NeverSavePasswordInternal() override; |
| 109 | 109 |
| 110 bool opened_bubble_; | 110 bool opened_bubble_; |
| 111 }; | 111 }; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) { | 425 TEST_F(ManagePasswordsUIControllerTest, NormalNavigations) { |
| 426 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 426 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
| 427 CreateFormManager()); | 427 CreateFormManager()); |
| 428 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 428 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 429 controller()->OnPasswordSubmitted(std::move(test_form_manager)); | 429 controller()->OnPasswordSubmitted(std::move(test_form_manager)); |
| 430 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); | 430 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); |
| 431 | 431 |
| 432 // Fake-navigate. We expect the bubble's state to persist so a user reasonably | 432 // Fake-navigate. We expect the bubble's state to persist so a user reasonably |
| 433 // has been able to interact with the bubble. This happens on | 433 // has been able to interact with the bubble. This happens on |
| 434 // `accounts.google.com`, for instance. | 434 // `accounts.google.com`, for instance. |
| 435 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), | 435 std::unique_ptr<content::NavigationHandle> navigation_handle = |
| 436 content::FrameNavigateParams()); | 436 content::NavigationHandle::CreateNavigationHandleForTesting( |
| 437 GURL(), main_rfh(), true); |
| 438 navigation_handle.reset(); // Calls DidFinishNavigation. |
| 437 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, | 439 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, |
| 438 controller()->GetState()); | 440 controller()->GetState()); |
| 439 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); | 441 ExpectIconStateIs(password_manager::ui::PENDING_PASSWORD_STATE); |
| 440 } | 442 } |
| 441 | 443 |
| 442 TEST_F(ManagePasswordsUIControllerTest, NormalNavigationsClosedBubble) { | 444 TEST_F(ManagePasswordsUIControllerTest, NormalNavigationsClosedBubble) { |
| 443 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 445 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( |
| 444 CreateFormManager()); | 446 CreateFormManager()); |
| 445 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 447 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 446 controller()->OnPasswordSubmitted(std::move(test_form_manager)); | 448 controller()->OnPasswordSubmitted(std::move(test_form_manager)); |
| 447 controller()->SavePassword(); | 449 controller()->SavePassword(); |
| 448 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 450 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 449 controller()->OnBubbleHidden(); | 451 controller()->OnBubbleHidden(); |
| 450 ExpectIconStateIs(password_manager::ui::MANAGE_STATE); | 452 ExpectIconStateIs(password_manager::ui::MANAGE_STATE); |
| 451 | 453 |
| 452 // Fake-navigate. There is no bubble, reset the state. | 454 // Fake-navigate. There is no bubble, reset the state. |
| 453 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 455 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 454 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), | 456 std::unique_ptr<content::NavigationHandle> navigation_handle = |
| 455 content::FrameNavigateParams()); | 457 content::NavigationHandle::CreateNavigationHandleForTesting( |
| 458 GURL(), main_rfh(), true); |
| 459 navigation_handle.reset(); // Calls DidFinishNavigation. |
| 456 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); | 460 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->GetState()); |
| 457 ExpectIconStateIs(password_manager::ui::INACTIVE_STATE); | 461 ExpectIconStateIs(password_manager::ui::INACTIVE_STATE); |
| 458 } | 462 } |
| 459 | 463 |
| 460 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) { | 464 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) { |
| 461 // Navigate to a non-webby URL, then see what happens! | 465 // Navigate to a non-webby URL, then see what happens! |
| 462 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 466 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 463 content::WebContentsTester::For(web_contents()) | 467 content::WebContentsTester::For(web_contents()) |
| 464 ->NavigateAndCommit(GURL("chrome://sign-in")); | 468 ->NavigateAndCommit(GURL("chrome://sign-in")); |
| 465 | 469 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 | 700 |
| 697 TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRunAfterNavigation) { | 701 TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRunAfterNavigation) { |
| 698 // Pop up the autosignin promo. | 702 // Pop up the autosignin promo. |
| 699 EXPECT_CALL(*controller(), CreateAutoSigninPrompt(_)).WillOnce( | 703 EXPECT_CALL(*controller(), CreateAutoSigninPrompt(_)).WillOnce( |
| 700 Return(&dialog_prompt())); | 704 Return(&dialog_prompt())); |
| 701 EXPECT_CALL(dialog_prompt(), ShowAutoSigninPrompt()); | 705 EXPECT_CALL(dialog_prompt(), ShowAutoSigninPrompt()); |
| 702 controller()->OnPromptEnableAutoSignin(); | 706 controller()->OnPromptEnableAutoSignin(); |
| 703 | 707 |
| 704 // The dialog should survive any navigation. | 708 // The dialog should survive any navigation. |
| 705 EXPECT_CALL(dialog_prompt(), ControllerGone()).Times(0); | 709 EXPECT_CALL(dialog_prompt(), ControllerGone()).Times(0); |
| 706 content::FrameNavigateParams params; | |
| 707 params.transition = ui::PAGE_TRANSITION_LINK; | |
| 708 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 710 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 709 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(), params); | 711 std::unique_ptr<content::NavigationHandle> navigation_handle = |
| 712 content::NavigationHandle::CreateNavigationHandleForTesting( |
| 713 GURL(), main_rfh(), true); |
| 714 navigation_handle.reset(); // Calls DidFinishNavigation. |
| 710 ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&dialog_prompt())); | 715 ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(&dialog_prompt())); |
| 711 EXPECT_CALL(dialog_prompt(), ControllerGone()); | 716 EXPECT_CALL(dialog_prompt(), ControllerGone()); |
| 712 } | 717 } |
| 713 | 718 |
| 714 TEST_F(ManagePasswordsUIControllerTest, AutofillDuringAutoSignin) { | 719 TEST_F(ManagePasswordsUIControllerTest, AutofillDuringAutoSignin) { |
| 715 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; | 720 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials; |
| 716 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); | 721 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
| 717 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 722 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 718 controller()->OnAutoSignin(std::move(local_credentials), | 723 controller()->OnAutoSignin(std::move(local_credentials), |
| 719 test_local_form().origin); | 724 test_local_form().origin); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 // Open the bubble again. | 797 // Open the bubble again. |
| 793 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); | 798 local_credentials.emplace_back(new autofill::PasswordForm(test_local_form())); |
| 794 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); | 799 EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); |
| 795 controller()->OnAutoSignin(std::move(local_credentials), | 800 controller()->OnAutoSignin(std::move(local_credentials), |
| 796 test_local_form().origin); | 801 test_local_form().origin); |
| 797 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); | 802 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->GetState()); |
| 798 // Check the delegate is destroyed. Thus, the first bubble has no way to mess | 803 // Check the delegate is destroyed. Thus, the first bubble has no way to mess |
| 799 // up with the controller's state. | 804 // up with the controller's state. |
| 800 EXPECT_FALSE(proxy_delegate); | 805 EXPECT_FALSE(proxy_delegate); |
| 801 } | 806 } |
| OLD | NEW |