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 c2056c148ae8c99edb23477c57230906c9bcfaf6..ab09812d3429900d2393a1e68681d145164296c5 100644 |
--- a/components/password_manager/core/browser/password_autofill_manager_unittest.cc |
+++ b/components/password_manager/core/browser/password_autofill_manager_unittest.cc |
@@ -2,13 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "components/password_manager/core/browser/password_autofill_manager.h" |
+ |
#include "base/compiler_specific.h" |
#include "base/message_loop/message_loop.h" |
#include "base/strings/utf_string_conversions.h" |
#include "components/autofill/core/browser/popup_item_ids.h" |
#include "components/autofill/core/browser/test_autofill_client.h" |
#include "components/autofill/core/browser/test_autofill_driver.h" |
-#include "components/password_manager/core/browser/password_autofill_manager.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" |
#include "components/password_manager/core/browser/stub_password_manager_driver.h" |
#include "testing/gmock/include/gmock/gmock.h" |
@@ -167,10 +170,16 @@ TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) { |
InitializePasswordAutofillManager(client.get(), autofill_client.get()); |
gfx::RectF element_bounds; |
- std::vector<base::string16> suggestions; |
- suggestions.push_back(test_username_); |
- std::vector<base::string16> realms; |
- realms.push_back(base::ASCIIToUTF16("http://foo.com/")); |
+ autofill::PasswordFormFillData data; |
+ data.basic_data.fields.resize(2); |
+ data.basic_data.fields[0].value = test_username_; |
+ data.basic_data.fields[1].value = test_password_; |
+ data.preferred_realm = "http://foo.com/"; |
+ autofill::FormFieldData dummy_key; |
+ password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
+ |
+ EXPECT_CALL(*client->mock_driver(), |
+ FillSuggestion(test_username_, test_password_)); |
// The enums must be cast to ints to prevent compile errors on linux_rel. |
EXPECT_CALL(*autofill_client, |
@@ -183,12 +192,71 @@ TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) { |
testing::ElementsAre(autofill::POPUP_ITEM_ID_PASSWORD_ENTRY), |
_)); |
password_autofill_manager_->OnShowPasswordSuggestions( |
- username_field_, element_bounds, suggestions, realms); |
+ dummy_key, base::string16(), false, element_bounds); |
// Accepting a suggestion should trigger a call to hide the popup. |
EXPECT_CALL(*autofill_client, HideAutofillPopup()); |
password_autofill_manager_->DidAcceptSuggestion( |
- suggestions[0], autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); |
+ test_username_, autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); |
+} |
+ |
+// Test that OnShowPasswordSuggestions correctly matches the given FormFieldData |
+// to the known PasswordFormFillData, and extracts the right suggestions. |
+TEST_F(PasswordAutofillManagerTest, ExtractSuggestions) { |
+ 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; |
+ data.basic_data.fields.resize(2); |
+ data.basic_data.fields[0].value = test_username_; |
+ data.basic_data.fields[1].value = test_password_; |
+ data.preferred_realm = "http://foo.com/"; |
+ |
+ autofill::PasswordAndRealm additional; |
+ additional.realm = "https://foobarrealm.org"; |
+ base::string16 additional_username(base::ASCIIToUTF16("John Foo")); |
+ 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("John Different")); |
+ other_names.push_back(other_username); |
+ data.other_possible_usernames[usernames_key] = other_names; |
+ |
+ autofill::FormFieldData dummy_key; |
+ password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data); |
+ |
+ // First, simulate displaying suggestions matching an empty prefix. |
+ EXPECT_CALL(*autofill_client, |
+ ShowAutofillPopup( |
+ element_bounds, _, |
+ testing::UnorderedElementsAre( |
+ test_username_, additional_username, other_username), |
+ _, _, _, _)); |
+ password_autofill_manager_->OnShowPasswordSuggestions( |
+ dummy_key, base::string16(), false, element_bounds); |
+ |
+ // Now simulate displaying suggestions matching "John". |
+ EXPECT_CALL(*autofill_client, |
+ ShowAutofillPopup(element_bounds, _, |
+ testing::UnorderedElementsAre( |
+ additional_username, other_username), |
+ _, _, _, _)); |
+ password_autofill_manager_->OnShowPasswordSuggestions( |
+ dummy_key, base::ASCIIToUTF16("John"), false, element_bounds); |
+ |
+ // Finally, simulate displaying all suggestions, without any prefix matching. |
+ EXPECT_CALL(*autofill_client, |
+ ShowAutofillPopup( |
+ element_bounds, _, |
+ testing::UnorderedElementsAre( |
+ test_username_, additional_username, other_username), |
+ _, _, _, _)); |
+ password_autofill_manager_->OnShowPasswordSuggestions( |
+ dummy_key, base::ASCIIToUTF16("xyz"), true, element_bounds); |
} |
} // namespace password_manager |