OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 autofill_test::CreateTestFormField("Color", "color", "", "text", &field); | 595 autofill_test::CreateTestFormField("Color", "color", "", "text", &field); |
596 form.fields.push_back(field); | 596 form.fields.push_back(field); |
597 | 597 |
598 std::vector<FormData> forms(1, form); | 598 std::vector<FormData> forms(1, form); |
599 autofill_manager_->FormsSeen(forms); | 599 autofill_manager_->FormsSeen(forms); |
600 | 600 |
601 rvh()->ResetAutoFillState(kDefaultPageID); | 601 rvh()->ResetAutoFillState(kDefaultPageID); |
602 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); | 602 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
603 } | 603 } |
604 | 604 |
| 605 // Test that we cull duplicate profile suggestions. |
| 606 TEST_F(AutoFillManagerTest, GetProfileSuggestionsWithDuplicates) { |
| 607 // Set up our form data. |
| 608 FormData form; |
| 609 CreateTestAddressFormData(&form); |
| 610 std::vector<FormData> forms(1, form); |
| 611 autofill_manager_->FormsSeen(forms); |
| 612 |
| 613 // Add a duplicate profile. |
| 614 AutoFillProfile* duplicate_profile = static_cast<AutoFillProfile*>( |
| 615 autofill_manager_->GetLabeledProfile("Home")->Clone()); |
| 616 autofill_manager_->AddProfile(duplicate_profile); |
| 617 |
| 618 const FormField& field = form.fields[0]; |
| 619 rvh()->ResetAutoFillState(kDefaultPageID); |
| 620 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field)); |
| 621 |
| 622 // No suggestions provided, so send an empty vector as the results. |
| 623 // This triggers the combined message send. |
| 624 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 625 |
| 626 // Test that we sent the right message to the renderer. |
| 627 int page_id = 0; |
| 628 std::vector<string16> values; |
| 629 std::vector<string16> labels; |
| 630 std::vector<string16> icons; |
| 631 std::vector<int> unique_ids; |
| 632 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons, |
| 633 &unique_ids)); |
| 634 |
| 635 string16 expected_values[] = { |
| 636 ASCIIToUTF16("Elvis"), |
| 637 ASCIIToUTF16("Charles") |
| 638 }; |
| 639 string16 expected_labels[] = { |
| 640 ASCIIToUTF16("3734 Elvis Presley Blvd."), |
| 641 ASCIIToUTF16("123 Apple St.") |
| 642 }; |
| 643 string16 expected_icons[] = {string16(), string16()}; |
| 644 int expected_unique_ids[] = {1, 2}; |
| 645 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| 646 kDefaultPageID, arraysize(expected_values), expected_values, |
| 647 expected_labels, expected_icons, expected_unique_ids); |
| 648 } |
| 649 |
605 // Test that we return no suggestions when autofill is disabled. | 650 // Test that we return no suggestions when autofill is disabled. |
606 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { | 651 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { |
607 // Set up our form data. | 652 // Set up our form data. |
608 FormData form; | 653 FormData form; |
609 CreateTestAddressFormData(&form); | 654 CreateTestAddressFormData(&form); |
610 std::vector<FormData> forms(1, form); | 655 std::vector<FormData> forms(1, form); |
611 autofill_manager_->FormsSeen(forms); | 656 autofill_manager_->FormsSeen(forms); |
612 | 657 |
613 // Disable AutoFill. | 658 // Disable AutoFill. |
614 autofill_manager_->set_autofill_enabled(false); | 659 autofill_manager_->set_autofill_enabled(false); |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1567 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1523 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1568 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1524 profile()->GetPrefs()->SetBoolean( | 1569 profile()->GetPrefs()->SetBoolean( |
1525 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1570 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
1526 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1571 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
1527 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1572 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1528 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1573 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1529 #endif | 1574 #endif |
1530 } | 1575 } |
1531 | 1576 |
OLD | NEW |