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

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

Issue 548953002: [Password Manager] Modified to support saving passwords on forms without username fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed breakages. Created 6 years, 3 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
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 99d877aad9341a73a3cd3b47a686f71d5d6f3312..ff326df4fa6ea3ec1cf4111d65c7f1df4f78a20b 100644
--- a/components/password_manager/core/browser/password_form_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_form_manager_unittest.cc
@@ -624,13 +624,13 @@ TEST_F(PasswordFormManagerTest, TestValidForms) {
credentials.username_element.clear();
PasswordFormManager manager4(NULL, NULL, NULL, credentials, false);
SimulateMatchingPhase(&manager4, RESULT_NO_MATCH);
- EXPECT_FALSE(manager4.HasValidPasswordForm());
+ EXPECT_TRUE(manager4.HasValidPasswordForm());
// Form without a username_element but with a new_password_element.
new_credentials.username_element.clear();
PasswordFormManager manager5(NULL, NULL, NULL, new_credentials, false);
SimulateMatchingPhase(&manager5, RESULT_NO_MATCH);
- EXPECT_FALSE(manager5.HasValidPasswordForm());
+ EXPECT_TRUE(manager5.HasValidPasswordForm());
// Form without a password_element but with a username_element.
credentials.username_element = saved_match()->username_element;
@@ -1242,4 +1242,54 @@ TEST_F(PasswordFormManagerTest, UploadFormData_AccountCreationPassword) {
form_manager.Save();
}
+TEST_F(PasswordFormManagerTest, CorrectlySavePasswordWithoutUsernameFields) {
+ // 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));
+
+ PasswordForm form(*observed_form());
+ form.username_element.clear();
+ form.password_value = ASCIIToUTF16("password");
+ form.preferred = true;
+
+ PasswordFormManager storing_manager(&password_manager,
+ &client_with_store,
+ client_with_store.GetDriver(),
+ *observed_form(),
+ false);
+ storing_manager.FetchMatchingLoginsFromPasswordStore(
+ PasswordStore::ALLOW_PROMPT);
+ RunAllPendingTasks();
+
+ storing_manager.ProvisionallySave(
+ form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
+
+ EXPECT_TRUE(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("password"),
+ retrieving_manager.preferred_match()->password_value);
+ password_store->Shutdown();
+}
+
} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698