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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 ShowAutofillPopup( | 256 ShowAutofillPopup( |
255 element_bounds, _, | 257 element_bounds, _, |
256 testing::UnorderedElementsAre( | 258 testing::UnorderedElementsAre( |
257 test_username_, additional_username, other_username), | 259 test_username_, additional_username, other_username), |
258 _, _, _, _)); | 260 _, _, _, _)); |
259 password_autofill_manager_->OnShowPasswordSuggestions( | 261 password_autofill_manager_->OnShowPasswordSuggestions( |
260 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, | 262 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, |
261 element_bounds); | 263 element_bounds); |
262 } | 264 } |
263 | 265 |
| 266 TEST_F(PasswordAutofillManagerTest, FillSuggestionPasswordField) { |
| 267 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| 268 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| 269 InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| 270 |
| 271 gfx::RectF element_bounds; |
| 272 autofill::PasswordFormFillData data; |
| 273 data.username_field.value = test_username_; |
| 274 data.password_field.value = test_password_; |
| 275 data.preferred_realm = "http://foo.com/"; |
| 276 |
| 277 autofill::PasswordAndRealm additional; |
| 278 additional.realm = "https://foobarrealm.org"; |
| 279 base::string16 additional_username(base::ASCIIToUTF16("John Foo")); |
| 280 data.additional_logins[additional_username] = additional; |
| 281 |
| 282 autofill::UsernamesCollectionKey usernames_key; |
| 283 usernames_key.realm = "http://yetanother.net"; |
| 284 std::vector<base::string16> other_names; |
| 285 base::string16 other_username(base::ASCIIToUTF16("John Different")); |
| 286 other_names.push_back(other_username); |
| 287 data.other_possible_usernames[usernames_key] = other_names; |
| 288 |
| 289 int dummy_key = 0; |
| 290 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| 291 |
| 292 // Simulate displaying suggestions matching a username and specifying that the |
| 293 // field is a password field. |
| 294 base::string16 title = l10n_util::GetStringUTF16( |
| 295 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE); |
| 296 EXPECT_CALL(*autofill_client, |
| 297 ShowAutofillPopup( |
| 298 element_bounds, _, |
| 299 testing::UnorderedElementsAre(title, test_username_), |
| 300 _, _, _, _)); |
| 301 password_autofill_manager_->OnShowPasswordSuggestions( |
| 302 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, |
| 303 autofill::ShowPasswordSuggestionsOptions::IS_PASSWORD_FIELD, |
| 304 element_bounds); |
| 305 } |
| 306 |
264 } // namespace password_manager | 307 } // namespace password_manager |
OLD | NEW |