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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/password_manager/core/browser/password_form_manager_unittest.cc
diff --git a/components/password_manager/core/browser/password_form_manager_unittest.cc b/components/password_manager/core/browser/password_form_manager_unittest.cc
index e2532847a87a73a10a089fb616086651373a9c5d..756f546ab4176f1e6ae5acd51fab8b0256f6db11 100644
--- a/components/password_manager/core/browser/password_form_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_form_manager_unittest.cc
@@ -101,6 +101,7 @@ class MockFormSaver : public StubFormSaver {
class MockFormFetcher : public FakeFormFetcher {
public:
MOCK_METHOD1(AddConsumer, void(Consumer*));
+ MOCK_METHOD1(RemoveConsumer, void(Consumer*));
};
MATCHER_P(CheckUsername, username_value, "Username incorrect") {
@@ -700,8 +701,10 @@ class PasswordFormManagerTest : public testing::Test {
PasswordForm psl_saved_match_;
TestPasswordManagerClient client_;
std::unique_ptr<PasswordManager> password_manager_;
- std::unique_ptr<PasswordFormManager> form_manager_;
+ // Define |fake_form_fetcher_| before |form_manager_|, because the former
+ // needs to outlive the latter.
FakeFormFetcher fake_form_fetcher_;
+ std::unique_ptr<PasswordFormManager> form_manager_;
};
class PasswordFormManagerFillOnAccountSelectTest
@@ -2964,6 +2967,21 @@ TEST_F(PasswordFormManagerTest, ResetStoredMatches) {
EXPECT_THAT(credentials_to_update, IsEmpty());
}
+// Check that on changing FormFetcher, the PasswordFormManager removes itself
+// from consuming the old one.
+TEST_F(PasswordFormManagerTest, DropFetcherOnDestruction) {
+ MockFormFetcher fetcher;
+ FormFetcher::Consumer* added_consumer = nullptr;
+ EXPECT_CALL(fetcher, AddConsumer(_)).WillOnce(SaveArg<0>(&added_consumer));
+ auto form_manager = base::MakeUnique<PasswordFormManager>(
+ password_manager(), client(), client()->driver(), *observed_form(),
+ base::MakeUnique<MockFormSaver>(), &fetcher);
+ EXPECT_EQ(form_manager.get(), added_consumer);
+
+ EXPECT_CALL(fetcher, RemoveConsumer(form_manager.get()));
+ form_manager.reset();
+}
+
// Check that if asked to take ownership of the same FormFetcher which it had
// consumed before, the PasswordFormManager does not add itself as a consumer
// again.
« 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