OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/memory/scoped_vector.h" |
5 #include "base/string16.h" | 6 #include "base/string16.h" |
6 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/autofill/autofill_field.h" | 8 #include "chrome/browser/autofill/autofill_field.h" |
8 #include "chrome/browser/autofill/form_field.h" | 9 #include "chrome/browser/autofill/form_field.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 TEST(FormFieldTest, Match) { | 12 TEST(FormFieldTest, Match) { |
12 AutofillField field; | 13 AutofillField field; |
13 | 14 |
14 // Empty strings match. | 15 // Empty strings match. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 field.label = ASCIIToUTF16("contains word:"); | 108 field.label = ASCIIToUTF16("contains word:"); |
108 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("\\bword\\b"), | 109 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("\\bword\\b"), |
109 FormField::MATCH_LABEL)); | 110 FormField::MATCH_LABEL)); |
110 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcon\\b"), | 111 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcon\\b"), |
111 FormField::MATCH_LABEL)); | 112 FormField::MATCH_LABEL)); |
112 // Make sure the circumflex in 'crepe' is not treated as a word boundary. | 113 // Make sure the circumflex in 'crepe' is not treated as a word boundary. |
113 field.label = UTF8ToUTF16("cr" "\xC3\xAA" "pe"); | 114 field.label = UTF8ToUTF16("cr" "\xC3\xAA" "pe"); |
114 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcr\\b"), | 115 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcr\\b"), |
115 FormField::MATCH_LABEL)); | 116 FormField::MATCH_LABEL)); |
116 } | 117 } |
| 118 |
| 119 // Test that we ignore checkable elements. |
| 120 TEST(FormFieldTest, ParseFormFields) { |
| 121 ScopedVector<AutofillField> fields; |
| 122 FormFieldData field_data; |
| 123 field_data.form_control_type = "text"; |
| 124 |
| 125 field_data.label = ASCIIToUTF16("Address line1"); |
| 126 fields.push_back(new AutofillField(field_data, field_data.label)); |
| 127 |
| 128 field_data.is_checkable = true; |
| 129 field_data.label = ASCIIToUTF16("Is PO Box"); |
| 130 fields.push_back(new AutofillField(field_data, field_data.label)); |
| 131 |
| 132 // reset is_checkable to false. |
| 133 field_data.is_checkable = false; |
| 134 field_data.label = ASCIIToUTF16("Address line2"); |
| 135 fields.push_back(new AutofillField(field_data, field_data.label)); |
| 136 |
| 137 FieldTypeMap field_type_map; |
| 138 FormField::ParseFormFields(fields.get(), &field_type_map); |
| 139 // Checkable element shouldn't interfere with inference of Address line2. |
| 140 EXPECT_EQ(2U, field_type_map.size()); |
| 141 |
| 142 EXPECT_EQ(ADDRESS_HOME_LINE1, |
| 143 field_type_map.find(ASCIIToUTF16("Address line1"))->second); |
| 144 EXPECT_EQ(ADDRESS_HOME_LINE2, |
| 145 field_type_map.find(ASCIIToUTF16("Address line2"))->second); |
| 146 } |
OLD | NEW |