Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <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.
| |
| 5 #include <vector> | 6 #include <vector> |
| 6 | 7 |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/password_manager/core/browser/mock_password_store.h" | 14 #include "components/password_manager/core/browser/mock_password_store.h" |
| 14 #include "components/password_manager/core/browser/password_autofill_manager.h" | 15 #include "components/password_manager/core/browser/password_autofill_manager.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 form.username_element = ASCIIToUTF16("EmailField"); | 168 form.username_element = ASCIIToUTF16("EmailField"); |
| 168 form.password_element = ASCIIToUTF16("PasswdField"); | 169 form.password_element = ASCIIToUTF16("PasswdField"); |
| 169 form.username_value = ASCIIToUTF16("twitter"); | 170 form.username_value = ASCIIToUTF16("twitter"); |
| 170 form.password_value = ASCIIToUTF16("password"); | 171 form.password_value = ASCIIToUTF16("password"); |
| 171 form.password_autocomplete_set = true; | 172 form.password_autocomplete_set = true; |
| 172 form.submit_element = ASCIIToUTF16("signIn"); | 173 form.submit_element = ASCIIToUTF16("signIn"); |
| 173 form.signon_realm = "https://twitter.com"; | 174 form.signon_realm = "https://twitter.com"; |
| 174 return form; | 175 return form; |
| 175 } | 176 } |
| 176 | 177 |
| 178 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.
| |
| 179 PasswordForm form; | |
| 180 form.origin = GURL("http://www.google.com/a/LoginAuth"); | |
| 181 form.action = GURL("http://www.google.com/a/Login"); | |
| 182 form.password_element = ASCIIToUTF16("Passwd"); | |
| 183 form.password_value = ASCIIToUTF16("password"); | |
| 184 form.password_autocomplete_set = true; | |
| 185 form.submit_element = ASCIIToUTF16("signIn"); | |
| 186 form.signon_realm = "http://www.google.com"; | |
| 187 return form; | |
| 188 } | |
| 189 | |
| 177 bool FormsAreEqual(const autofill::PasswordForm& lhs, | 190 bool FormsAreEqual(const autofill::PasswordForm& lhs, |
| 178 const autofill::PasswordForm& rhs) { | 191 const autofill::PasswordForm& rhs) { |
| 179 if (lhs.origin != rhs.origin) | 192 if (lhs.origin != rhs.origin) |
| 180 return false; | 193 return false; |
| 181 if (lhs.action != rhs.action) | 194 if (lhs.action != rhs.action) |
| 182 return false; | 195 return false; |
| 183 if (lhs.username_element != rhs.username_element) | 196 if (lhs.username_element != rhs.username_element) |
| 184 return false; | 197 return false; |
| 185 if (lhs.password_element != rhs.password_element) | 198 if (lhs.password_element != rhs.password_element) |
| 186 return false; | 199 return false; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); | 764 EXPECT_CALL(client_, PromptUserToSavePasswordPtr(_)).Times(Exactly(0)); |
| 752 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); | 765 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))).Times(Exactly(0)); |
| 753 | 766 |
| 754 // Submit form and finish navigation. | 767 // Submit form and finish navigation. |
| 755 manager()->ProvisionallySavePassword(form); | 768 manager()->ProvisionallySavePassword(form); |
| 756 observed.clear(); | 769 observed.clear(); |
| 757 manager()->OnPasswordFormsParsed(observed); | 770 manager()->OnPasswordFormsParsed(observed); |
| 758 manager()->OnPasswordFormsRendered(observed, true); | 771 manager()->OnPasswordFormsRendered(observed, true); |
| 759 } | 772 } |
| 760 | 773 |
| 774 TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) { | |
| 775 // 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.
| |
| 776 std::vector<PasswordForm*> result; // Empty password store. | |
| 777 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | |
| 778 EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) | |
| 779 .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); | |
| 780 std::vector<PasswordForm> observed; | |
| 781 PasswordForm form(MakeSimpleFormWithOnlyPasswordField()); | |
| 782 observed.push_back(form); | |
| 783 manager()->OnPasswordFormsParsed(observed); // The initial load. | |
| 784 manager()->OnPasswordFormsRendered(observed, true); // The initial layout. | |
| 785 | |
| 786 // 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.
| |
| 787 manager()->SetFormHasGeneratedPassword(form); | |
| 788 manager()->ProvisionallySavePassword(form); | |
| 789 | |
| 790 // 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.
| |
| 791 // consent by using the generated password. The form should be saved once | |
| 792 // navigation occurs. The client will be informed that automatic saving has | |
| 793 // occured. | |
| 794 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.
| |
| 795 EXPECT_CALL(*store_.get(), AddLogin(FormMatches(form))); | |
| 796 scoped_ptr<PasswordFormManager> saved_form_manager; | |
| 797 EXPECT_CALL(client_, AutomaticPasswordSavePtr(_)).Times(Exactly(1)).WillOnce( | |
| 798 WithArg<0>(SaveToScopedPtr(&saved_form_manager))); | |
| 799 | |
| 800 // Now the password manager waits for the navigation to complete. | |
| 801 observed.clear(); | |
| 802 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. | |
| 803 manager()->OnPasswordFormsRendered(observed, | |
| 804 true); // The post-navigation layout. | |
| 805 } | |
| 806 | |
| 761 } // namespace password_manager | 807 } // namespace password_manager |
| OLD | NEW |