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

Side by Side 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: Initial 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 // The enums must be cast to ints to prevent compile errors on linux_rel. 286 // The enums must be cast to ints to prevent compile errors on linux_rel.
287 EXPECT_CALL( 287 EXPECT_CALL(
288 autofill_client_, 288 autofill_client_,
289 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); 289 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
290 290
291 external_delegate_->SetCurrentDataListValues(data_list_items, 291 external_delegate_->SetCurrentDataListValues(data_list_items,
292 data_list_items); 292 data_list_items);
293 } 293 }
294 294
295 // Test that we _don't_ de-dupe autofill values against datalist values. We
296 // keep both with a separator.
297 TEST_F(AutofillExternalDelegateUnitTest, DuplicateAutofillDatalistValues) {
298 IssueOnQuery(kQueryId);
299
300 std::vector<base::string16> data_list_items;
301 data_list_items.push_back(base::ASCIIToUTF16("Rick"));
302 data_list_items.push_back(base::ASCIIToUTF16("Deckard"));
303
304 EXPECT_CALL(
305 autofill_client_,
306 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
307
308 external_delegate_->SetCurrentDataListValues(data_list_items,
309 data_list_items);
310
311 // The enums must be cast to ints to prevent compile errors on linux_rel.
312 auto element_ids = testing::ElementsAre(
313 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
314 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
315 #if !defined(OS_ANDROID)
316 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
317 #endif
318 kAutofillProfileId,
319 #if !defined(OS_ANDROID)
320 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
321 #endif
322 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS));
323 EXPECT_CALL(
324 autofill_client_,
325 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _));
326
327 // Have an Autofill item that is identical to one of the datalist entries.
328 std::vector<Suggestion> autofill_item;
329 autofill_item.push_back(Suggestion());
330 autofill_item[0].value = ASCIIToUTF16("Rick");
331 autofill_item[0].frontend_id = kAutofillProfileId;;
332 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item);
333 }
334
335 // Test that we de-dupe autocomplete values against datalist values, keeping the
336 // latter in case of a match.
337 TEST_F(AutofillExternalDelegateUnitTest, DuplicateAutocompleteDatalistValues) {
338 IssueOnQuery(kQueryId);
339
340 std::vector<base::string16> data_list_items;
341 data_list_items.push_back(base::ASCIIToUTF16("Rick"));
342 data_list_items.push_back(base::ASCIIToUTF16("Deckard"));
343
344 EXPECT_CALL(
345 autofill_client_,
346 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
347
348 external_delegate_->SetCurrentDataListValues(data_list_items,
349 data_list_items);
350
351 // The enums must be cast to ints to prevent compile errors on linux_rel.
352 auto element_ids = testing::ElementsAre(
353 // We are expecting only two data list entries.
354 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
355 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
356 #if !defined(OS_ANDROID)
357 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
358 #endif
359 static_cast<int>(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY)
360 );
361 EXPECT_CALL(
362 autofill_client_,
363 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _));
364
365 // Have an Autocomplete item that is identical to one of the datalist entries
366 // and one that is distinct.
367 std::vector<Suggestion> autocomplete_items;
368 autocomplete_items.push_back(Suggestion());
369 autocomplete_items[0].value = ASCIIToUTF16("Rick");
370 autocomplete_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
371 autocomplete_items.push_back(Suggestion());
372 autocomplete_items[1].value = ASCIIToUTF16("Cain");
373 autocomplete_items[1].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY;
374 external_delegate_->OnSuggestionsReturned(kQueryId, autocomplete_items);
375 }
376
295 // Test that the Autofill popup is able to display warnings explaining why 377 // Test that the Autofill popup is able to display warnings explaining why
296 // Autofill is disabled for a website. 378 // Autofill is disabled for a website.
297 // Regression test for http://crbug.com/247880 379 // Regression test for http://crbug.com/247880
298 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { 380 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) {
299 IssueOnQuery(kQueryId); 381 IssueOnQuery(kQueryId);
300 382
301 // The enums must be cast to ints to prevent compile errors on linux_rel. 383 // The enums must be cast to ints to prevent compile errors on linux_rel.
302 EXPECT_CALL( 384 EXPECT_CALL(
303 autofill_client_, 385 autofill_client_,
304 ShowAutofillPopup( 386 ShowAutofillPopup(
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 RendererShouldFillFieldWithValue(dummy_string)); 598 RendererShouldFillFieldWithValue(dummy_string));
517 base::HistogramTester histogram_tester; 599 base::HistogramTester histogram_tester;
518 external_delegate_->DidAcceptSuggestion(dummy_string, 600 external_delegate_->DidAcceptSuggestion(dummy_string,
519 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, 601 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY,
520 0); 602 0);
521 histogram_tester.ExpectUniqueSample( 603 histogram_tester.ExpectUniqueSample(
522 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); 604 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1);
523 } 605 }
524 606
525 } // namespace autofill 607 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698