Chromium Code Reviews| Index: components/password_manager/core/browser/password_autofill_manager_unittest.cc |
| diff --git a/components/password_manager/core/browser/password_autofill_manager_unittest.cc b/components/password_manager/core/browser/password_autofill_manager_unittest.cc |
| index 7dd87dcebc16a8513abdebc3330c5c0e07825268..f5e97c5647003f053a1f84b29d4ae61553444581 100644 |
| --- a/components/password_manager/core/browser/password_autofill_manager_unittest.cc |
| +++ b/components/password_manager/core/browser/password_autofill_manager_unittest.cc |
| @@ -4,6 +4,7 @@ |
| #include "components/password_manager/core/browser/password_autofill_manager.h" |
| +#include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -12,6 +13,7 @@ |
| #include "components/autofill/core/browser/test_autofill_client.h" |
| #include "components/autofill/core/browser/test_autofill_driver.h" |
| #include "components/autofill/core/common/autofill_constants.h" |
| +#include "components/autofill/core/common/autofill_switches.h" |
| #include "components/autofill/core/common/form_field_data.h" |
| #include "components/autofill/core/common/password_form_fill_data.h" |
| #include "components/password_manager/core/browser/stub_password_manager_client.h" |
| @@ -354,4 +356,201 @@ TEST_F(PasswordAutofillManagerTest, FillSuggestionPasswordField) { |
| autofill::IS_PASSWORD_FIELD, element_bounds); |
| } |
| +// Verify that typing "foo" into the username field will match usernames |
| +// "foo.bar@example.com", "bar.foo@example.com" and "example@foo.com". |
| +TEST_F(PasswordAutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { |
| + // Token matching is currently behind a flag. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| + |
| + scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| + scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| + InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| + |
| + gfx::RectF element_bounds; |
| + autofill::PasswordFormFillData data; |
| + base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| + data.username_field.value = username; |
| + data.password_field.value = base::ASCIIToUTF16("foobar"); |
| + data.preferred_realm = "http://foo.com/"; |
| + |
| + autofill::PasswordAndRealm additional; |
| + additional.realm = "https://foobarrealm.org"; |
| + base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| + data.additional_logins[additional_username] = additional; |
| + |
| + autofill::UsernamesCollectionKey usernames_key; |
| + usernames_key.realm = "http://yetanother.net"; |
| + std::vector<base::string16> other_names; |
| + base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| + other_names.push_back(other_username); |
| + data.other_possible_usernames[usernames_key] = other_names; |
| + |
| + int dummy_key = 0; |
| + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| + |
| + // Simulate displaying suggestions for username field contents "foo", check |
| + // that matching usernames "foo.bar@example.com", "bar.foo@example.com" and |
| + // "example@foo.com" are displayed. |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Please delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + EXPECT_CALL( |
| + *autofill_client, |
| + ShowAutofillPopup(element_bounds, _, |
| + SuggestionVectorValuesAre(testing::UnorderedElementsAre( |
| + username, additional_username, other_username)), |
| + _)); |
| + password_autofill_manager_->OnShowPasswordSuggestions( |
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false, |
| + element_bounds); |
| +} |
| + |
| +// Verify that typing "oo" into the username field will not match any usernames |
| +// "foo.bar@example.com", "bar.foo@example.com" or "example@foo.com". |
| +TEST_F(PasswordAutofillManagerTest, NoSuggestionForNonPrefixTokenMatch) { |
| + // Token matching is currently behind a flag. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| + |
| + scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| + scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| + InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| + |
| + gfx::RectF element_bounds; |
| + autofill::PasswordFormFillData data; |
| + base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| + data.username_field.value = username; |
| + data.password_field.value = base::ASCIIToUTF16("foobar"); |
| + data.preferred_realm = "http://foo.com/"; |
| + |
| + autofill::PasswordAndRealm additional; |
| + additional.realm = "https://foobarrealm.org"; |
| + base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| + data.additional_logins[additional_username] = additional; |
| + |
| + autofill::UsernamesCollectionKey usernames_key; |
| + usernames_key.realm = "http://yetanother.net"; |
| + std::vector<base::string16> other_names; |
| + base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| + other_names.push_back(other_username); |
| + data.other_possible_usernames[usernames_key] = other_names; |
| + |
| + int dummy_key = 0; |
| + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| + |
| + // Simulate displaying suggestions for username field contents "oo". Check |
| + // that none appear, because none of the usernames "foo.bar@example.com", |
| + // "bar.foo@example.com" or "example@foo.com" has a token with a prefix "oo". |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Please delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0); |
| + |
| + password_autofill_manager_->OnShowPasswordSuggestions( |
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("oo"), false, |
| + element_bounds); |
| +} |
| + |
| +// Verify that typing "foo@exam" into the username field will not match username |
| +// "bar.foo@example.com" as filed containts span accross multiple tokens. |
|
please use gerrit instead
2015/06/30 19:06:23
s/field contains/field contents
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| +TEST_F(PasswordAutofillManagerTest, |
| + MatchingContentsWithSuggestionTokenSeparator) { |
| + // Token matching is currently behind a flag. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| + |
| + scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| + scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| + InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| + |
| + gfx::RectF element_bounds; |
| + autofill::PasswordFormFillData data; |
| + base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| + data.username_field.value = username; |
| + data.password_field.value = base::ASCIIToUTF16("foobar"); |
| + data.preferred_realm = "http://foo.com/"; |
| + |
| + autofill::PasswordAndRealm additional; |
| + additional.realm = "https://foobarrealm.org"; |
| + base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| + data.additional_logins[additional_username] = additional; |
| + |
| + autofill::UsernamesCollectionKey usernames_key; |
| + usernames_key.realm = "http://yetanother.net"; |
| + std::vector<base::string16> other_names; |
| + base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| + other_names.push_back(other_username); |
| + data.other_possible_usernames[usernames_key] = other_names; |
| + |
| + int dummy_key = 0; |
| + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| + |
| + // Simulate displaying suggestions for field contents "foo@exam". Because "@" |
| + // is a token separator, the field contents cannot be a prefix of any |
| + // suggestion token. Moreover, no suggestion starts with "foo@exam". |
| + // Therefore, no suggestions should match. |
| + EXPECT_CALL(*autofill_client, ShowAutofillPopup(_, _, _, _)).Times(0); |
| + password_autofill_manager_->OnShowPasswordSuggestions( |
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo@exam"), |
| + false, element_bounds); |
| + |
| + // Simulate displaying suggestions for field contents "foo.bar@ex". Because |
| + // "@" is a token separator, the field contents cannot be a prefix of any |
| + // suggestion token. However, the suggestion "foo.bar@example.com" starts with |
| + // "foo.bar@ex". That suggestion should be the only match. |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Please delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + EXPECT_CALL(*autofill_client, |
| + ShowAutofillPopup(element_bounds, _, |
| + SuggestionVectorValuesAre( |
| + testing::UnorderedElementsAre(username)), |
| + _)); |
| + password_autofill_manager_->OnShowPasswordSuggestions( |
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo.bar@ex"), |
| + false, element_bounds); |
| +} |
| + |
| +// Verify that typing "example" into the username field will match and order |
| +// usernames "example@foo.com", "foo.bar@example.com" and "bar.foo@example.com" |
| +// i.e. prefix matched followed by substring matched. |
| +TEST_F(PasswordAutofillManagerTest, |
| + DisplaySuggestionsWithPrefixesPrecedeSubstringMatched) { |
| + // Token matching is currently behind a flag. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| + |
| + scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); |
| + scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |
| + InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
| + |
| + gfx::RectF element_bounds; |
| + autofill::PasswordFormFillData data; |
| + base::string16 username = base::ASCIIToUTF16("foo.bar@example.com"); |
| + data.username_field.value = username; |
| + data.password_field.value = base::ASCIIToUTF16("foobar"); |
| + data.preferred_realm = "http://foo.com/"; |
| + |
| + autofill::PasswordAndRealm additional; |
| + additional.realm = "https://foobarrealm.org"; |
| + base::string16 additional_username(base::ASCIIToUTF16("bar.foo@example.com")); |
| + data.additional_logins[additional_username] = additional; |
| + |
| + autofill::UsernamesCollectionKey usernames_key; |
| + usernames_key.realm = "http://yetanother.net"; |
| + std::vector<base::string16> other_names; |
| + base::string16 other_username(base::ASCIIToUTF16("example@foo.com")); |
| + other_names.push_back(other_username); |
| + data.other_possible_usernames[usernames_key] = other_names; |
| + |
| + int dummy_key = 0; |
| + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
| + |
| + // Simulate displaying suggestions for field contents "example", check that |
| + // matching ones are displayed with prefix matched username "example@foo.com" |
| + // placed before substring matched usernames "foo.bar@example.com" and |
| + // "bar.foo@example.com". |
|
please use gerrit instead
2015/06/30 19:06:23
Redundant comment. Please delete.
Pritam Nikam
2015/07/01 17:26:00
Done.
|
| + EXPECT_CALL( |
| + *autofill_client, |
| + ShowAutofillPopup(element_bounds, _, |
| + SuggestionVectorValuesAre(testing::UnorderedElementsAre( |
| + other_username, username, additional_username)), |
| + _)); |
| + password_autofill_manager_->OnShowPasswordSuggestions( |
| + dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("foo"), false, |
| + element_bounds); |
| +} |
| + |
| } // namespace password_manager |