| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/autofill/core/browser/address_i18n.h" | 5 #include "components/autofill/core/browser/address_i18n.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 using ::i18n::addressinput::ADMIN_AREA; | 28 using ::i18n::addressinput::ADMIN_AREA; |
| 29 using ::i18n::addressinput::COUNTRY; | 29 using ::i18n::addressinput::COUNTRY; |
| 30 using ::i18n::addressinput::DEPENDENT_LOCALITY; | 30 using ::i18n::addressinput::DEPENDENT_LOCALITY; |
| 31 using ::i18n::addressinput::LOCALITY; | 31 using ::i18n::addressinput::LOCALITY; |
| 32 using ::i18n::addressinput::ORGANIZATION; | 32 using ::i18n::addressinput::ORGANIZATION; |
| 33 using ::i18n::addressinput::POSTAL_CODE; | 33 using ::i18n::addressinput::POSTAL_CODE; |
| 34 using ::i18n::addressinput::RECIPIENT; | 34 using ::i18n::addressinput::RECIPIENT; |
| 35 using ::i18n::addressinput::SORTING_CODE; | 35 using ::i18n::addressinput::SORTING_CODE; |
| 36 using ::i18n::addressinput::STREET_ADDRESS; | 36 using ::i18n::addressinput::STREET_ADDRESS; |
| 37 | 37 |
| 38 TEST(AddressI18nTest, FieldTypeMirrorConversions) { | 38 struct FieldTypeMirrorConversionsTestCase { |
| 39 static const struct { | 39 bool billing; |
| 40 bool billing; | 40 ServerFieldType server_field; |
| 41 ServerFieldType server_field; | 41 AddressField address_field; |
| 42 AddressField address_field; | 42 }; |
| 43 } kTestData[] = { | |
| 44 {true, ADDRESS_BILLING_COUNTRY, COUNTRY}, | |
| 45 {true, ADDRESS_BILLING_STATE, ADMIN_AREA}, | |
| 46 {true, ADDRESS_BILLING_CITY, LOCALITY}, | |
| 47 {true, ADDRESS_BILLING_DEPENDENT_LOCALITY, DEPENDENT_LOCALITY}, | |
| 48 {true, ADDRESS_BILLING_SORTING_CODE, SORTING_CODE}, | |
| 49 {true, ADDRESS_BILLING_ZIP, POSTAL_CODE}, | |
| 50 {true, ADDRESS_BILLING_STREET_ADDRESS, STREET_ADDRESS}, | |
| 51 {true, COMPANY_NAME, ORGANIZATION}, | |
| 52 {true, NAME_BILLING_FULL, RECIPIENT}, | |
| 53 {false, ADDRESS_HOME_COUNTRY, COUNTRY}, | |
| 54 {false, ADDRESS_HOME_STATE, ADMIN_AREA}, | |
| 55 {false, ADDRESS_HOME_CITY, LOCALITY}, | |
| 56 {false, ADDRESS_HOME_DEPENDENT_LOCALITY, DEPENDENT_LOCALITY}, | |
| 57 {false, ADDRESS_HOME_SORTING_CODE, SORTING_CODE}, | |
| 58 {false, ADDRESS_HOME_ZIP, POSTAL_CODE}, | |
| 59 {false, ADDRESS_HOME_STREET_ADDRESS, STREET_ADDRESS}, | |
| 60 {false, COMPANY_NAME, ORGANIZATION}, | |
| 61 {false, NAME_FULL, RECIPIENT}, | |
| 62 }; | |
| 63 | 43 |
| 64 for (const auto& test_data : kTestData) { | 44 class FieldTypeMirrorConversionsTest |
| 65 AddressField address_field; | 45 : public testing::TestWithParam<FieldTypeMirrorConversionsTestCase> {}; |
| 66 EXPECT_TRUE(FieldForType(test_data.server_field, &address_field)); | |
| 67 EXPECT_EQ(test_data.address_field, address_field); | |
| 68 | 46 |
| 69 ServerFieldType server_field = | 47 TEST_P(FieldTypeMirrorConversionsTest, FieldTypeMirrorConversions) { |
| 70 TypeForField(test_data.address_field, test_data.billing); | 48 auto test_data = GetParam(); |
| 71 EXPECT_EQ(test_data.server_field, server_field); | 49 AddressField address_field; |
| 72 } | 50 EXPECT_TRUE(FieldForType(test_data.server_field, &address_field)); |
| 51 EXPECT_EQ(test_data.address_field, address_field); |
| 52 |
| 53 ServerFieldType server_field = |
| 54 TypeForField(test_data.address_field, test_data.billing); |
| 55 EXPECT_EQ(test_data.server_field, server_field); |
| 73 } | 56 } |
| 74 | 57 |
| 75 TEST(AddressI18nTest, FieldTypeUnidirectionalConversions) { | 58 INSTANTIATE_TEST_CASE_P( |
| 76 static const struct { | 59 AddressI18nTest, |
| 77 ServerFieldType server_field; | 60 FieldTypeMirrorConversionsTest, |
| 78 AddressField expected_address_field; | 61 testing::Values( |
| 79 } kTestData[] = { | 62 FieldTypeMirrorConversionsTestCase{true, ADDRESS_BILLING_COUNTRY, |
| 80 {ADDRESS_BILLING_LINE1, STREET_ADDRESS}, | 63 COUNTRY}, |
| 81 {ADDRESS_BILLING_LINE2, STREET_ADDRESS}, | 64 FieldTypeMirrorConversionsTestCase{true, ADDRESS_BILLING_STATE, |
| 82 {ADDRESS_HOME_LINE1, STREET_ADDRESS}, | 65 ADMIN_AREA}, |
| 83 {ADDRESS_HOME_LINE2, STREET_ADDRESS}, | 66 FieldTypeMirrorConversionsTestCase{true, ADDRESS_BILLING_CITY, |
| 84 }; | 67 LOCALITY}, |
| 68 FieldTypeMirrorConversionsTestCase{ |
| 69 true, ADDRESS_BILLING_DEPENDENT_LOCALITY, DEPENDENT_LOCALITY}, |
| 70 FieldTypeMirrorConversionsTestCase{true, ADDRESS_BILLING_SORTING_CODE, |
| 71 SORTING_CODE}, |
| 72 FieldTypeMirrorConversionsTestCase{true, ADDRESS_BILLING_ZIP, |
| 73 POSTAL_CODE}, |
| 74 FieldTypeMirrorConversionsTestCase{true, ADDRESS_BILLING_STREET_ADDRESS, |
| 75 STREET_ADDRESS}, |
| 76 FieldTypeMirrorConversionsTestCase{true, COMPANY_NAME, ORGANIZATION}, |
| 77 FieldTypeMirrorConversionsTestCase{true, NAME_BILLING_FULL, RECIPIENT}, |
| 78 FieldTypeMirrorConversionsTestCase{false, ADDRESS_HOME_COUNTRY, |
| 79 COUNTRY}, |
| 80 FieldTypeMirrorConversionsTestCase{false, ADDRESS_HOME_STATE, |
| 81 ADMIN_AREA}, |
| 82 FieldTypeMirrorConversionsTestCase{false, ADDRESS_HOME_CITY, LOCALITY}, |
| 83 FieldTypeMirrorConversionsTestCase{ |
| 84 false, ADDRESS_HOME_DEPENDENT_LOCALITY, DEPENDENT_LOCALITY}, |
| 85 FieldTypeMirrorConversionsTestCase{false, ADDRESS_HOME_SORTING_CODE, |
| 86 SORTING_CODE}, |
| 87 FieldTypeMirrorConversionsTestCase{false, ADDRESS_HOME_ZIP, |
| 88 POSTAL_CODE}, |
| 89 FieldTypeMirrorConversionsTestCase{false, ADDRESS_HOME_STREET_ADDRESS, |
| 90 STREET_ADDRESS}, |
| 91 FieldTypeMirrorConversionsTestCase{false, COMPANY_NAME, ORGANIZATION}, |
| 92 FieldTypeMirrorConversionsTestCase{false, NAME_FULL, RECIPIENT})); |
| 85 | 93 |
| 86 for (const auto& test_data : kTestData) { | 94 struct FieldTypeUnidirectionalConversionsTestCase { |
| 87 AddressField actual_address_field; | 95 ServerFieldType server_field; |
| 88 FieldForType(test_data.server_field, &actual_address_field); | 96 AddressField expected_address_field; |
| 89 EXPECT_EQ(test_data.expected_address_field, actual_address_field); | 97 }; |
| 90 } | 98 |
| 99 class FieldTypeUnidirectionalConversionsTest |
| 100 : public testing::TestWithParam< |
| 101 FieldTypeUnidirectionalConversionsTestCase> {}; |
| 102 |
| 103 TEST_P(FieldTypeUnidirectionalConversionsTest, |
| 104 FieldTypeUnidirectionalConversions) { |
| 105 auto test_data = GetParam(); |
| 106 AddressField actual_address_field; |
| 107 FieldForType(test_data.server_field, &actual_address_field); |
| 108 EXPECT_EQ(test_data.expected_address_field, actual_address_field); |
| 91 } | 109 } |
| 92 | 110 |
| 111 INSTANTIATE_TEST_CASE_P(AddressI18nTest, |
| 112 FieldTypeUnidirectionalConversionsTest, |
| 113 testing::Values( |
| 114 FieldTypeUnidirectionalConversionsTestCase{ |
| 115 ADDRESS_BILLING_LINE1, STREET_ADDRESS}, |
| 116 FieldTypeUnidirectionalConversionsTestCase{ |
| 117 ADDRESS_BILLING_LINE2, STREET_ADDRESS}, |
| 118 FieldTypeUnidirectionalConversionsTestCase{ |
| 119 ADDRESS_HOME_LINE1, STREET_ADDRESS}, |
| 120 FieldTypeUnidirectionalConversionsTestCase{ |
| 121 ADDRESS_HOME_LINE2, STREET_ADDRESS})); |
| 122 |
| 93 TEST(AddressI18nTest, UnconvertableServerFields) { | 123 TEST(AddressI18nTest, UnconvertableServerFields) { |
| 94 EXPECT_FALSE(FieldForType(PHONE_HOME_NUMBER, NULL)); | 124 EXPECT_FALSE(FieldForType(PHONE_HOME_NUMBER, NULL)); |
| 95 EXPECT_FALSE(FieldForType(EMAIL_ADDRESS, NULL)); | 125 EXPECT_FALSE(FieldForType(EMAIL_ADDRESS, NULL)); |
| 96 } | 126 } |
| 97 | 127 |
| 98 TEST(AddressI18nTest, CreateAddressDataFromAutofillProfile) { | 128 TEST(AddressI18nTest, CreateAddressDataFromAutofillProfile) { |
| 99 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); | 129 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); |
| 100 test::SetProfileInfo(&profile, | 130 test::SetProfileInfo(&profile, |
| 101 "John", | 131 "John", |
| 102 "H.", | 132 "H.", |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 expected.postal_code = "91111"; | 152 expected.postal_code = "91111"; |
| 123 expected.language_code = "en"; | 153 expected.language_code = "en"; |
| 124 expected.organization = "Underworld"; | 154 expected.organization = "Underworld"; |
| 125 expected.recipient = "John H. Doe"; | 155 expected.recipient = "John H. Doe"; |
| 126 | 156 |
| 127 EXPECT_EQ(expected, *actual); | 157 EXPECT_EQ(expected, *actual); |
| 128 } | 158 } |
| 129 | 159 |
| 130 } // namespace i18n | 160 } // namespace i18n |
| 131 } // namespace autofill | 161 } // namespace autofill |
| OLD | NEW |