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

Unified Diff: components/password_manager/core/browser/password_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: Added unit-tests and fixed lint errors. 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_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 469a0a1a965d1e3edcfbac4972c54768c7c86112..b82bd3f6d7a5842e8fe22dff1af04a4755adac40 100644
--- a/components/password_manager/core/browser/password_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_manager_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
vabr (Chromium) 2014/09/15 13:01:45 Also here -- you don't introduce std::string with
Pritam Nikam 2014/09/15 15:02:08 Done.
#include <vector>
#include "base/message_loop/message_loop.h"
@@ -174,6 +175,18 @@ class PasswordManagerTest : public testing::Test {
return form;
}
+ PasswordForm MakeSimpleFormWithOnlyPasswordField() {
vabr (Chromium) 2014/09/15 13:01:46 nit: To improve readability, consider changing the
Pritam Nikam 2014/09/15 15:02:08 Done.
+ PasswordForm form;
+ form.origin = GURL("http://www.google.com/a/LoginAuth");
+ form.action = GURL("http://www.google.com/a/Login");
+ form.password_element = ASCIIToUTF16("Passwd");
+ form.password_value = ASCIIToUTF16("password");
+ form.password_autocomplete_set = true;
+ form.submit_element = ASCIIToUTF16("signIn");
+ form.signon_realm = "http://www.google.com";
+ return form;
+ }
+
bool FormsAreEqual(const autofill::PasswordForm& lhs,
const autofill::PasswordForm& rhs) {
if (lhs.origin != rhs.origin)
@@ -758,4 +771,37 @@ TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) {
manager()->OnPasswordFormsRendered(observed, true);
}
+TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) {
+ // Test that observing a newly submitted form shows the save password bar.
vabr (Chromium) 2014/09/15 13:01:45 nits: (1) Do mention what is special about the for
Pritam Nikam 2014/09/15 15:02:09 Done.
+ 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(MakeSimpleFormWithOnlyPasswordField());
+ observed.push_back(form);
+ manager()->OnPasswordFormsParsed(observed); // The initial load.
+ manager()->OnPasswordFormsRendered(observed, true); // The initial layout.
+
+ // Simulate the user generating the password and submitting the form.
vabr (Chromium) 2014/09/15 13:01:45 Don't mix password generation in -- we only allow
Pritam Nikam 2014/09/15 15:02:08 Done.
+ manager()->SetFormHasGeneratedPassword(form);
+ manager()->ProvisionallySavePassword(form);
+
+ // The user should not be presented with an infobar as they have already given
vabr (Chromium) 2014/09/15 13:01:46 This whole comment looks wrong: the save password
Pritam Nikam 2014/09/15 15:02:08 Done.
+ // consent by using the generated password. The form should be saved once
+ // navigation occurs. The client will be informed that automatic saving has
+ // occured.
+ EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0));
vabr (Chromium) 2014/09/15 13:01:46 Please update the expectations following the clari
Pritam Nikam 2014/09/15 15:02:08 Done.
+ EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
+ scoped_ptr<PasswordFormManager> saved_form_manager;
+ EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1)).WillOnce(
+ WithArg<0>(SaveToScopedPtr(&saved_form_manager)));
+
+ // Now the password manager waits for the navigation to complete.
+ observed.clear();
+ manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
+ manager()->OnPasswordFormsRendered(observed,
+ true); // The post-navigation layout.
+}
+
} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698