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

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

Issue 431893003: [Password Manager] Verify that password is updated if multiple credentials (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 6 years, 4 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.h ('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 1228d58ebd24f0464d2be42912e5575bdcd391bf..a3399cd47ae732545fd08d488ce8b4c21cd96661 100644
--- a/components/password_manager/core/browser/password_form_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_form_manager_unittest.cc
@@ -1004,4 +1004,71 @@ TEST_F(PasswordFormManagerTest,
PasswordFormManager::RESULT_MANDATORY_ATTRIBUTES_MATCH);
}
+TEST_F(PasswordFormManagerTest, CorrectlyUpdatePasswordsWithSameUsername) {
+ // Need a MessageLoop for callbacks.
+ base::MessageLoop message_loop;
+ scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore;
+ CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare(), ""));
+
+ TestPasswordManagerClient client_with_store(password_store.get());
+ TestPasswordManager password_manager(&client_with_store);
+ EXPECT_CALL(*client_with_store.GetMockDriver(),
+ AllowPasswordGenerationForForm(_)).Times(2);
+ EXPECT_CALL(*client_with_store.GetMockDriver(), IsOffTheRecord())
+ .WillRepeatedly(Return(false));
+
+ // Add two credentials with the same username. Both should score the same
+ // and be seen as candidates to autofill.
+ PasswordForm first(*saved_match());
+ first.action = observed_form()->action;
+ first.password_value = ASCIIToUTF16("first");
+ password_store->AddLogin(first);
+
+ PasswordForm second(first);
+ second.origin = GURL("http://accounts.google.com/a/AddLogin");
+ second.password_value = ASCIIToUTF16("second");
+ second.preferred = false;
+ password_store->AddLogin(second);
+
+ PasswordFormManager storing_manager(&password_manager,
+ &client_with_store,
+ client_with_store.GetDriver(),
+ *observed_form(),
+ false);
+ storing_manager.FetchMatchingLoginsFromPasswordStore(
+ PasswordStore::ALLOW_PROMPT);
+ RunAllPendingTasks();
+
+ // We always take the last credential with a particular username, regardless
+ // of which ones are labeled preferred.
+ EXPECT_EQ(ASCIIToUTF16("second"),
+ storing_manager.preferred_match()->password_value);
+
+ PasswordForm login(*observed_form());
+ login.username_value = saved_match()->username_value;
+ login.password_value = ASCIIToUTF16("third");
+ login.preferred = true;
+ storing_manager.ProvisionallySave(
+ login, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
+
+ EXPECT_FALSE(storing_manager.IsNewLogin());
+ storing_manager.Save();
+ RunAllPendingTasks();
+
+ PasswordFormManager retrieving_manager(&password_manager,
+ &client_with_store,
+ client_with_store.GetDriver(),
+ *observed_form(),
+ false);
+
+ retrieving_manager.FetchMatchingLoginsFromPasswordStore(
+ PasswordStore::ALLOW_PROMPT);
+ RunAllPendingTasks();
+
+ // Make sure that the preferred match is updated appropriately.
+ EXPECT_EQ(ASCIIToUTF16("third"),
+ retrieving_manager.preferred_match()->password_value);
+ password_store->Shutdown();
+}
+
} // namespace password_manager
« no previous file with comments | « components/password_manager/core/browser/password_form_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698