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/command_line.h" | |
7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/popup_item_ids.h" | 11 #include "components/autofill/core/browser/popup_item_ids.h" |
11 #include "components/autofill/core/browser/suggestion_test_helpers.h" | 12 #include "components/autofill/core/browser/suggestion_test_helpers.h" |
12 #include "components/autofill/core/browser/test_autofill_client.h" | 13 #include "components/autofill/core/browser/test_autofill_client.h" |
13 #include "components/autofill/core/browser/test_autofill_driver.h" | 14 #include "components/autofill/core/browser/test_autofill_driver.h" |
14 #include "components/autofill/core/common/autofill_constants.h" | 15 #include "components/autofill/core/common/autofill_constants.h" |
16 #include "components/autofill/core/common/autofill_switches.h" | |
15 #include "components/autofill/core/common/form_field_data.h" | 17 #include "components/autofill/core/common/form_field_data.h" |
16 #include "components/autofill/core/common/password_form_fill_data.h" | 18 #include "components/autofill/core/common/password_form_fill_data.h" |
17 #include "components/password_manager/core/browser/stub_password_manager_client. h" | 19 #include "components/password_manager/core/browser/stub_password_manager_client. h" |
18 #include "components/password_manager/core/browser/stub_password_manager_driver. h" | 20 #include "components/password_manager/core/browser/stub_password_manager_driver. h" |
19 #include "components/strings/grit/components_strings.h" | 21 #include "components/strings/grit/components_strings.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/geometry/rect_f.h" | 25 #include "ui/gfx/geometry/rect_f.h" |
24 | 26 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 element_bounds, _, | 349 element_bounds, _, |
348 SuggestionVectorValuesAre(testing::UnorderedElementsAre( | 350 SuggestionVectorValuesAre(testing::UnorderedElementsAre( |
349 title, | 351 title, |
350 test_username_)), | 352 test_username_)), |
351 _)); | 353 _)); |
352 password_autofill_manager_->OnShowPasswordSuggestions( | 354 password_autofill_manager_->OnShowPasswordSuggestions( |
353 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, | 355 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, |
354 autofill::IS_PASSWORD_FIELD, element_bounds); | 356 autofill::IS_PASSWORD_FIELD, element_bounds); |
355 } | 357 } |
356 | 358 |
359 // Test that when |kEnableSuggestionsWithSubStringMatch| command line switch is | |
360 // on we return only sub-string matching username suggestions when the selected | |
vabr (Chromium)
2015/03/23 14:17:33
Just writing "only" makes it not clear which cases
Pritam Nikam
2015/03/24 11:39:37
Done.
| |
361 // form field has been partially filled out. | |
362 TEST_F(PasswordAutofillManagerTest, ExtractSuggestionsWithSubStringMatch) { | |
363 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
364 autofill::switches::kEnableSuggestionsWithSubStringMatch); | |
365 | |
366 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); | |
367 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); | |
368 InitializePasswordAutofillManager(client.get(), autofill_client.get()); | |
369 | |
370 gfx::RectF element_bounds; | |
371 autofill::PasswordFormFillData data; | |
372 base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); | |
373 data.username_field.value = username; | |
374 data.password_field.value = base::ASCIIToUTF16("foobar"); | |
375 data.preferred_realm = "http://foo.com/"; | |
376 | |
377 autofill::PasswordAndRealm additional; | |
378 additional.realm = "https://foobarrealm.org"; | |
379 base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); | |
380 data.additional_logins[additional_username] = additional; | |
381 | |
382 autofill::UsernamesCollectionKey usernames_key; | |
383 usernames_key.realm = "http://yetanother.net"; | |
384 std::vector<base::string16> other_names; | |
385 base::string16 other_username1(base::ASCIIToUTF16("example@foo.com")); | |
386 other_names.push_back(other_username1); | |
387 base::string16 other_username2(base::ASCIIToUTF16("example@bar.com")); | |
388 other_names.push_back(other_username2); | |
389 data.other_possible_usernames[usernames_key] = other_names; | |
390 | |
391 int dummy_key = 0; | |
392 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); | |
393 | |
394 // Simulate displaying suggestions with sub-string matching "foo". | |
395 EXPECT_CALL( | |
396 *autofill_client, | |
397 ShowAutofillPopup(element_bounds, _, | |
398 SuggestionVectorValuesAre(testing::UnorderedElementsAre( | |
399 username, additional_username, other_username1)), | |
400 _)); | |
401 password_autofill_manager_->OnShowPasswordSuggestions( | |
402 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false, | |
403 element_bounds); | |
404 } | |
405 | |
357 } // namespace password_manager | 406 } // namespace password_manager |
OLD | NEW |