Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / autofill / core / browser / address_field_unittest.cc
blobb8f27ad72a7d4be6e922d7db6bee0c0474f0ecf0
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/address_field.h"
10 #include "components/autofill/core/browser/autofill_field.h"
11 #include "components/autofill/core/browser/autofill_scanner.h"
12 #include "components/autofill/core/common/form_field_data.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using base::ASCIIToUTF16;
17 namespace autofill {
19 class AddressFieldTest : public testing::Test {
20 public:
21 AddressFieldTest() {}
23 protected:
24 ScopedVector<AutofillField> list_;
25 scoped_ptr<AddressField> field_;
26 ServerFieldTypeMap field_type_map_;
28 // Downcast for tests.
29 static scoped_ptr<AddressField> Parse(AutofillScanner* scanner) {
30 scoped_ptr<FormField> field = AddressField::Parse(scanner);
31 return make_scoped_ptr(static_cast<AddressField*>(field.release()));
34 private:
35 DISALLOW_COPY_AND_ASSIGN(AddressFieldTest);
38 TEST_F(AddressFieldTest, Empty) {
39 AutofillScanner scanner(list_.get());
40 field_ = Parse(&scanner);
41 ASSERT_EQ(nullptr, field_.get());
44 TEST_F(AddressFieldTest, NonParse) {
45 list_.push_back(new AutofillField);
46 AutofillScanner scanner(list_.get());
47 field_ = Parse(&scanner);
48 ASSERT_EQ(nullptr, field_.get());
51 TEST_F(AddressFieldTest, ParseOneLineAddress) {
52 FormFieldData field;
53 field.form_control_type = "text";
55 field.label = ASCIIToUTF16("Address");
56 field.name = ASCIIToUTF16("address");
57 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr1")));
59 AutofillScanner scanner(list_.get());
60 field_ = Parse(&scanner);
61 ASSERT_NE(nullptr, field_.get());
62 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
63 ASSERT_TRUE(
64 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
65 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
68 TEST_F(AddressFieldTest, ParseTwoLineAddress) {
69 FormFieldData field;
70 field.form_control_type = "text";
72 field.label = ASCIIToUTF16("Address");
73 field.name = ASCIIToUTF16("address");
74 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr1")));
76 field.label = base::string16();
77 field.name = ASCIIToUTF16("address2");
78 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr2")));
80 AutofillScanner scanner(list_.get());
81 field_ = Parse(&scanner);
82 ASSERT_NE(nullptr, field_.get());
83 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
84 ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("addr1")) !=
85 field_type_map_.end());
86 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
87 ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("addr2")) !=
88 field_type_map_.end());
89 EXPECT_EQ(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]);
92 TEST_F(AddressFieldTest, ParseThreeLineAddress) {
93 FormFieldData field;
94 field.form_control_type = "text";
96 field.label = ASCIIToUTF16("Address Line1");
97 field.name = ASCIIToUTF16("Address1");
98 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr1")));
100 field.label = ASCIIToUTF16("Address Line2");
101 field.name = ASCIIToUTF16("Address2");
102 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr2")));
104 field.label = ASCIIToUTF16("Address Line3");
105 field.name = ASCIIToUTF16("Address3");
106 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr3")));
108 AutofillScanner scanner(list_.get());
109 field_ = Parse(&scanner);
110 ASSERT_NE(nullptr, field_.get());
111 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
112 ASSERT_TRUE(
113 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
114 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
115 ASSERT_TRUE(
116 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end());
117 EXPECT_EQ(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]);
118 ASSERT_TRUE(
119 field_type_map_.find(ASCIIToUTF16("addr3")) != field_type_map_.end());
120 EXPECT_EQ(ADDRESS_HOME_LINE3, field_type_map_[ASCIIToUTF16("addr3")]);
123 TEST_F(AddressFieldTest, ParseStreetAddressFromTextArea) {
124 FormFieldData field;
125 field.form_control_type = "textarea";
127 field.label = ASCIIToUTF16("Address");
128 field.name = ASCIIToUTF16("address");
129 list_.push_back(new AutofillField(field, ASCIIToUTF16("addr")));
131 AutofillScanner scanner(list_.get());
132 field_ = Parse(&scanner);
133 ASSERT_NE(nullptr, field_.get());
134 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
135 ASSERT_TRUE(
136 field_type_map_.find(ASCIIToUTF16("addr")) != field_type_map_.end());
137 EXPECT_EQ(ADDRESS_HOME_STREET_ADDRESS, field_type_map_[ASCIIToUTF16("addr")]);
140 TEST_F(AddressFieldTest, ParseCity) {
141 FormFieldData field;
142 field.form_control_type = "text";
144 field.label = ASCIIToUTF16("City");
145 field.name = ASCIIToUTF16("city");
146 list_.push_back(new AutofillField(field, ASCIIToUTF16("city1")));
148 AutofillScanner scanner(list_.get());
149 field_ = Parse(&scanner);
150 ASSERT_NE(nullptr, field_.get());
151 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
152 ASSERT_TRUE(
153 field_type_map_.find(ASCIIToUTF16("city1")) != field_type_map_.end());
154 EXPECT_EQ(ADDRESS_HOME_CITY, field_type_map_[ASCIIToUTF16("city1")]);
157 TEST_F(AddressFieldTest, ParseState) {
158 FormFieldData field;
159 field.form_control_type = "text";
161 field.label = ASCIIToUTF16("State");
162 field.name = ASCIIToUTF16("state");
163 list_.push_back(new AutofillField(field, ASCIIToUTF16("state1")));
165 AutofillScanner scanner(list_.get());
166 field_ = Parse(&scanner);
167 ASSERT_NE(nullptr, field_.get());
168 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
169 ASSERT_TRUE(
170 field_type_map_.find(ASCIIToUTF16("state1")) != field_type_map_.end());
171 EXPECT_EQ(ADDRESS_HOME_STATE, field_type_map_[ASCIIToUTF16("state1")]);
174 TEST_F(AddressFieldTest, ParseZip) {
175 FormFieldData field;
176 field.form_control_type = "text";
178 field.label = ASCIIToUTF16("Zip");
179 field.name = ASCIIToUTF16("zip");
180 list_.push_back(new AutofillField(field, ASCIIToUTF16("zip1")));
182 AutofillScanner scanner(list_.get());
183 field_ = Parse(&scanner);
184 ASSERT_NE(nullptr, field_.get());
185 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
186 ASSERT_TRUE(
187 field_type_map_.find(ASCIIToUTF16("zip1")) != field_type_map_.end());
188 EXPECT_EQ(ADDRESS_HOME_ZIP, field_type_map_[ASCIIToUTF16("zip1")]);
191 TEST_F(AddressFieldTest, ParseStateAndZipOneLabel) {
192 FormFieldData field;
193 field.form_control_type = "text";
195 field.label = ASCIIToUTF16("State/Province, Zip/Postal Code");
196 field.name = ASCIIToUTF16("state");
197 list_.push_back(new AutofillField(field, ASCIIToUTF16("state")));
199 field.label = ASCIIToUTF16("State/Province, Zip/Postal Code");
200 field.name = ASCIIToUTF16("zip");
201 list_.push_back(new AutofillField(field, ASCIIToUTF16("zip")));
203 AutofillScanner scanner(list_.get());
204 field_ = Parse(&scanner);
205 ASSERT_NE(nullptr, field_.get());
206 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
207 ASSERT_TRUE(
208 field_type_map_.find(ASCIIToUTF16("state")) != field_type_map_.end());
209 EXPECT_EQ(ADDRESS_HOME_STATE, field_type_map_[ASCIIToUTF16("state")]);
210 ASSERT_TRUE(
211 field_type_map_.find(ASCIIToUTF16("zip")) != field_type_map_.end());
212 EXPECT_EQ(ADDRESS_HOME_ZIP, field_type_map_[ASCIIToUTF16("zip")]);
215 TEST_F(AddressFieldTest, ParseCountry) {
216 FormFieldData field;
217 field.form_control_type = "text";
219 field.label = ASCIIToUTF16("Country");
220 field.name = ASCIIToUTF16("country");
221 list_.push_back(new AutofillField(field, ASCIIToUTF16("country1")));
223 AutofillScanner scanner(list_.get());
224 field_ = Parse(&scanner);
225 ASSERT_NE(nullptr, field_.get());
226 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
227 ASSERT_TRUE(
228 field_type_map_.find(ASCIIToUTF16("country1")) != field_type_map_.end());
229 EXPECT_EQ(ADDRESS_HOME_COUNTRY, field_type_map_[ASCIIToUTF16("country1")]);
232 TEST_F(AddressFieldTest, ParseCompany) {
233 FormFieldData field;
234 field.form_control_type = "text";
236 field.label = ASCIIToUTF16("Company");
237 field.name = ASCIIToUTF16("company");
238 list_.push_back(new AutofillField(field, ASCIIToUTF16("company1")));
240 AutofillScanner scanner(list_.get());
241 field_ = Parse(&scanner);
242 ASSERT_NE(nullptr, field_.get());
243 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
244 ASSERT_TRUE(
245 field_type_map_.find(ASCIIToUTF16("company1")) != field_type_map_.end());
246 EXPECT_EQ(COMPANY_NAME, field_type_map_[ASCIIToUTF16("company1")]);
249 } // namespace autofill