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