Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: components/autofill/core/browser/autofill_external_delegate_unittest.cc

Issue 1458903003: [Autofill] Deduplicate Autocomplete and Datalist suggestions, keeping the latter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/autofill_external_delegate.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_external_delegate_unittest.cc
diff --git a/components/autofill/core/browser/autofill_external_delegate_unittest.cc b/components/autofill/core/browser/autofill_external_delegate_unittest.cc
index 120c0918d4d27cb665fd507d8c594aaab8d0c25c..1803f34733582bc53002561aa313216b9228d638 100644
--- a/components/autofill/core/browser/autofill_external_delegate_unittest.cc
+++ b/components/autofill/core/browser/autofill_external_delegate_unittest.cc
@@ -292,6 +292,84 @@ TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) {
data_list_items);
}
+// Test that we _don't_ de-dupe autofill values against datalist values. We
+// keep both with a separator.
+TEST_F(AutofillExternalDelegateUnitTest, DuplicateAutofillDatalistValues) {
+ IssueOnQuery(kQueryId);
+
+ std::vector<base::string16> data_list_items;
+ data_list_items.push_back(base::ASCIIToUTF16("Rick"));
+ data_list_items.push_back(base::ASCIIToUTF16("Deckard"));
+
+ EXPECT_CALL(autofill_client_, UpdateAutofillPopupDataListValues(
+ data_list_items, data_list_items));
+
+ external_delegate_->SetCurrentDataListValues(data_list_items,
+ data_list_items);
+
+ // The enums must be cast to ints to prevent compile errors on linux_rel.
+ auto element_ids =
+ testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
+ static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
+#if !defined(OS_ANDROID)
+ static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
+#endif
+ kAutofillProfileId,
+#if !defined(OS_ANDROID)
+ static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
+#endif
+ static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS));
+ EXPECT_CALL(autofill_client_,
+ ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _));
+
+ // Have an Autofill item that is identical to one of the datalist entries.
+ std::vector<Suggestion> autofill_item;
+ autofill_item.push_back(Suggestion());
+ autofill_item[0].value = ASCIIToUTF16("Rick");
+ autofill_item[0].frontend_id = kAutofillProfileId;
+ ;
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
+}
+
+// Test that we de-dupe autocomplete values against datalist values, keeping the
+// latter in case of a match.
+TEST_F(AutofillExternalDelegateUnitTest, DuplicateAutocompleteDatalistValues) {
+ IssueOnQuery(kQueryId);
+
+ std::vector<base::string16> data_list_items;
+ data_list_items.push_back(base::ASCIIToUTF16("Rick"));
+ data_list_items.push_back(base::ASCIIToUTF16("Deckard"));
+
+ EXPECT_CALL(autofill_client_, UpdateAutofillPopupDataListValues(
+ data_list_items, data_list_items));
+
+ external_delegate_->SetCurrentDataListValues(data_list_items,
+ data_list_items);
+
+ // The enums must be cast to ints to prevent compile errors on linux_rel.
+ auto element_ids = testing::ElementsAre(
+ // We are expecting only two data list entries.
+ static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
+ static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
+#if !defined(OS_ANDROID)
+ static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
+#endif
+ static_cast<int>(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY));
+ EXPECT_CALL(autofill_client_,
+ ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _));
+
+ // Have an Autocomplete item that is identical to one of the datalist entries
+ // and one that is distinct.
+ std::vector<Suggestion> autocomplete_items;
+ autocomplete_items.push_back(Suggestion());
+ autocomplete_items[0].value = ASCIIToUTF16("Rick");
+ autocomplete_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
+ autocomplete_items.push_back(Suggestion());
+ autocomplete_items[1].value = ASCIIToUTF16("Cain");
+ autocomplete_items[1].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
+ external_delegate_->OnSuggestionsReturned(kQueryId, autocomplete_items);
+}
+
// Test that the Autofill popup is able to display warnings explaining why
// Autofill is disabled for a website.
// Regression test for http://crbug.com/247880
« no previous file with comments | « components/autofill/core/browser/autofill_external_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698