OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/strings/string_util.h" | |
6 #include "base/strings/utf_string_conversions.h" | |
7 #include "components/autofill/browser/autofill_field.h" | |
8 #include "components/autofill/browser/field_types.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace autofill { | |
12 namespace { | |
13 | |
14 TEST(AutofillFieldTest, Type) { | |
15 AutofillField field; | |
16 ASSERT_EQ(NO_SERVER_DATA, field.server_type()); | |
17 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type()); | |
18 | |
19 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned. | |
20 EXPECT_EQ(UNKNOWN_TYPE, field.type()); | |
21 | |
22 // Set the heuristic type and check it. | |
23 field.set_heuristic_type(NAME_FIRST); | |
24 EXPECT_EQ(NAME_FIRST, field.type()); | |
25 | |
26 // Set the server type and check it. | |
27 field.set_server_type(ADDRESS_BILLING_LINE1); | |
28 EXPECT_EQ(ADDRESS_BILLING_LINE1, field.type()); | |
29 | |
30 // Remove the server type to make sure the heuristic type is preserved. | |
31 field.set_server_type(NO_SERVER_DATA); | |
32 EXPECT_EQ(NAME_FIRST, field.type()); | |
33 } | |
34 | |
35 TEST(AutofillFieldTest, IsEmpty) { | |
36 AutofillField field; | |
37 ASSERT_EQ(base::string16(), field.value); | |
38 | |
39 // Field value is empty. | |
40 EXPECT_TRUE(field.IsEmpty()); | |
41 | |
42 // Field value is non-empty. | |
43 field.value = ASCIIToUTF16("Value"); | |
44 EXPECT_FALSE(field.IsEmpty()); | |
45 } | |
46 | |
47 TEST(AutofillFieldTest, FieldSignature) { | |
48 AutofillField field; | |
49 ASSERT_EQ(base::string16(), field.name); | |
50 ASSERT_EQ(std::string(), field.form_control_type); | |
51 | |
52 // Signature is empty. | |
53 EXPECT_EQ("2085434232", field.FieldSignature()); | |
54 | |
55 // Field name is set. | |
56 field.name = ASCIIToUTF16("Name"); | |
57 EXPECT_EQ("1606968241", field.FieldSignature()); | |
58 | |
59 // Field form control type is set. | |
60 field.form_control_type = "text"; | |
61 EXPECT_EQ("502192749", field.FieldSignature()); | |
62 | |
63 // Heuristic type does not affect FieldSignature. | |
64 field.set_heuristic_type(NAME_FIRST); | |
65 EXPECT_EQ("502192749", field.FieldSignature()); | |
66 | |
67 // Server type does not affect FieldSignature. | |
68 field.set_server_type(NAME_LAST); | |
69 EXPECT_EQ("502192749", field.FieldSignature()); | |
70 } | |
71 | |
72 TEST(AutofillFieldTest, IsFieldFillable) { | |
73 AutofillField field; | |
74 ASSERT_EQ(UNKNOWN_TYPE, field.type()); | |
75 | |
76 // Type is unknown. | |
77 EXPECT_FALSE(field.IsFieldFillable()); | |
78 | |
79 // Only heuristic type is set. | |
80 field.set_heuristic_type(NAME_FIRST); | |
81 EXPECT_TRUE(field.IsFieldFillable()); | |
82 | |
83 // Only server type is set. | |
84 field.set_heuristic_type(UNKNOWN_TYPE); | |
85 field.set_server_type(NAME_LAST); | |
86 EXPECT_TRUE(field.IsFieldFillable()); | |
87 | |
88 // Both types set. | |
89 field.set_heuristic_type(NAME_FIRST); | |
90 field.set_server_type(NAME_LAST); | |
91 EXPECT_TRUE(field.IsFieldFillable()); | |
92 } | |
93 | |
94 } // namespace | |
95 } // namespace autofill | |
OLD | NEW |