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

Side by Side Diff: chrome/browser/autofill/wallet/wallet_address_unittest.cc

Issue 12388059: Adds wallet::Address::CreateAddress() for when IDs are optional (for billing addresses). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_address.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/autofill/wallet/wallet_address.h" 10 #include "chrome/browser/autofill/wallet/wallet_address.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 protected: 159 protected:
160 void SetUpDictionary(const std::string& json) { 160 void SetUpDictionary(const std::string& json) {
161 scoped_ptr<Value> value(base::JSONReader::Read(json)); 161 scoped_ptr<Value> value(base::JSONReader::Read(json));
162 DCHECK(value.get()); 162 DCHECK(value.get());
163 DCHECK(value->IsType(Value::TYPE_DICTIONARY)); 163 DCHECK(value->IsType(Value::TYPE_DICTIONARY));
164 dict_.reset(static_cast<DictionaryValue*>(value.release())); 164 dict_.reset(static_cast<DictionaryValue*>(value.release()));
165 } 165 }
166 scoped_ptr<const DictionaryValue> dict_; 166 scoped_ptr<const DictionaryValue> dict_;
167 }; 167 };
168 168
169 TEST_F(WalletAddressTest, CreateAddressMissingObjectId) {
170 SetUpDictionary(kAddressMissingObjectId);
171 Address address("country_name_code",
172 ASCIIToUTF16("recipient_name"),
173 ASCIIToUTF16("address_line_1"),
174 ASCIIToUTF16("address_line_2"),
175 ASCIIToUTF16("locality_name"),
176 ASCIIToUTF16("administrative_area_name"),
177 ASCIIToUTF16("postal_code_number"),
178 ASCIIToUTF16("phone_number"),
179 "");
180 ASSERT_EQ(address, *Address::CreateAddress(*dict_));
181 }
182
169 TEST_F(WalletAddressTest, CreateAddressWithIDMissingObjectId) { 183 TEST_F(WalletAddressTest, CreateAddressWithIDMissingObjectId) {
170 SetUpDictionary(kAddressMissingObjectId); 184 SetUpDictionary(kAddressMissingObjectId);
171 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); 185 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get());
172 } 186 }
173 187
174 TEST_F(WalletAddressTest, CreateAddressWithIDMissingCountryNameCode) { 188 TEST_F(WalletAddressTest, CreateAddressMissingCountryNameCode) {
175 SetUpDictionary(kAddressMissingCountryNameCode); 189 SetUpDictionary(kAddressMissingCountryNameCode);
190 ASSERT_EQ(NULL, Address::CreateAddress(*dict_).get());
176 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); 191 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get());
177 } 192 }
178 193
179 TEST_F(WalletAddressTest, CreateAddressWithIDMissingRecipientName) { 194 TEST_F(WalletAddressTest, CreateAddressMissingRecipientName) {
180 SetUpDictionary(kAddressMissingRecipientName); 195 SetUpDictionary(kAddressMissingRecipientName);
196 ASSERT_EQ(NULL, Address::CreateAddress(*dict_).get());
181 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); 197 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get());
182 } 198 }
183 199
184 TEST_F(WalletAddressTest, CreateAddressWithIDMissingPostalCodeNumber) { 200 TEST_F(WalletAddressTest, CreateAddressMissingPostalCodeNumber) {
185 SetUpDictionary(kAddressMissingPostalCodeNumber); 201 SetUpDictionary(kAddressMissingPostalCodeNumber);
202 ASSERT_EQ(NULL, Address::CreateAddress(*dict_).get());
186 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); 203 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict_).get());
187 } 204 }
188 205
189 TEST_F(WalletAddressTest, CreateAddressWithID) { 206 TEST_F(WalletAddressTest, CreateAddressWithID) {
190 SetUpDictionary(kValidAddress); 207 SetUpDictionary(kValidAddress);
191 Address address("country_name_code", 208 Address address("country_name_code",
192 ASCIIToUTF16("recipient_name"), 209 ASCIIToUTF16("recipient_name"),
193 ASCIIToUTF16("address_line_1"), 210 ASCIIToUTF16("address_line_1"),
194 ASCIIToUTF16("address_line_2"), 211 ASCIIToUTF16("address_line_2"),
195 ASCIIToUTF16("locality_name"), 212 ASCIIToUTF16("locality_name"),
196 ASCIIToUTF16("administrative_area_name"), 213 ASCIIToUTF16("administrative_area_name"),
197 ASCIIToUTF16("postal_code_number"), 214 ASCIIToUTF16("postal_code_number"),
198 ASCIIToUTF16("phone_number"), 215 ASCIIToUTF16("phone_number"),
199 "id"); 216 "id");
217 ASSERT_EQ(address, *Address::CreateAddress(*dict_));
200 ASSERT_EQ(address, *Address::CreateAddressWithID(*dict_)); 218 ASSERT_EQ(address, *Address::CreateAddressWithID(*dict_));
201 } 219 }
202 220
203 TEST_F(WalletAddressTest, CreateDisplayAddressMissingCountryNameCode) { 221 TEST_F(WalletAddressTest, CreateDisplayAddressMissingCountryNameCode) {
204 SetUpDictionary(kClientAddressMissingCountryCode); 222 SetUpDictionary(kClientAddressMissingCountryCode);
205 ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); 223 ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get());
206 } 224 }
207 225
208 TEST_F(WalletAddressTest, CreateDisplayAddressMissingName) { 226 TEST_F(WalletAddressTest, CreateDisplayAddressMissingName) {
209 SetUpDictionary(kClientAddressMissingName); 227 SetUpDictionary(kClientAddressMissingName);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 ASCIIToUTF16("administrative_area_name"), 304 ASCIIToUTF16("administrative_area_name"),
287 ASCIIToUTF16("postal_code_number"), 305 ASCIIToUTF16("postal_code_number"),
288 ASCIIToUTF16("phone_number"), 306 ASCIIToUTF16("phone_number"),
289 "id"); 307 "id");
290 308
291 EXPECT_TRUE(expected.Equals(address.ToDictionaryWithID().get())); 309 EXPECT_TRUE(expected.Equals(address.ToDictionaryWithID().get()));
292 } 310 }
293 311
294 } // namespace wallet 312 } // namespace wallet
295 } // namespace autofill 313 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_address.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698