| 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "components/autofill/core/browser/autofill_field.h" | 7 #include "components/autofill/core/browser/autofill_field.h" |
| 8 #include "components/autofill/core/browser/autofill_type.h" | 8 #include "components/autofill/core/browser/autofill_type.h" |
| 9 #include "components/autofill/core/browser/field_types.h" | 9 #include "components/autofill/core/browser/field_types.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace autofill { | 12 namespace autofill { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 TEST(AutofillFieldTest, Type) { | 15 TEST(AutofillFieldTest, Type) { |
| 16 AutofillField field; | 16 AutofillField field; |
| 17 ASSERT_EQ(NO_SERVER_DATA, field.server_type()); | 17 ASSERT_EQ(NO_SERVER_DATA, field.server_type()); |
| 18 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type()); | 18 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type()); |
| 19 | 19 |
| 20 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned. | 20 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned. |
| 21 EXPECT_EQ(UNKNOWN_TYPE, field.Type().native_type()); | 21 EXPECT_EQ(UNKNOWN_TYPE, field.Type().GetEquivalentNativeType()); |
| 22 | 22 |
| 23 // Set the heuristic type and check it. | 23 // Set the heuristic type and check it. |
| 24 field.set_heuristic_type(NAME_FIRST); | 24 field.set_heuristic_type(NAME_FIRST); |
| 25 EXPECT_EQ(NAME_FIRST, field.Type().native_type()); | 25 EXPECT_EQ(NAME_FIRST, field.Type().GetEquivalentNativeType()); |
| 26 EXPECT_EQ(NAME, field.Type().group()); |
| 26 | 27 |
| 27 // Set the server type and check it. | 28 // Set the server type and check it. |
| 28 field.set_server_type(ADDRESS_BILLING_LINE1); | 29 field.set_server_type(ADDRESS_BILLING_LINE1); |
| 29 EXPECT_EQ(ADDRESS_BILLING_LINE1, field.Type().native_type()); | 30 EXPECT_EQ(ADDRESS_HOME_LINE1, field.Type().GetEquivalentNativeType()); |
| 31 EXPECT_EQ(ADDRESS_BILLING, field.Type().group()); |
| 30 | 32 |
| 31 // Remove the server type to make sure the heuristic type is preserved. | 33 // Remove the server type to make sure the heuristic type is preserved. |
| 32 field.set_server_type(NO_SERVER_DATA); | 34 field.set_server_type(NO_SERVER_DATA); |
| 33 EXPECT_EQ(NAME_FIRST, field.Type().native_type()); | 35 EXPECT_EQ(NAME_FIRST, field.Type().GetEquivalentNativeType()); |
| 36 EXPECT_EQ(NAME, field.Type().group()); |
| 34 } | 37 } |
| 35 | 38 |
| 36 TEST(AutofillFieldTest, IsEmpty) { | 39 TEST(AutofillFieldTest, IsEmpty) { |
| 37 AutofillField field; | 40 AutofillField field; |
| 38 ASSERT_EQ(base::string16(), field.value); | 41 ASSERT_EQ(base::string16(), field.value); |
| 39 | 42 |
| 40 // Field value is empty. | 43 // Field value is empty. |
| 41 EXPECT_TRUE(field.IsEmpty()); | 44 EXPECT_TRUE(field.IsEmpty()); |
| 42 | 45 |
| 43 // Field value is non-empty. | 46 // Field value is non-empty. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 field.set_heuristic_type(NAME_FIRST); | 68 field.set_heuristic_type(NAME_FIRST); |
| 66 EXPECT_EQ("502192749", field.FieldSignature()); | 69 EXPECT_EQ("502192749", field.FieldSignature()); |
| 67 | 70 |
| 68 // Server type does not affect FieldSignature. | 71 // Server type does not affect FieldSignature. |
| 69 field.set_server_type(NAME_LAST); | 72 field.set_server_type(NAME_LAST); |
| 70 EXPECT_EQ("502192749", field.FieldSignature()); | 73 EXPECT_EQ("502192749", field.FieldSignature()); |
| 71 } | 74 } |
| 72 | 75 |
| 73 TEST(AutofillFieldTest, IsFieldFillable) { | 76 TEST(AutofillFieldTest, IsFieldFillable) { |
| 74 AutofillField field; | 77 AutofillField field; |
| 75 ASSERT_EQ(UNKNOWN_TYPE, field.Type().native_type()); | 78 ASSERT_EQ(UNKNOWN_TYPE, field.Type().GetEquivalentNativeType()); |
| 76 | 79 |
| 77 // Type is unknown. | 80 // Type is unknown. |
| 78 EXPECT_FALSE(field.IsFieldFillable()); | 81 EXPECT_FALSE(field.IsFieldFillable()); |
| 79 | 82 |
| 80 // Only heuristic type is set. | 83 // Only heuristic type is set. |
| 81 field.set_heuristic_type(NAME_FIRST); | 84 field.set_heuristic_type(NAME_FIRST); |
| 82 EXPECT_TRUE(field.IsFieldFillable()); | 85 EXPECT_TRUE(field.IsFieldFillable()); |
| 83 | 86 |
| 84 // Only server type is set. | 87 // Only server type is set. |
| 85 field.set_heuristic_type(UNKNOWN_TYPE); | 88 field.set_heuristic_type(UNKNOWN_TYPE); |
| 86 field.set_server_type(NAME_LAST); | 89 field.set_server_type(NAME_LAST); |
| 87 EXPECT_TRUE(field.IsFieldFillable()); | 90 EXPECT_TRUE(field.IsFieldFillable()); |
| 88 | 91 |
| 89 // Both types set. | 92 // Both types set. |
| 90 field.set_heuristic_type(NAME_FIRST); | 93 field.set_heuristic_type(NAME_FIRST); |
| 91 field.set_server_type(NAME_LAST); | 94 field.set_server_type(NAME_LAST); |
| 92 EXPECT_TRUE(field.IsFieldFillable()); | 95 EXPECT_TRUE(field.IsFieldFillable()); |
| 93 } | 96 } |
| 94 | 97 |
| 95 } // namespace | 98 } // namespace |
| 96 } // namespace autofill | 99 } // namespace autofill |
| OLD | NEW |