diff options
author | engedy <engedy@chromium.org> | 2015-03-18 08:28:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-18 15:29:16 +0000 |
commit | 23445b31b84396a79d77c16fe700aedaf393d9f6 (patch) | |
tree | 889e608385c3b1aa536f977611f778e3c73ca101 /components/password_manager | |
parent | 169cd7a1c2b202035401edcbb291a61d891ca4eb (diff) | |
download | chromium_src-23445b31b84396a79d77c16fe700aedaf393d9f6.zip chromium_src-23445b31b84396a79d77c16fe700aedaf393d9f6.tar.gz chromium_src-23445b31b84396a79d77c16fe700aedaf393d9f6.tar.bz2 |
Prettify Android application realms in autofill suggestions.
BUG=437865
Review URL: https://codereview.chromium.org/1021453002
Cr-Commit-Position: refs/heads/master@{#321137}
Diffstat (limited to 'components/password_manager')
-rw-r--r-- | components/password_manager/core/browser/password_autofill_manager.cc | 18 | ||||
-rw-r--r-- | components/password_manager/core/browser/password_autofill_manager_unittest.cc | 54 |
2 files changed, 66 insertions, 6 deletions
diff --git a/components/password_manager/core/browser/password_autofill_manager.cc b/components/password_manager/core/browser/password_autofill_manager.cc index 3095dd3..15d5f7e 100644 --- a/components/password_manager/core/browser/password_autofill_manager.cc +++ b/components/password_manager/core/browser/password_autofill_manager.cc @@ -15,6 +15,7 @@ #include "components/autofill/core/browser/suggestion.h" #include "components/autofill/core/common/autofill_constants.h" #include "components/autofill/core/common/autofill_data_validation.h" +#include "components/password_manager/core/browser/affiliation_utils.h" #include "components/password_manager/core/browser/password_manager_driver.h" #include "components/strings/grit/components_strings.h" #include "grit/components_strings.h" @@ -45,6 +46,17 @@ base::string16 ReplaceEmptyUsername(const base::string16& username) { return username; } +// Returns the prettified version of |signon_realm| to be displayed on the UI. +base::string16 GetHumanReadableRealm(const std::string& signon_realm) { + // For Android application realms, remove the hash component. Otherwise, make + // no changes. + FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm)); + if (maybe_facet_uri.IsValidAndroidFacetURI()) + return base::UTF8ToUTF16("android://" + + maybe_facet_uri.android_package_name() + "/"); + return base::UTF8ToUTF16(signon_realm); +} + // This function attempts to fill |suggestions| and |realms| form |fill_data| // based on |current_username|. Unless |show_all| is true, it only picks // suggestions where the username has |current_username| as a prefix. @@ -56,7 +68,7 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data, StartsWith(fill_data.username_field.value, current_username, false)) { autofill::Suggestion suggestion( ReplaceEmptyUsername(fill_data.username_field.value)); - suggestion.label = base::UTF8ToUTF16(fill_data.preferred_realm); + suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; suggestions->push_back(suggestion); } @@ -64,7 +76,7 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data, for (const auto& login : fill_data.additional_logins) { if (show_all || StartsWith(login.first, current_username, false)) { autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); - suggestion.label = base::UTF8ToUTF16(login.second.realm); + suggestion.label = GetHumanReadableRealm(login.second.realm); suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; suggestions->push_back(suggestion); } @@ -76,7 +88,7 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data, StartsWith(usernames.second[i], current_username, false)) { autofill::Suggestion suggestion( ReplaceEmptyUsername(usernames.second[i])); - suggestion.label = base::UTF8ToUTF16(usernames.first.realm); + suggestion.label = GetHumanReadableRealm(usernames.first.realm); suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; suggestions->push_back(suggestion); } 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 dc8563e..d811161 100644 --- a/components/password_manager/core/browser/password_autofill_manager_unittest.cc +++ b/components/password_manager/core/browser/password_autofill_manager_unittest.cc @@ -33,6 +33,7 @@ const char kAlicePassword[] = "password"; using autofill::Suggestion; using autofill::SuggestionVectorIdsAre; using autofill::SuggestionVectorValuesAre; +using autofill::SuggestionVectorLabelsAre; using testing::_; namespace autofill { @@ -229,12 +230,19 @@ TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) { int dummy_key = 0; password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); - // First, simulate displaying suggestions matching an empty prefix. + // First, simulate displaying suggestions matching an empty prefix. Also + // verify that both the values and labels are filled correctly. The 'value' + // should be the user name; the 'label' should be the realm. EXPECT_CALL(*autofill_client, ShowAutofillPopup( element_bounds, _, - SuggestionVectorValuesAre(testing::UnorderedElementsAre( - test_username_, additional_username, other_username)), + testing::AllOf( + SuggestionVectorValuesAre(testing::UnorderedElementsAre( + test_username_, additional_username, other_username)), + SuggestionVectorLabelsAre(testing::UnorderedElementsAre( + base::UTF8ToUTF16(data.preferred_realm), + base::UTF8ToUTF16(additional.realm), + base::UTF8ToUTF16(usernames_key.realm)))), _)); password_autofill_manager_->OnShowPasswordSuggestions( dummy_key, base::i18n::RIGHT_TO_LEFT, base::string16(), false, @@ -264,6 +272,46 @@ TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) { element_bounds); } +// Verify that, for Android application credentials, the prettified realms of +// applications are displayed as the labels of suggestions on the UI (for +// matches of all levels of preferredness). +TEST_F(PasswordAutofillManagerTest, PrettifiedAndroidRealmsAreShownAsLabels) { + scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); + scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); + InitializePasswordAutofillManager(client.get(), autofill_client.get()); + + autofill::PasswordFormFillData data; + data.username_field.value = test_username_; + data.preferred_realm = "android://hash@com.example1.android/"; + + autofill::PasswordAndRealm additional; + additional.realm = "android://hash@com.example2.android/"; + base::string16 additional_username(base::ASCIIToUTF16("John Foo")); + data.additional_logins[additional_username] = additional; + + autofill::UsernamesCollectionKey usernames_key; + usernames_key.realm = "android://hash@com.example3.android/"; + std::vector<base::string16> other_names; + base::string16 other_username(base::ASCIIToUTF16("John Different")); + other_names.push_back(other_username); + data.other_possible_usernames[usernames_key] = other_names; + + const int dummy_key = 0; + password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); + + EXPECT_CALL( + *autofill_client, + ShowAutofillPopup( + _, _, SuggestionVectorLabelsAre(testing::UnorderedElementsAre( + base::ASCIIToUTF16("android://com.example1.android/"), + base::ASCIIToUTF16("android://com.example2.android/"), + base::ASCIIToUTF16("android://com.example3.android/"))), + _)); + password_autofill_manager_->OnShowPasswordSuggestions( + dummy_key, base::i18n::RIGHT_TO_LEFT, base::string16(), false, + gfx::RectF()); +} + TEST_F(PasswordAutofillManagerTest, FillSuggestionPasswordField) { scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); |