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

Side by Side 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: Fixed breakages. Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/core/browser/password_manager.h" 5 #include "components/password_manager/core/browser/password_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 form.username_element = ASCIIToUTF16("EmailField"); 170 form.username_element = ASCIIToUTF16("EmailField");
171 form.password_element = ASCIIToUTF16("PasswdField"); 171 form.password_element = ASCIIToUTF16("PasswdField");
172 form.username_value = ASCIIToUTF16("twitter"); 172 form.username_value = ASCIIToUTF16("twitter");
173 form.password_value = ASCIIToUTF16("password"); 173 form.password_value = ASCIIToUTF16("password");
174 form.password_autocomplete_set = true; 174 form.password_autocomplete_set = true;
175 form.submit_element = ASCIIToUTF16("signIn"); 175 form.submit_element = ASCIIToUTF16("signIn");
176 form.signon_realm = "https://twitter.com"; 176 form.signon_realm = "https://twitter.com";
177 return form; 177 return form;
178 } 178 }
179 179
180 PasswordForm MakeSimpleFormWithOnlyPasswordField() {
181 PasswordForm form(MakeSimpleForm());
182 form.username_element.clear();
183 form.username_value.clear();
184 return form;
185 }
186
180 bool FormsAreEqual(const autofill::PasswordForm& lhs, 187 bool FormsAreEqual(const autofill::PasswordForm& lhs,
181 const autofill::PasswordForm& rhs) { 188 const autofill::PasswordForm& rhs) {
182 if (lhs.origin != rhs.origin) 189 if (lhs.origin != rhs.origin)
183 return false; 190 return false;
184 if (lhs.action != rhs.action) 191 if (lhs.action != rhs.action)
185 return false; 192 return false;
186 if (lhs.username_element != rhs.username_element) 193 if (lhs.username_element != rhs.username_element)
187 return false; 194 return false;
188 if (lhs.password_element != rhs.password_element) 195 if (lhs.password_element != rhs.password_element)
189 return false; 196 return false;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 scoped_ptr<PasswordFormManager> form_to_save; 827 scoped_ptr<PasswordFormManager> form_to_save;
821 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0); 828 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(0);
822 829
823 // Now the password manager waits for the login to complete successfully. 830 // Now the password manager waits for the login to complete successfully.
824 observed.clear(); 831 observed.clear();
825 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 832 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
826 manager()->OnPasswordFormsRendered(observed, 833 manager()->OnPasswordFormsRendered(observed,
827 true); // The post-navigation layout. 834 true); // The post-navigation layout.
828 } 835 }
829 836
837 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) {
838 // Test to verify that on submitting the HTML password form without having
839 // username input filed shows password save promt and saves the password to
840 // store.
841 std::vector<PasswordForm*> result; // Empty password store.
842 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
843 EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
844 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
845 std::vector<PasswordForm> observed;
846
847 // Loads passsword form without username input field.
848 PasswordForm form(MakeSimpleFormWithOnlyPasswordField());
849 observed.push_back(form);
850 manager()->OnPasswordFormsParsed(observed); // The initial load.
851 manager()->OnPasswordFormsRendered(observed, true); // The initial layout.
852
853 // And the form submit contract is to call ProvisionallySavePassword.
854 manager()->ProvisionallySavePassword(form);
855
856 scoped_ptr<PasswordFormManager> form_to_save;
857 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_))
858 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
859
860 // Now the password manager waits for the navigation to complete.
861 observed.clear();
862 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
863 manager()->OnPasswordFormsRendered(observed,
864 true); // The post-navigation layout.
865
866 ASSERT_TRUE(form_to_save.get());
867 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form)));
868
869 // Simulate saving the form, as if the info bar was accepted.
870 form_to_save->Save();
871 }
872
830 } // namespace password_manager 873 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698