OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_autofill_manager.h" | 5 #include "components/password_manager/core/browser/password_autofill_manager.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/popup_item_ids.h" | 10 #include "components/autofill/core/browser/popup_item_ids.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 PasswordAutofillManagerTest() | 74 PasswordAutofillManagerTest() |
75 : test_username_(base::ASCIIToUTF16(kAliceUsername)), | 75 : test_username_(base::ASCIIToUTF16(kAliceUsername)), |
76 test_password_(base::ASCIIToUTF16(kAlicePassword)), | 76 test_password_(base::ASCIIToUTF16(kAlicePassword)), |
77 fill_data_id_(0) {} | 77 fill_data_id_(0) {} |
78 | 78 |
79 void SetUp() override { | 79 void SetUp() override { |
80 // Add a preferred login and an additional login to the FillData. | 80 // Add a preferred login and an additional login to the FillData. |
81 autofill::FormFieldData username_field; | 81 autofill::FormFieldData username_field; |
82 username_field.name = base::ASCIIToUTF16(kUsernameName); | 82 username_field.name = base::ASCIIToUTF16(kUsernameName); |
83 username_field.value = test_username_; | 83 username_field.value = test_username_; |
84 fill_data_.basic_data.fields.push_back(username_field); | 84 fill_data_.username_field = username_field; |
85 | 85 |
86 autofill::FormFieldData password_field; | 86 autofill::FormFieldData password_field; |
87 password_field.name = base::ASCIIToUTF16(kPasswordName); | 87 password_field.name = base::ASCIIToUTF16(kPasswordName); |
88 password_field.value = test_password_; | 88 password_field.value = test_password_; |
89 fill_data_.basic_data.fields.push_back(password_field); | 89 fill_data_.password_field = password_field; |
90 } | 90 } |
91 | 91 |
92 void InitializePasswordAutofillManager( | 92 void InitializePasswordAutofillManager( |
93 PasswordManagerClient* client, | 93 PasswordManagerClient* client, |
94 autofill::AutofillClient* autofill_client) { | 94 autofill::AutofillClient* autofill_client) { |
95 password_autofill_manager_.reset( | 95 password_autofill_manager_.reset( |
96 new PasswordAutofillManager(client, autofill_client)); | 96 new PasswordAutofillManager(client, autofill_client)); |
97 password_autofill_manager_->OnAddPasswordFormMapping(fill_data_id_, | 97 password_autofill_manager_->OnAddPasswordFormMapping(fill_data_id_, |
98 fill_data_); | 98 fill_data_); |
99 } | 99 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 // Test that the popup is marked as visible after recieving password | 167 // Test that the popup is marked as visible after recieving password |
168 // suggestions. | 168 // suggestions. |
169 TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) { | 169 TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) { |
170 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); | 170 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
171 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); | 171 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
172 InitializePasswordAutofillManager(client.get(), autofill_client.get()); | 172 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
173 | 173 |
174 gfx::RectF element_bounds; | 174 gfx::RectF element_bounds; |
175 autofill::PasswordFormFillData data; | 175 autofill::PasswordFormFillData data; |
176 data.basic_data.fields.resize(2); | 176 data.username_field.value = test_username_; |
177 data.basic_data.fields[0].value = test_username_; | 177 data.password_field.value = test_password_; |
178 data.basic_data.fields[1].value = test_password_; | |
179 data.preferred_realm = "http://foo.com/"; | 178 data.preferred_realm = "http://foo.com/"; |
180 int dummy_key = 0; | 179 int dummy_key = 0; |
181 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); | 180 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
182 | 181 |
183 EXPECT_CALL(*client->mock_driver(), | 182 EXPECT_CALL(*client->mock_driver(), |
184 FillSuggestion(test_username_, test_password_)); | 183 FillSuggestion(test_username_, test_password_)); |
185 | 184 |
186 // The enums must be cast to ints to prevent compile errors on linux_rel. | 185 // The enums must be cast to ints to prevent compile errors on linux_rel. |
187 EXPECT_CALL(*autofill_client, | 186 EXPECT_CALL(*autofill_client, |
188 ShowAutofillPopup( | 187 ShowAutofillPopup( |
(...skipping 16 matching lines...) Expand all Loading... |
205 | 204 |
206 // Test that OnShowPasswordSuggestions correctly matches the given FormFieldData | 205 // Test that OnShowPasswordSuggestions correctly matches the given FormFieldData |
207 // to the known PasswordFormFillData, and extracts the right suggestions. | 206 // to the known PasswordFormFillData, and extracts the right suggestions. |
208 TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) { | 207 TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) { |
209 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); | 208 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
210 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); | 209 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
211 InitializePasswordAutofillManager(client.get(), autofill_client.get()); | 210 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
212 | 211 |
213 gfx::RectF element_bounds; | 212 gfx::RectF element_bounds; |
214 autofill::PasswordFormFillData data; | 213 autofill::PasswordFormFillData data; |
215 data.basic_data.fields.resize(2); | 214 data.username_field.value = test_username_; |
216 data.basic_data.fields[0].value = test_username_; | 215 data.password_field.value = test_password_; |
217 data.basic_data.fields[1].value = test_password_; | |
218 data.preferred_realm = "http://foo.com/"; | 216 data.preferred_realm = "http://foo.com/"; |
219 | 217 |
220 autofill::PasswordAndRealm additional; | 218 autofill::PasswordAndRealm additional; |
221 additional.realm = "https://foobarrealm.org"; | 219 additional.realm = "https://foobarrealm.org"; |
222 base::string16 additional_username(base::ASCIIToUTF16("John Foo")); | 220 base::string16 additional_username(base::ASCIIToUTF16("John Foo")); |
223 data.additional_logins[additional_username] = additional; | 221 data.additional_logins[additional_username] = additional; |
224 | 222 |
225 autofill::UsernamesCollectionKey usernames_key; | 223 autofill::UsernamesCollectionKey usernames_key; |
226 usernames_key.realm = "http://yetanother.net"; | 224 usernames_key.realm = "http://yetanother.net"; |
227 std::vector<base::string16> other_names; | 225 std::vector<base::string16> other_names; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 element_bounds, _, | 257 element_bounds, _, |
260 testing::UnorderedElementsAre( | 258 testing::UnorderedElementsAre( |
261 test_username_, additional_username, other_username), | 259 test_username_, additional_username, other_username), |
262 _, _, _, _)); | 260 _, _, _, _)); |
263 password_autofill_manager_->OnShowPasswordSuggestions( | 261 password_autofill_manager_->OnShowPasswordSuggestions( |
264 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, | 262 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, |
265 element_bounds); | 263 element_bounds); |
266 } | 264 } |
267 | 265 |
268 } // namespace password_manager | 266 } // namespace password_manager |
OLD | NEW |