Index: components/password_manager/core/browser/password_manager_unittest.cc |
diff --git a/components/password_manager/core/browser/password_manager_unittest.cc b/components/password_manager/core/browser/password_manager_unittest.cc |
index d4ed8cb27a3e610a8207e96469776c16b674ec43..69393427efbb1eb71984d1ae30c69494ad12f116 100644 |
--- a/components/password_manager/core/browser/password_manager_unittest.cc |
+++ b/components/password_manager/core/browser/password_manager_unittest.cc |
@@ -119,6 +119,14 @@ class PasswordManagerTest : public testing::Test { |
return form; |
} |
+ // Create a sign-up form that only has a new password field. |
+ PasswordForm MakeFormWithOnlyNewPasswordField() { |
+ PasswordForm form = MakeSimpleForm(); |
+ form.new_password_element.swap(form.password_element); |
+ form.new_password_value.swap(form.password_value); |
+ return form; |
+ } |
+ |
// Reproduction of the form present on twitter's login page. |
PasswordForm MakeTwitterLoginForm() { |
PasswordForm form; |
@@ -159,10 +167,14 @@ class PasswordManagerTest : public testing::Test { |
return false; |
if (lhs.password_element != rhs.password_element) |
return false; |
+ if (lhs.new_password_element != rhs.new_password_element) |
+ return false; |
if (lhs.username_value != rhs.username_value) |
return false; |
if (lhs.password_value != rhs.password_value) |
return false; |
+ if (lhs.new_password_value != rhs.new_password_value) |
+ return false; |
if (lhs.password_autocomplete_set != rhs.password_autocomplete_set) |
return false; |
if (lhs.submit_element != rhs.submit_element) |
@@ -201,6 +213,7 @@ MATCHER_P(FormMatches, form, "") { |
form.action == arg.action && |
form.username_element == arg.username_element && |
form.password_element == arg.password_element && |
+ form.new_password_element == arg.new_password_element && |
form.password_autocomplete_set == arg.password_autocomplete_set && |
form.submit_element == arg.submit_element; |
} |
@@ -237,8 +250,53 @@ TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
form_to_save->Save(); |
} |
+TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { |
+ // This test is the same as FormSubmitEmptyStore, except that it simulates the |
+ // user entering credentials into a sign-up form that only has a new password |
+ // field. |
+ std::vector<PasswordForm*> result; // Empty password store. |
+ EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
+ EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
+ .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
+ std::vector<PasswordForm> observed; |
+ PasswordForm form(MakeFormWithOnlyNewPasswordField()); |
+ observed.push_back(form); |
+ manager()->OnPasswordFormsParsed(observed); |
+ manager()->OnPasswordFormsRendered(observed, true); |
+ |
+ // And the form submit contract is to call ProvisionallySavePassword. |
+ manager()->ProvisionallySavePassword(form); |
+ |
+ scoped_ptr<PasswordFormManager> form_to_save; |
+ EXPECT_CALL(client_, PromptUserToSavePassword(_)) |
+ .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
+ |
+ // Now the password manager waits for the navigation to complete. |
+ observed.clear(); |
+ manager()->OnPasswordFormsParsed(observed); |
+ manager()->OnPasswordFormsRendered(observed, true); |
+ |
+ ASSERT_TRUE(form_to_save.get()); |
+ |
+ // Simulate saving the form, as if the info bar was accepted. |
+ PasswordForm saved_form; |
+ EXPECT_CALL(*store_.get(), AddLogin(_)) |
+ .WillOnce(testing::SaveArg<0>(&saved_form)); |
+ form_to_save->Save(); |
+ |
+ // The value of the new password field should have been promoted to, and saved |
+ // to the password store as the current password, and no password element name |
+ // should have been saved. |
+ PasswordForm expected_form(form); |
+ expected_form.password_value.swap(expected_form.new_password_value); |
+ expected_form.new_password_element.clear(); |
+ EXPECT_THAT(saved_form, FormMatches(expected_form)); |
+ EXPECT_EQ(expected_form.password_value, saved_form.password_value); |
+ EXPECT_EQ(expected_form.new_password_value, saved_form.new_password_value); |
+} |
+ |
TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
- // This test is the same FormSubmitEmptyStore, except that it simulates the |
+ // This test is the same as FormSubmitEmptyStore, except that it simulates the |
// user generating the password through the browser. |
std::vector<PasswordForm*> result; // Empty password store. |
EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |