Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: components/password_manager/core/browser/password_form_manager_unittest.cc

Issue 2760653002: Add FormFetcher::RemoveConsumer (Closed)
Patch Set: Rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/password_manager/core/browser/password_form_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/password_manager/core/browser/password_form_manager.h" 5 #include "components/password_manager/core/browser/password_form_manager.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return *static_cast<MockFormSaver*>(form_manager->form_saver()); 94 return *static_cast<MockFormSaver*>(form_manager->form_saver());
95 } 95 }
96 96
97 private: 97 private:
98 DISALLOW_COPY_AND_ASSIGN(MockFormSaver); 98 DISALLOW_COPY_AND_ASSIGN(MockFormSaver);
99 }; 99 };
100 100
101 class MockFormFetcher : public FakeFormFetcher { 101 class MockFormFetcher : public FakeFormFetcher {
102 public: 102 public:
103 MOCK_METHOD1(AddConsumer, void(Consumer*)); 103 MOCK_METHOD1(AddConsumer, void(Consumer*));
104 MOCK_METHOD1(RemoveConsumer, void(Consumer*));
104 }; 105 };
105 106
106 MATCHER_P(CheckUsername, username_value, "Username incorrect") { 107 MATCHER_P(CheckUsername, username_value, "Username incorrect") {
107 return arg.username_value == username_value; 108 return arg.username_value == username_value;
108 } 109 }
109 110
110 MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") { 111 MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") {
111 return arg && arg->username_value == username_value; 112 return arg && arg->username_value == username_value;
112 } 113 }
113 114
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 694
694 private: 695 private:
695 // Necessary for callbacks, and for TestAutofillDriver. 696 // Necessary for callbacks, and for TestAutofillDriver.
696 base::MessageLoop message_loop_; 697 base::MessageLoop message_loop_;
697 698
698 PasswordForm observed_form_; 699 PasswordForm observed_form_;
699 PasswordForm saved_match_; 700 PasswordForm saved_match_;
700 PasswordForm psl_saved_match_; 701 PasswordForm psl_saved_match_;
701 TestPasswordManagerClient client_; 702 TestPasswordManagerClient client_;
702 std::unique_ptr<PasswordManager> password_manager_; 703 std::unique_ptr<PasswordManager> password_manager_;
704 // Define |fake_form_fetcher_| before |form_manager_|, because the former
705 // needs to outlive the latter.
706 FakeFormFetcher fake_form_fetcher_;
703 std::unique_ptr<PasswordFormManager> form_manager_; 707 std::unique_ptr<PasswordFormManager> form_manager_;
704 FakeFormFetcher fake_form_fetcher_;
705 }; 708 };
706 709
707 class PasswordFormManagerFillOnAccountSelectTest 710 class PasswordFormManagerFillOnAccountSelectTest
708 : public PasswordFormManagerTest { 711 : public PasswordFormManagerTest {
709 public: 712 public:
710 PasswordFormManagerFillOnAccountSelectTest() { 713 PasswordFormManagerFillOnAccountSelectTest() {
711 scoped_feature_list_.InitAndEnableFeature(features::kFillOnAccountSelect); 714 scoped_feature_list_.InitAndEnableFeature(features::kFillOnAccountSelect);
712 } 715 }
713 716
714 base::test::ScopedFeatureList scoped_feature_list_; 717 base::test::ScopedFeatureList scoped_feature_list_;
(...skipping 2242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 form_manager()->ProvisionallySave( 2960 form_manager()->ProvisionallySave(
2958 updated, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2961 updated, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2959 credentials_to_update.clear(); 2962 credentials_to_update.clear();
2960 EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr)) 2963 EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr))
2961 .WillOnce(SaveArgPointee<2>(&credentials_to_update)); 2964 .WillOnce(SaveArgPointee<2>(&credentials_to_update));
2962 form_manager()->Save(); 2965 form_manager()->Save();
2963 2966
2964 EXPECT_THAT(credentials_to_update, IsEmpty()); 2967 EXPECT_THAT(credentials_to_update, IsEmpty());
2965 } 2968 }
2966 2969
2970 // Check that on changing FormFetcher, the PasswordFormManager removes itself
2971 // from consuming the old one.
2972 TEST_F(PasswordFormManagerTest, DropFetcherOnDestruction) {
2973 MockFormFetcher fetcher;
2974 FormFetcher::Consumer* added_consumer = nullptr;
2975 EXPECT_CALL(fetcher, AddConsumer(_)).WillOnce(SaveArg<0>(&added_consumer));
2976 auto form_manager = base::MakeUnique<PasswordFormManager>(
2977 password_manager(), client(), client()->driver(), *observed_form(),
2978 base::MakeUnique<MockFormSaver>(), &fetcher);
2979 EXPECT_EQ(form_manager.get(), added_consumer);
2980
2981 EXPECT_CALL(fetcher, RemoveConsumer(form_manager.get()));
2982 form_manager.reset();
2983 }
2984
2967 // Check that if asked to take ownership of the same FormFetcher which it had 2985 // Check that if asked to take ownership of the same FormFetcher which it had
2968 // consumed before, the PasswordFormManager does not add itself as a consumer 2986 // consumed before, the PasswordFormManager does not add itself as a consumer
2969 // again. 2987 // again.
2970 TEST_F(PasswordFormManagerTest, GrabFetcher_Same) { 2988 TEST_F(PasswordFormManagerTest, GrabFetcher_Same) {
2971 auto fetcher = base::MakeUnique<MockFormFetcher>(); 2989 auto fetcher = base::MakeUnique<MockFormFetcher>();
2972 fetcher->Fetch(); 2990 fetcher->Fetch();
2973 PasswordFormManager form_manager( 2991 PasswordFormManager form_manager(
2974 password_manager(), client(), client()->driver(), *observed_form(), 2992 password_manager(), client(), client()->driver(), *observed_form(),
2975 base::MakeUnique<MockFormSaver>(), fetcher.get()); 2993 base::MakeUnique<MockFormSaver>(), fetcher.get());
2976 2994
2977 EXPECT_CALL(*fetcher, AddConsumer(_)).Times(0); 2995 EXPECT_CALL(*fetcher, AddConsumer(_)).Times(0);
2978 form_manager.GrabFetcher(std::move(fetcher)); 2996 form_manager.GrabFetcher(std::move(fetcher));
2979 } 2997 }
2980 2998
2981 } // namespace password_manager 2999 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/core/browser/password_form_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698