Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/browser/autofill/form_field_unittest.cc

Issue 11415221: Add support for autofilling radio buttons and checkboxes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: More unit tests Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | chrome/browser/autofill/form_structure.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 AutofillField* BuildTestField(const std::string& name) {
Ilya Sherman 2012/12/18 02:05:11 nit: Please rename the parameter to |label|, since
120 FormFieldData field_data;
121 field_data.label = ASCIIToUTF16(name);
122 field_data.name = ASCIIToUTF16("name");
123 field_data.value = ASCIIToUTF16("value");
124 field_data.form_control_type = "text";
125 field_data.is_focusable = true;
126 field_data.autocomplete_attribute = "on";
127 field_data.should_autocomplete = true;
128 return new AutofillField(field_data, field_data.label);
Ilya Sherman 2012/12/18 02:05:11 You should pretty much never return a raw pointer
129 }
Ilya Sherman 2012/12/18 02:05:11 nit: Please move this function definition into an
130
131 // Test that we ignore checkable elements.
132 TEST(FormFieldTest, ParseFormFields) {
133 ScopedVector<AutofillField> fields;
134 fields.push_back(BuildTestField("Address line1"));
135 AutofillField* checkable_field = BuildTestField("Is PO box");
136 checkable_field->is_checkable = true;
137 fields.push_back(checkable_field);
138 fields.push_back(BuildTestField("Address line2"));
139
140 FieldTypeMap field_type_map;
141 FormField::ParseFormFields(fields.get(), &field_type_map);
142 // Checkable element shouldn't interfere with inference of Address line2.
143 EXPECT_EQ(2U, field_type_map.size());
144
145 EXPECT_EQ(ADDRESS_HOME_LINE1,
146 field_type_map.find(ASCIIToUTF16("Address line1"))->second);
147 EXPECT_EQ(ADDRESS_HOME_LINE2,
148 field_type_map.find(ASCIIToUTF16("Address line2"))->second);
149 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | chrome/browser/autofill/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698