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" |
11 #include "components/autofill/core/browser/test_autofill_client.h" | 11 #include "components/autofill/core/browser/test_autofill_client.h" |
12 #include "components/autofill/core/browser/test_autofill_driver.h" | 12 #include "components/autofill/core/browser/test_autofill_driver.h" |
13 #include "components/autofill/core/common/form_field_data.h" | 13 #include "components/autofill/core/common/form_field_data.h" |
14 #include "components/autofill/core/common/password_form_fill_data.h" | 14 #include "components/autofill/core/common/password_form_fill_data.h" |
15 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 15 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
16 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 16 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
| 17 #include "components/strings/grit/components_strings.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/gfx/geometry/rect_f.h" | 21 #include "ui/gfx/geometry/rect_f.h" |
20 | 22 |
21 // The name of the username/password element in the form. | 23 // The name of the username/password element in the form. |
22 const char kUsernameName[] = "username"; | 24 const char kUsernameName[] = "username"; |
23 const char kInvalidUsername[] = "no-username"; | 25 const char kInvalidUsername[] = "no-username"; |
24 const char kPasswordName[] = "password"; | 26 const char kPasswordName[] = "password"; |
25 | 27 |
26 const char kAliceUsername[] = "alice"; | 28 const char kAliceUsername[] = "alice"; |
27 const char kAlicePassword[] = "password"; | 29 const char kAlicePassword[] = "password"; |
28 | 30 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 ShowAutofillPopup( | 258 ShowAutofillPopup( |
257 element_bounds, _, | 259 element_bounds, _, |
258 testing::UnorderedElementsAre( | 260 testing::UnorderedElementsAre( |
259 test_username_, additional_username, other_username), | 261 test_username_, additional_username, other_username), |
260 _, _, _, _)); | 262 _, _, _, _)); |
261 password_autofill_manager_->OnShowPasswordSuggestions( | 263 password_autofill_manager_->OnShowPasswordSuggestions( |
262 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, | 264 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, |
263 element_bounds); | 265 element_bounds); |
264 } | 266 } |
265 | 267 |
| 268 TEST_F(PasswordAutofillManagerTest, FillSuggestionPasswordField) { |
| 269 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| 270 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| 271 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| 272 |
| 273 gfx::RectF element_bounds; |
| 274 autofill::PasswordFormFillData data; |
| 275 data.username_field.value = test_username_; |
| 276 data.password_field.value = test_password_; |
| 277 data.preferred_realm = "http://foo.com/"; |
| 278 |
| 279 autofill::PasswordAndRealm additional; |
| 280 additional.realm = "https://foobarrealm.org"; |
| 281 base::string16 additional_username(base::ASCIIToUTF16("John Foo")); |
| 282 data.additional_logins[additional_username] = additional; |
| 283 |
| 284 autofill::UsernamesCollectionKey usernames_key; |
| 285 usernames_key.realm = "http://yetanother.net"; |
| 286 std::vector<base::string16> other_names; |
| 287 base::string16 other_username(base::ASCIIToUTF16("John Different")); |
| 288 other_names.push_back(other_username); |
| 289 data.other_possible_usernames[usernames_key] = other_names; |
| 290 |
| 291 int dummy_key = 0; |
| 292 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| 293 |
| 294 // Simulate displaying suggestions matching a username and specifying that the |
| 295 // field is a password field. |
| 296 base::string16 title = l10n_util::GetStringUTF16( |
| 297 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE); |
| 298 EXPECT_CALL(*autofill_client, |
| 299 ShowAutofillPopup( |
| 300 element_bounds, _, |
| 301 testing::UnorderedElementsAre(title, test_username_), |
| 302 _, _, _, _)); |
| 303 password_autofill_manager_->OnShowPasswordSuggestions( |
| 304 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, |
| 305 autofill::ShowPasswordSuggestionsOptions::IS_PASSWORD_FIELD, |
| 306 element_bounds); |
| 307 } |
| 308 |
266 } // namespace password_manager | 309 } // namespace password_manager |
OLD | NEW |