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

Unified Diff: components/password_manager/core/browser/form_fetcher_impl_unittest.cc

Issue 2754043002: Introduce FormFetcher::Clone (Closed)
Patch Set: Fix stats test 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/form_fetcher_impl.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/form_fetcher_impl_unittest.cc
diff --git a/components/password_manager/core/browser/form_fetcher_impl_unittest.cc b/components/password_manager/core/browser/form_fetcher_impl_unittest.cc
index 219e7e59fe25fab999e3cf59a0940a4803a54430..9372dbdfb1e76f48249a13dba430c0e6deb08667 100644
--- a/components/password_manager/core/browser/form_fetcher_impl_unittest.cc
+++ b/components/password_manager/core/browser/form_fetcher_impl_unittest.cc
@@ -553,4 +553,68 @@ TEST_F(FormFetcherImplTest, StateIsWaitingDuringMigration) {
EXPECT_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState());
}
+// Cloning a FormFetcherImpl with empty results should result in an
+// instance with empty results.
+TEST_F(FormFetcherImplTest, Clone_EmptyResults) {
+ Fetch();
+ form_fetcher_->OnGetPasswordStoreResults(
+ std::vector<std::unique_ptr<PasswordForm>>());
+
+ // Clone() should not cause re-fetching from PasswordStore.
+ EXPECT_CALL(*mock_store_, GetLogins(_, _)).Times(0);
+ auto clone = form_fetcher_->Clone();
+ EXPECT_EQ(FormFetcher::State::NOT_WAITING, clone->GetState());
+ EXPECT_THAT(clone->GetInteractionsStats(), IsEmpty());
+ EXPECT_THAT(clone->GetFederatedMatches(), IsEmpty());
+ MockConsumer consumer;
+ EXPECT_CALL(consumer, ProcessMatches(IsEmpty(), 0u));
+ clone->AddConsumer(&consumer);
+}
+
+// Cloning a FormFetcherImpl with non-empty results should result in an
+// instance with the same results.
+TEST_F(FormFetcherImplTest, Clone_NonEmptyResults) {
+ Fetch();
+ PasswordForm non_federated = CreateNonFederated();
+ PasswordForm federated = CreateFederated();
+ PasswordForm android_federated = CreateAndroidFederated();
+ std::vector<std::unique_ptr<PasswordForm>> results;
+ results.push_back(base::MakeUnique<PasswordForm>(non_federated));
+ results.push_back(base::MakeUnique<PasswordForm>(federated));
+ results.push_back(base::MakeUnique<PasswordForm>(android_federated));
+ form_fetcher_->OnGetPasswordStoreResults(std::move(results));
+
+ // Clone() should not cause re-fetching from PasswordStore.
+ EXPECT_CALL(*mock_store_, GetLogins(_, _)).Times(0);
+ auto clone = form_fetcher_->Clone();
+
+ // Additionally, destroy the original FormFetcher. This should not invalidate
+ // the data in |clone|.
+ form_fetcher_.reset();
+
+ EXPECT_EQ(FormFetcher::State::NOT_WAITING, clone->GetState());
+ EXPECT_THAT(clone->GetInteractionsStats(), IsEmpty());
+ EXPECT_THAT(
+ clone->GetFederatedMatches(),
+ UnorderedElementsAre(Pointee(federated), Pointee(android_federated)));
+ MockConsumer consumer;
+ EXPECT_CALL(consumer,
+ ProcessMatches(UnorderedElementsAre(Pointee(non_federated)), 0u));
+ clone->AddConsumer(&consumer);
+}
+
+// Cloning a FormFetcherImpl with some stats should result in an instance with
+// the same stats.
+TEST_F(FormFetcherImplTest, Clone_Stats) {
+ Fetch();
+ // Pass empty results to make the state NOT_WAITING.
+ form_fetcher_->OnGetPasswordStoreResults(
+ std::vector<std::unique_ptr<PasswordForm>>());
+ std::vector<InteractionsStats> stats(1);
+ form_fetcher_->OnGetSiteStatistics(std::move(stats));
+
+ auto clone = form_fetcher_->Clone();
+ EXPECT_EQ(1u, clone->GetInteractionsStats().size());
+}
+
} // namespace password_manager
« no previous file with comments | « components/password_manager/core/browser/form_fetcher_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698