OLD | NEW |
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 Loading... |
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(autofill_client_, UpdateAutofillPopupDataListValues( |
| 305 data_list_items, data_list_items)); |
| 306 |
| 307 external_delegate_->SetCurrentDataListValues(data_list_items, |
| 308 data_list_items); |
| 309 |
| 310 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 311 auto element_ids = |
| 312 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
| 313 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
| 314 #if !defined(OS_ANDROID) |
| 315 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 316 #endif |
| 317 kAutofillProfileId, |
| 318 #if !defined(OS_ANDROID) |
| 319 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 320 #endif |
| 321 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)); |
| 322 EXPECT_CALL(autofill_client_, |
| 323 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _)); |
| 324 |
| 325 // Have an Autofill item that is identical to one of the datalist entries. |
| 326 std::vector<Suggestion> autofill_item; |
| 327 autofill_item.push_back(Suggestion()); |
| 328 autofill_item[0].value = ASCIIToUTF16("Rick"); |
| 329 autofill_item[0].frontend_id = kAutofillProfileId; |
| 330 ; |
| 331 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
| 332 } |
| 333 |
| 334 // Test that we de-dupe autocomplete values against datalist values, keeping the |
| 335 // latter in case of a match. |
| 336 TEST_F(AutofillExternalDelegateUnitTest, DuplicateAutocompleteDatalistValues) { |
| 337 IssueOnQuery(kQueryId); |
| 338 |
| 339 std::vector<base::string16> data_list_items; |
| 340 data_list_items.push_back(base::ASCIIToUTF16("Rick")); |
| 341 data_list_items.push_back(base::ASCIIToUTF16("Deckard")); |
| 342 |
| 343 EXPECT_CALL(autofill_client_, UpdateAutofillPopupDataListValues( |
| 344 data_list_items, data_list_items)); |
| 345 |
| 346 external_delegate_->SetCurrentDataListValues(data_list_items, |
| 347 data_list_items); |
| 348 |
| 349 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 350 auto element_ids = testing::ElementsAre( |
| 351 // We are expecting only two data list entries. |
| 352 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
| 353 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
| 354 #if !defined(OS_ANDROID) |
| 355 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 356 #endif |
| 357 static_cast<int>(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY)); |
| 358 EXPECT_CALL(autofill_client_, |
| 359 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _)); |
| 360 |
| 361 // Have an Autocomplete item that is identical to one of the datalist entries |
| 362 // and one that is distinct. |
| 363 std::vector<Suggestion> autocomplete_items; |
| 364 autocomplete_items.push_back(Suggestion()); |
| 365 autocomplete_items[0].value = ASCIIToUTF16("Rick"); |
| 366 autocomplete_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
| 367 autocomplete_items.push_back(Suggestion()); |
| 368 autocomplete_items[1].value = ASCIIToUTF16("Cain"); |
| 369 autocomplete_items[1].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
| 370 external_delegate_->OnSuggestionsReturned(kQueryId, autocomplete_items); |
| 371 } |
| 372 |
295 // Test that the Autofill popup is able to display warnings explaining why | 373 // Test that the Autofill popup is able to display warnings explaining why |
296 // Autofill is disabled for a website. | 374 // Autofill is disabled for a website. |
297 // Regression test for http://crbug.com/247880 | 375 // Regression test for http://crbug.com/247880 |
298 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { | 376 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { |
299 IssueOnQuery(kQueryId); | 377 IssueOnQuery(kQueryId); |
300 | 378 |
301 // The enums must be cast to ints to prevent compile errors on linux_rel. | 379 // The enums must be cast to ints to prevent compile errors on linux_rel. |
302 EXPECT_CALL( | 380 EXPECT_CALL( |
303 autofill_client_, | 381 autofill_client_, |
304 ShowAutofillPopup( | 382 ShowAutofillPopup( |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 RendererShouldFillFieldWithValue(dummy_string)); | 594 RendererShouldFillFieldWithValue(dummy_string)); |
517 base::HistogramTester histogram_tester; | 595 base::HistogramTester histogram_tester; |
518 external_delegate_->DidAcceptSuggestion(dummy_string, | 596 external_delegate_->DidAcceptSuggestion(dummy_string, |
519 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, | 597 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, |
520 0); | 598 0); |
521 histogram_tester.ExpectUniqueSample( | 599 histogram_tester.ExpectUniqueSample( |
522 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); | 600 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); |
523 } | 601 } |
524 | 602 |
525 } // namespace autofill | 603 } // namespace autofill |
OLD | NEW |