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 "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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 .WillRepeatedly(Return(true)); | 104 .WillRepeatedly(Return(true)); |
105 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) | 105 EXPECT_CALL(client_, IsSyncAccountCredential(_, _)) |
106 .WillRepeatedly(Return(false)); | 106 .WillRepeatedly(Return(false)); |
107 EXPECT_CALL(client_, GetPasswordStore()) | 107 EXPECT_CALL(client_, GetPasswordStore()) |
108 .WillRepeatedly(Return(store_.get())); | 108 .WillRepeatedly(Return(store_.get())); |
109 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); | 109 EXPECT_CALL(client_, GetPrefs()).WillRepeatedly(Return(&prefs_)); |
110 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); | 110 EXPECT_CALL(client_, GetDriver()).WillRepeatedly(Return(&driver_)); |
111 | 111 |
112 manager_.reset(new TestPasswordManager(&client_)); | 112 manager_.reset(new TestPasswordManager(&client_)); |
113 password_autofill_manager_.reset( | 113 password_autofill_manager_.reset( |
114 new PasswordAutofillManager(client_.GetDriver(), NULL)); | 114 new PasswordAutofillManager(client_.GetDriver(), nullptr)); |
115 | 115 |
116 EXPECT_CALL(driver_, GetPasswordManager()) | 116 EXPECT_CALL(driver_, GetPasswordManager()) |
117 .WillRepeatedly(Return(manager_.get())); | 117 .WillRepeatedly(Return(manager_.get())); |
118 EXPECT_CALL(driver_, GetPasswordAutofillManager()) | 118 EXPECT_CALL(driver_, GetPasswordAutofillManager()) |
119 .WillRepeatedly(Return(password_autofill_manager_.get())); | 119 .WillRepeatedly(Return(password_autofill_manager_.get())); |
120 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors()) | 120 EXPECT_CALL(client_, DidLastPageLoadEncounterSSLErrors()) |
121 .WillRepeatedly(Return(false)); | 121 .WillRepeatedly(Return(false)); |
122 | 122 |
123 ON_CALL(*store_, GetLogins(_, _, _)) | 123 ON_CALL(*store_, GetLogins(_, _, _)) |
124 .WillByDefault(WithArg<2>(InvokeEmptyConsumer())); | 124 .WillByDefault(WithArg<2>(InvokeEmptyConsumer())); |
125 } | 125 } |
126 | 126 |
127 void TearDown() override { | 127 void TearDown() override { |
128 store_->Shutdown(); | 128 store_->Shutdown(); |
129 store_ = NULL; | 129 store_ = nullptr; |
130 } | 130 } |
131 | 131 |
132 PasswordForm MakeSimpleForm() { | 132 PasswordForm MakeSimpleForm() { |
133 PasswordForm form; | 133 PasswordForm form; |
134 form.origin = GURL("http://www.google.com/a/LoginAuth"); | 134 form.origin = GURL("http://www.google.com/a/LoginAuth"); |
135 form.action = GURL("http://www.google.com/a/Login"); | 135 form.action = GURL("http://www.google.com/a/Login"); |
136 form.username_element = ASCIIToUTF16("Email"); | 136 form.username_element = ASCIIToUTF16("Email"); |
137 form.password_element = ASCIIToUTF16("Passwd"); | 137 form.password_element = ASCIIToUTF16("Passwd"); |
138 form.username_value = ASCIIToUTF16("google"); | 138 form.username_value = ASCIIToUTF16("google"); |
139 form.password_value = ASCIIToUTF16("password"); | 139 form.password_value = ASCIIToUTF16("password"); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 PromptUserToSavePasswordPtr( | 449 PromptUserToSavePasswordPtr( |
450 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) | 450 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) |
451 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 451 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
452 | 452 |
453 observed.clear(); | 453 observed.clear(); |
454 manager()->OnPasswordFormsParsed(&driver_, | 454 manager()->OnPasswordFormsParsed(&driver_, |
455 observed); // The post-navigation load. | 455 observed); // The post-navigation load. |
456 manager()->OnPasswordFormsRendered(&driver_, observed, | 456 manager()->OnPasswordFormsRendered(&driver_, observed, |
457 true); // The post-navigation layout. | 457 true); // The post-navigation layout. |
458 | 458 |
459 ASSERT_FALSE(NULL == form_to_save.get()); | 459 ASSERT_TRUE(form_to_save); |
460 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); | 460 EXPECT_CALL(*store_, AddLogin(FormMatches(form))); |
461 | 461 |
462 // Simulate saving the form, as if the info bar was accepted. | 462 // Simulate saving the form, as if the info bar was accepted. |
463 form_to_save->Save(); | 463 form_to_save->Save(); |
464 } | 464 } |
465 | 465 |
466 // This test verifies a fix for http://crbug.com/236673 | 466 // This test verifies a fix for http://crbug.com/236673 |
467 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { | 467 TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
468 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); | 468 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
469 PasswordForm first_form(MakeSimpleForm()); | 469 PasswordForm first_form(MakeSimpleForm()); |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 scoped_ptr<PasswordFormManager> form_to_save; | 931 scoped_ptr<PasswordFormManager> form_to_save; |
932 EXPECT_CALL(client_, | 932 EXPECT_CALL(client_, |
933 PromptUserToSavePasswordPtr( | 933 PromptUserToSavePasswordPtr( |
934 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) | 934 _, CredentialSourceType::CREDENTIAL_SOURCE_PASSWORD_MANAGER)) |
935 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); | 935 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save))); |
936 | 936 |
937 manager()->OnInPageNavigation(&driver_, form); | 937 manager()->OnInPageNavigation(&driver_, form); |
938 } | 938 } |
939 | 939 |
940 } // namespace password_manager | 940 } // namespace password_manager |
OLD | NEW |