| Index: chrome/browser/password_manager/password_manager_unittest.cc
|
| diff --git a/chrome/browser/password_manager/password_manager_unittest.cc b/chrome/browser/password_manager/password_manager_unittest.cc
|
| index 1c0c97e7842b803f6c88824cbbb537907e344bfa..8884af16efda8a5914a9d4ce78736a90aca36996 100644
|
| --- a/chrome/browser/password_manager/password_manager_unittest.cc
|
| +++ b/chrome/browser/password_manager/password_manager_unittest.cc
|
| @@ -83,6 +83,8 @@ class PasswordManagerTest : public ChromeRenderViewHostTestHarness {
|
| form.password_element = ASCIIToUTF16("Passwd");
|
| form.username_value = ASCIIToUTF16("google");
|
| form.password_value = ASCIIToUTF16("password");
|
| + // Default to true so we only need to add tests in autocomplete=off cases.
|
| + form.password_autocomplete_set = true;
|
| form.submit_element = ASCIIToUTF16("signIn");
|
| form.signon_realm = "http://www.google.com";
|
| return form;
|
| @@ -107,6 +109,8 @@ MATCHER_P(FormMatches, form, "") {
|
| form.action == arg.action &&
|
| form.username_element == arg.username_element &&
|
| form.password_element == arg.password_element &&
|
| + form.password_autocomplete_set ==
|
| + arg.password_autocomplete_set &&
|
| form.submit_element == arg.submit_element;
|
| }
|
|
|
| @@ -159,7 +163,8 @@ TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) {
|
| manager()->ProvisionallySavePassword(form);
|
|
|
| // The user should not be presented with an infobar as they have already given
|
| - // consent. The form should be saved once navigation occurs.
|
| + // consent by using the generated password. The form should be saved once
|
| + // navigation occurs.
|
| EXPECT_CALL(delegate_,
|
| AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
|
| EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
|
| @@ -370,3 +375,61 @@ TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) {
|
| manager()->OnPasswordFormsParsed(observed);
|
| }
|
|
|
| +TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) {
|
| + // Test password form with non-generated password will not be saved if
|
| + // autocomplete=off.
|
| + std::vector<PasswordForm*> result; // Empty password store.
|
| + EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
|
| + EXPECT_CALL(*store_, GetLogins(_,_))
|
| + .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
|
| + std::vector<PasswordForm> observed;
|
| + PasswordForm form(MakeSimpleForm());
|
| + form.password_autocomplete_set = false;
|
| + observed.push_back(form);
|
| + manager()->OnPasswordFormsParsed(observed); // The initial load.
|
| + manager()->OnPasswordFormsRendered(observed); // The initial layout.
|
| +
|
| + // And the form submit contract is to call ProvisionallySavePassword.
|
| + manager()->ProvisionallySavePassword(form);
|
| +
|
| + // Password form should not be saved.
|
| + EXPECT_CALL(delegate_,
|
| + AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
|
| + EXPECT_CALL(*store_, AddLogin(FormMatches(form))).Times(Exactly(0));
|
| +
|
| + // Now the password manager waits for the navigation to complete.
|
| + observed.clear();
|
| + manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
|
| + manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
|
| +}
|
| +
|
| +TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) {
|
| + // Test password form with generated password will still be saved if
|
| + // autocomplete=off.
|
| + std::vector<PasswordForm*> result; // Empty password store.
|
| + EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0));
|
| + EXPECT_CALL(*store_, GetLogins(_,_))
|
| + .WillOnce(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
|
| + std::vector<PasswordForm> observed;
|
| + PasswordForm form(MakeSimpleForm());
|
| + form.password_autocomplete_set = false;
|
| + observed.push_back(form);
|
| + manager()->OnPasswordFormsParsed(observed); // The initial load.
|
| + manager()->OnPasswordFormsRendered(observed); // The initial layout.
|
| +
|
| + // Simulate the user generating the password and submitting the form.
|
| + manager()->SetFormHasGeneratedPassword(form);
|
| + manager()->ProvisionallySavePassword(form);
|
| +
|
| + // The user should not be presented with an infobar as they have already given
|
| + // consent by using the generated password. The form should be saved once
|
| + // navigation occurs.
|
| + EXPECT_CALL(delegate_,
|
| + AddSavePasswordInfoBarIfPermitted(_)).Times(Exactly(0));
|
| + EXPECT_CALL(*store_, AddLogin(FormMatches(form)));
|
| +
|
| + // Now the password manager waits for the navigation to complete.
|
| + observed.clear();
|
| + manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
|
| + manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
|
| +}
|
|
|