diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 23:23:16 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 23:23:16 +0000 |
commit | 25bacf3dd25367f130baa92895a0c01c3d1d7e13 (patch) | |
tree | 3cd2ce246d1254ae666dcc46992cb04206e6cb1f /chrome/browser/autofill | |
parent | 0452c6e3ee2dcaa67b976398e248a97c59deeede (diff) | |
download | chromium_src-25bacf3dd25367f130baa92895a0c01c3d1d7e13.zip chromium_src-25bacf3dd25367f130baa92895a0c01c3d1d7e13.tar.gz chromium_src-25bacf3dd25367f130baa92895a0c01c3d1d7e13.tar.bz2 |
AutoFill: Don't show labels in the suggestions popup when the user is editing a
field in an auto-filled form.
BUG=47437
TEST=AutoFillManagerTest.GetFieldSuggestionsFormIsAutoFilled
Review URL: http://codereview.chromium.org/2861025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50782 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 9 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 1 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager_unittest.cc | 45 |
3 files changed, 48 insertions, 7 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 15b5ba8..4d489ef 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -121,6 +121,7 @@ void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) { } bool AutoFillManager::GetAutoFillSuggestions(int query_id, + bool form_autofilled, const FormField& field) { if (!IsAutoFillEnabled()) return false; @@ -180,6 +181,14 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id, if (values.empty()) return false; + // If the form is auto-filled and the renderer is querying for suggestions, + // then the user is editing the value of a field. In this case, we don't + // want to display the labels, as that information is redundant. + if (form_autofilled) { + for (size_t i = 0; i < labels.size(); ++i) + labels[i] = string16(); + } + host->AutoFillSuggestionsReturned(query_id, values, labels); return true; } diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index 46ee0f5..f45f7ed 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -49,6 +49,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill, virtual void FormsSeen( const std::vector<webkit_glue::FormData>& forms); virtual bool GetAutoFillSuggestions(int query_id, + bool form_autofilled, const webkit_glue::FormField& field); virtual bool FillAutoFillFormData(int query_id, const webkit_glue::FormData& form, diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index 2435b93..700966d 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -215,7 +215,7 @@ class AutoFillManagerTest : public RenderViewHostTestHarness { Profile* profile() { return contents()->profile(); } - bool GetAutoFillSuggestionsMessage(int *page_id, + bool GetAutoFillSuggestionsMessage(int* page_id, std::vector<string16>* values, std::vector<string16>* labels) { const uint32 kMsgID = ViewMsg_AutoFillSuggestionsReturned::ID; @@ -275,7 +275,7 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) { webkit_glue::FormField field; CreateTestFormField("First Name", "firstname", "", "text", &field); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); // Test that we sent the right message to the renderer. int page_id = 0; @@ -306,7 +306,7 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) { webkit_glue::FormField field; CreateTestFormField("First Name", "firstname", "E", "text", &field); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); // Test that we sent the right message to the renderer. int page_id = 0; @@ -335,7 +335,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { webkit_glue::FormField field; CreateTestFormField("Card Number", "cardnumber", "", "text", &field); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); // Test that we sent the right message to the renderer. int page_id = 0; @@ -374,7 +374,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) { webkit_glue::FormField field; CreateTestFormField("Card Number", "cardnumber", "1", "text", &field); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); // Test that we sent the right message to the renderer. int page_id = 0; @@ -407,7 +407,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) { webkit_glue::FormField field; CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); // Test that we sent the right message to the renderer. int page_id = 0; @@ -448,7 +448,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsSemicolon) { webkit_glue::FormField field; CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); - EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, field)); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); // Test that we sent the right message to the renderer. int page_id = 0; @@ -476,6 +476,37 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsSemicolon) { EXPECT_EQ(ASCIIToUTF16("Home; 8765; 8765"), labels[7]); } +TEST_F(AutoFillManagerTest, GetFieldSuggestionsFormIsAutoFilled) { + FormData form; + CreateTestFormData(&form); + + // Set up our FormStructures. + std::vector<FormData> forms; + forms.push_back(form); + autofill_manager_->FormsSeen(forms); + + // The page ID sent to the AutoFillManager from the RenderView, used to send + // an IPC message back to the renderer. + const int kPageID = 1; + + webkit_glue::FormField field; + CreateTestFormField("First Name", "firstname", "", "text", &field); + EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); + + // Test that we sent the right message to the renderer. + int page_id = 0; + std::vector<string16> values; + std::vector<string16> labels; + EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels)); + EXPECT_EQ(kPageID, page_id); + ASSERT_EQ(2U, values.size()); + EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); + EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); + ASSERT_EQ(2U, labels.size()); + EXPECT_EQ(string16(), labels[0]); + EXPECT_EQ(string16(), labels[1]); +} + TEST_F(AutoFillManagerTest, FillCreditCardForm) { FormData form; CreateTestFormDataBilling(&form); |