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

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

Issue 2078016: AutoFill fill billing address when credit card settings specify a billing address. (Closed)
Patch Set: Addressing review comments. Created 10 years, 7 months 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/address_field.cc ('k') | chrome/browser/autofill/autofill_manager.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/scoped_vector.h" 6 #include "base/scoped_vector.h"
7 #include "chrome/browser/autofill/address_field.h" 7 #include "chrome/browser/autofill/address_field.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "webkit/glue/form_field.h" 9 #include "webkit/glue/form_field.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"), 44 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"),
45 ASCIIToUTF16("address"), 45 ASCIIToUTF16("address"),
46 string16(), 46 string16(),
47 ASCIIToUTF16("text"), 47 ASCIIToUTF16("text"),
48 0), 48 0),
49 ASCIIToUTF16("addr1"))); 49 ASCIIToUTF16("addr1")));
50 list_.push_back(NULL); 50 list_.push_back(NULL);
51 iter_ = list_.begin(); 51 iter_ = list_.begin();
52 field_.reset(AddressField::Parse(&iter_, false)); 52 field_.reset(AddressField::Parse(&iter_, false));
53 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get()); 53 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
54 EXPECT_EQ(kGenericAddress, field_->FindType());
55 EXPECT_TRUE(field_->IsFullAddress());
56 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
57 ASSERT_TRUE(
58 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
59 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
60 }
61
62 TEST_F(AddressFieldTest, ParseOneLineAddressBilling) {
63 list_.push_back(
64 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"),
65 ASCIIToUTF16("billingAddress"),
66 string16(),
67 ASCIIToUTF16("text"),
68 0),
69 ASCIIToUTF16("addr1")));
70 list_.push_back(NULL);
71 iter_ = list_.begin();
72 field_.reset(AddressField::Parse(&iter_, false));
73 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
74 EXPECT_EQ(kBillingAddress, field_->FindType());
75 EXPECT_TRUE(field_->IsFullAddress());
76 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
77 ASSERT_TRUE(
78 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
79 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
80 }
81
82 TEST_F(AddressFieldTest, ParseOneLineAddressShipping) {
83 list_.push_back(
84 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address"),
85 ASCIIToUTF16("shippingAddress"),
86 string16(),
87 ASCIIToUTF16("text"),
88 0),
89 ASCIIToUTF16("addr1")));
90 list_.push_back(NULL);
91 iter_ = list_.begin();
92 field_.reset(AddressField::Parse(&iter_, false));
93 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
54 EXPECT_EQ(kShippingAddress, field_->FindType()); 94 EXPECT_EQ(kShippingAddress, field_->FindType());
55 EXPECT_TRUE(field_->IsFullAddress()); 95 EXPECT_TRUE(field_->IsFullAddress());
56 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); 96 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
57 ASSERT_TRUE( 97 ASSERT_TRUE(
58 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end()); 98 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
59 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]); 99 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
60 } 100 }
61 101
62 TEST_F(AddressFieldTest, ParseOneLineAddressEcml) { 102 TEST_F(AddressFieldTest, ParseOneLineAddressEcml) {
63 list_.push_back( 103 list_.push_back(
(...skipping 27 matching lines...) Expand all
91 new AutoFillField(webkit_glue::FormField(string16(), 131 new AutoFillField(webkit_glue::FormField(string16(),
92 string16(), 132 string16(),
93 string16(), 133 string16(),
94 ASCIIToUTF16("text"), 134 ASCIIToUTF16("text"),
95 0), 135 0),
96 ASCIIToUTF16("addr2"))); 136 ASCIIToUTF16("addr2")));
97 list_.push_back(NULL); 137 list_.push_back(NULL);
98 iter_ = list_.begin(); 138 iter_ = list_.begin();
99 field_.reset(AddressField::Parse(&iter_, false)); 139 field_.reset(AddressField::Parse(&iter_, false));
100 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get()); 140 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
101 EXPECT_EQ(kShippingAddress, field_->FindType()); 141 EXPECT_EQ(kGenericAddress, field_->FindType());
102 EXPECT_TRUE(field_->IsFullAddress()); 142 EXPECT_TRUE(field_->IsFullAddress());
103 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); 143 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
104 ASSERT_TRUE( 144 ASSERT_TRUE(
105 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end()); 145 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
106 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]); 146 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
107 ASSERT_TRUE( 147 ASSERT_TRUE(
108 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end()); 148 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end());
109 EXPECT_EQ(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]); 149 EXPECT_EQ(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]);
110 } 150 }
111 151
(...skipping 16 matching lines...) Expand all
128 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line3"), 168 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Address Line3"),
129 ASCIIToUTF16("Address"), 169 ASCIIToUTF16("Address"),
130 string16(), 170 string16(),
131 ASCIIToUTF16("text"), 171 ASCIIToUTF16("text"),
132 0), 172 0),
133 ASCIIToUTF16("addr3"))); 173 ASCIIToUTF16("addr3")));
134 list_.push_back(NULL); 174 list_.push_back(NULL);
135 iter_ = list_.begin(); 175 iter_ = list_.begin();
136 field_.reset(AddressField::Parse(&iter_, false)); 176 field_.reset(AddressField::Parse(&iter_, false));
137 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get()); 177 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
138 EXPECT_EQ(kShippingAddress, field_->FindType()); 178 EXPECT_EQ(kGenericAddress, field_->FindType());
139 EXPECT_TRUE(field_->IsFullAddress()); 179 EXPECT_TRUE(field_->IsFullAddress());
140 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); 180 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
141 ASSERT_TRUE( 181 ASSERT_TRUE(
142 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end()); 182 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
143 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]); 183 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
144 ASSERT_TRUE( 184 ASSERT_TRUE(
145 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end()); 185 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end());
146 EXPECT_EQ(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]); 186 EXPECT_EQ(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]);
147 ASSERT_TRUE( 187 ASSERT_TRUE(
148 field_type_map_.find(ASCIIToUTF16("addr3")) == field_type_map_.end()); 188 field_type_map_.find(ASCIIToUTF16("addr3")) == field_type_map_.end());
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 new AutoFillField(webkit_glue::FormField(string16(), 390 new AutoFillField(webkit_glue::FormField(string16(),
351 ASCIIToUTF16("bogus"), 391 ASCIIToUTF16("bogus"),
352 string16(), 392 string16(),
353 ASCIIToUTF16("text"), 393 ASCIIToUTF16("text"),
354 0), 394 0),
355 ASCIIToUTF16("addr2"))); 395 ASCIIToUTF16("addr2")));
356 list_.push_back(NULL); 396 list_.push_back(NULL);
357 iter_ = list_.begin(); 397 iter_ = list_.begin();
358 field_.reset(AddressField::Parse(&iter_, false)); 398 field_.reset(AddressField::Parse(&iter_, false));
359 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get()); 399 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
360 EXPECT_EQ(kShippingAddress, field_->FindType()); 400 EXPECT_EQ(kGenericAddress, field_->FindType());
361 EXPECT_TRUE(field_->IsFullAddress()); 401 EXPECT_TRUE(field_->IsFullAddress());
362 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); 402 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
363 ASSERT_TRUE( 403 ASSERT_TRUE(
364 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end()); 404 field_type_map_.find(ASCIIToUTF16("addr1")) != field_type_map_.end());
365 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]); 405 EXPECT_EQ(ADDRESS_HOME_LINE1, field_type_map_[ASCIIToUTF16("addr1")]);
366 ASSERT_FALSE( 406 ASSERT_FALSE(
367 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end()); 407 field_type_map_.find(ASCIIToUTF16("addr2")) != field_type_map_.end());
368 // The second line of the address should not match if |name| is set but 408 // The second line of the address should not match if |name| is set but
369 // |label| is empty. 409 // |label| is empty.
370 EXPECT_NE(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]); 410 EXPECT_NE(ADDRESS_HOME_LINE2, field_type_map_[ASCIIToUTF16("addr2")]);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get()); 444 ASSERT_NE(static_cast<AddressField*>(NULL), field_.get());
405 EXPECT_EQ(kGenericAddress, field_->FindType()); 445 EXPECT_EQ(kGenericAddress, field_->FindType());
406 EXPECT_FALSE(field_->IsFullAddress()); 446 EXPECT_FALSE(field_->IsFullAddress());
407 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); 447 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
408 ASSERT_TRUE( 448 ASSERT_TRUE(
409 field_type_map_.find(ASCIIToUTF16("company1")) != field_type_map_.end()); 449 field_type_map_.find(ASCIIToUTF16("company1")) != field_type_map_.end());
410 EXPECT_EQ(COMPANY_NAME, field_type_map_[ASCIIToUTF16("company1")]); 450 EXPECT_EQ(COMPANY_NAME, field_type_map_[ASCIIToUTF16("company1")]);
411 } 451 }
412 452
413 } // namespace 453 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autofill/address_field.cc ('k') | chrome/browser/autofill/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698