| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 test::CreateTestAddressFormData(&form); | 1379 test::CreateTestAddressFormData(&form); |
| 1380 std::vector<FormData> forms(1, form); | 1380 std::vector<FormData> forms(1, form); |
| 1381 FormsSeen(forms); | 1381 FormsSeen(forms); |
| 1382 | 1382 |
| 1383 // |profile| will be owned by the mock PersonalDataManager. | 1383 // |profile| will be owned by the mock PersonalDataManager. |
| 1384 AutofillProfile* profile = new AutofillProfile; | 1384 AutofillProfile* profile = new AutofillProfile; |
| 1385 test::SetProfileInfo(profile, "Elvis", "", "Presley", "me@x.com", "", | 1385 test::SetProfileInfo(profile, "Elvis", "", "Presley", "me@x.com", "", |
| 1386 "", "", "", "", "", "", ""); | 1386 "", "", "", "", "", "", ""); |
| 1387 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1387 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
| 1388 std::vector<base::string16> multi_values(2); | 1388 std::vector<base::string16> multi_values(2); |
| 1389 multi_values[0] = ASCIIToUTF16("Elvis Presley"); | 1389 multi_values[0] = ASCIIToUTF16("Elvis"); |
| 1390 multi_values[1] = ASCIIToUTF16("Elena Love"); | 1390 multi_values[1] = ASCIIToUTF16("Elena"); |
| 1391 profile->SetRawMultiInfo(NAME_FULL, multi_values); | 1391 profile->SetRawMultiInfo(NAME_FIRST, multi_values); |
| 1392 multi_values[0] = ASCIIToUTF16("Presley"); |
| 1393 multi_values[1] = ASCIIToUTF16("Love"); |
| 1394 profile->SetRawMultiInfo(NAME_LAST, multi_values); |
| 1392 personal_data_.ClearAutofillProfiles(); | 1395 personal_data_.ClearAutofillProfiles(); |
| 1393 autofill_manager_->AddProfile(profile); | 1396 autofill_manager_->AddProfile(profile); |
| 1394 | 1397 |
| 1395 { | 1398 { |
| 1396 // Get the first name field. | 1399 // Get the first name field. |
| 1397 // Start out with "E", hoping for either "Elvis" or "Elena. | 1400 // Start out with "E", hoping for either "Elvis" or "Elena. |
| 1398 FormFieldData& field = form.fields[0]; | 1401 FormFieldData& field = form.fields[0]; |
| 1399 field.value = ASCIIToUTF16("E"); | 1402 field.value = ASCIIToUTF16("E"); |
| 1400 field.is_autofilled = false; | 1403 field.is_autofilled = false; |
| 1401 GetAutofillSuggestions(form, field); | 1404 GetAutofillSuggestions(form, field); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 // Set up our form data. | 1450 // Set up our form data. |
| 1448 FormData form; | 1451 FormData form; |
| 1449 test::CreateTestAddressFormData(&form); | 1452 test::CreateTestAddressFormData(&form); |
| 1450 std::vector<FormData> forms(1, form); | 1453 std::vector<FormData> forms(1, form); |
| 1451 FormsSeen(forms); | 1454 FormsSeen(forms); |
| 1452 | 1455 |
| 1453 // |profile| will be owned by the mock PersonalDataManager. | 1456 // |profile| will be owned by the mock PersonalDataManager. |
| 1454 AutofillProfile* profile = new AutofillProfile; | 1457 AutofillProfile* profile = new AutofillProfile; |
| 1455 profile->set_guid("00000000-0000-0000-0000-000000000102"); | 1458 profile->set_guid("00000000-0000-0000-0000-000000000102"); |
| 1456 std::vector<base::string16> multi_values(3); | 1459 std::vector<base::string16> multi_values(3); |
| 1457 multi_values[0] = ASCIIToUTF16("Travis Smith"); | 1460 multi_values[0] = ASCIIToUTF16("Travis"); |
| 1458 multi_values[1] = ASCIIToUTF16("Cynthia Love"); | 1461 multi_values[1] = ASCIIToUTF16("Cynthia"); |
| 1459 multi_values[2] = ASCIIToUTF16("Zac Mango"); | 1462 multi_values[2] = ASCIIToUTF16("Zac"); |
| 1460 profile->SetRawMultiInfo(NAME_FULL, multi_values); | 1463 profile->SetRawMultiInfo(NAME_FIRST, multi_values); |
| 1464 multi_values[0] = ASCIIToUTF16("Smith"); |
| 1465 multi_values[1] = ASCIIToUTF16("Love"); |
| 1466 multi_values[2] = ASCIIToUTF16("Mango"); |
| 1467 profile->SetRawMultiInfo(NAME_LAST, multi_values); |
| 1461 autofill_manager_->AddProfile(profile); | 1468 autofill_manager_->AddProfile(profile); |
| 1462 | 1469 |
| 1463 // Get the first name field. And start out with "Travis", hoping for all the | 1470 // Get the first name field. And start out with "Travis", hoping for all the |
| 1464 // multi-valued variants as suggestions. | 1471 // multi-valued variants as suggestions. |
| 1465 FormFieldData& field = form.fields[0]; | 1472 FormFieldData& field = form.fields[0]; |
| 1466 field.value = ASCIIToUTF16("Travis"); | 1473 field.value = ASCIIToUTF16("Travis"); |
| 1467 field.is_autofilled = true; | 1474 field.is_autofilled = true; |
| 1468 GetAutofillSuggestions(form, field); | 1475 GetAutofillSuggestions(form, field); |
| 1469 | 1476 |
| 1470 // Trigger the |Send|. | 1477 // Trigger the |Send|. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1488 | 1495 |
| 1489 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { | 1496 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { |
| 1490 // Set up our form data. | 1497 // Set up our form data. |
| 1491 FormData form; | 1498 FormData form; |
| 1492 test::CreateTestAddressFormData(&form); | 1499 test::CreateTestAddressFormData(&form); |
| 1493 std::vector<FormData> forms(1, form); | 1500 std::vector<FormData> forms(1, form); |
| 1494 FormsSeen(forms); | 1501 FormsSeen(forms); |
| 1495 | 1502 |
| 1496 AutofillProfile* profile = new AutofillProfile; | 1503 AutofillProfile* profile = new AutofillProfile; |
| 1497 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1504 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
| 1498 std::vector<base::string16> multi_values(1); | 1505 profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"), |
| 1499 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); | 1506 "en-US"); |
| 1500 profile->SetRawMultiInfo(NAME_FULL, multi_values); | 1507 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 1501 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); | 1508 ASCIIToUTF16("1800PRAIRIE")); |
| 1502 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); | |
| 1503 autofill_manager_->AddProfile(profile); | 1509 autofill_manager_->AddProfile(profile); |
| 1504 | 1510 |
| 1505 const FormFieldData& field = form.fields[9]; | 1511 const FormFieldData& field = form.fields[9]; |
| 1506 GetAutofillSuggestions(form, field); | 1512 GetAutofillSuggestions(form, field); |
| 1507 | 1513 |
| 1508 // No suggestions provided, so send an empty vector as the results. | 1514 // No suggestions provided, so send an empty vector as the results. |
| 1509 // This triggers the combined message send. | 1515 // This triggers the combined message send. |
| 1510 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1516 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1511 | 1517 |
| 1512 // Test that we sent the right values to the external delegate. | 1518 // Test that we sent the right values to the external delegate. |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) { | 2048 TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) { |
| 2043 // Set up our form data. | 2049 // Set up our form data. |
| 2044 FormData form; | 2050 FormData form; |
| 2045 test::CreateTestAddressFormData(&form); | 2051 test::CreateTestAddressFormData(&form); |
| 2046 std::vector<FormData> forms(1, form); | 2052 std::vector<FormData> forms(1, form); |
| 2047 FormsSeen(forms); | 2053 FormsSeen(forms); |
| 2048 | 2054 |
| 2049 // Add a name variant to the Elvis profile. | 2055 // Add a name variant to the Elvis profile. |
| 2050 AutofillProfile* profile = autofill_manager_->GetProfileWithGUID( | 2056 AutofillProfile* profile = autofill_manager_->GetProfileWithGUID( |
| 2051 "00000000-0000-0000-0000-000000000001"); | 2057 "00000000-0000-0000-0000-000000000001"); |
| 2052 const base::string16 elvis_name = profile->GetRawInfo(NAME_FULL); | |
| 2053 | 2058 |
| 2054 std::vector<base::string16> name_variants; | 2059 std::vector<base::string16> name_variants; |
| 2055 name_variants.push_back(ASCIIToUTF16("Some Other Guy")); | 2060 name_variants.push_back(ASCIIToUTF16("Some")); |
| 2056 name_variants.push_back(elvis_name); | 2061 name_variants.push_back(profile->GetRawInfo(NAME_FIRST)); |
| 2057 profile->SetRawMultiInfo(NAME_FULL, name_variants); | 2062 profile->SetRawMultiInfo(NAME_FIRST, name_variants); |
| 2063 |
| 2064 name_variants.clear(); |
| 2065 name_variants.push_back(ASCIIToUTF16("Other")); |
| 2066 name_variants.push_back(profile->GetRawInfo(NAME_MIDDLE)); |
| 2067 profile->SetRawMultiInfo(NAME_MIDDLE, name_variants); |
| 2068 |
| 2069 name_variants.clear(); |
| 2070 name_variants.push_back(ASCIIToUTF16("Guy")); |
| 2071 name_variants.push_back(profile->GetRawInfo(NAME_LAST)); |
| 2072 profile->SetRawMultiInfo(NAME_LAST, name_variants); |
| 2058 | 2073 |
| 2059 GUIDPair guid(profile->guid(), 1); | 2074 GUIDPair guid(profile->guid(), 1); |
| 2060 GUIDPair empty(std::string(), 0); | 2075 GUIDPair empty(std::string(), 0); |
| 2061 int response_page_id = 0; | 2076 int response_page_id = 0; |
| 2062 FormData response_data1; | 2077 FormData response_data1; |
| 2063 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 2078 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
| 2064 PackGUIDs(empty, guid), &response_page_id, &response_data1); | 2079 PackGUIDs(empty, guid), &response_page_id, &response_data1); |
| 2065 { | 2080 { |
| 2066 SCOPED_TRACE("Valid variant"); | 2081 SCOPED_TRACE("Valid variant"); |
| 2067 ExpectFilledAddressFormElvis( | 2082 ExpectFilledAddressFormElvis( |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2871 test::CreateTestAddressFormData(&form); | 2886 test::CreateTestAddressFormData(&form); |
| 2872 std::vector<FormData> forms(1, form); | 2887 std::vector<FormData> forms(1, form); |
| 2873 FormsSeen(forms); | 2888 FormsSeen(forms); |
| 2874 const FormFieldData& field = form.fields[0]; | 2889 const FormFieldData& field = form.fields[0]; |
| 2875 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2890 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 2876 | 2891 |
| 2877 EXPECT_TRUE(external_delegate_->on_query_seen()); | 2892 EXPECT_TRUE(external_delegate_->on_query_seen()); |
| 2878 } | 2893 } |
| 2879 | 2894 |
| 2880 } // namespace autofill | 2895 } // namespace autofill |
| OLD | NEW |