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

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

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes from latest code review 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/json/json_reader.h"
6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "chrome/browser/autofill/wallet/wallet_address.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 const char kAddressMissingObjectId[] =
15 "{"
16 " \"phone_number\":\"phone_number\","
17 " \"postal_address\":"
18 " {"
19 " \"recipient_name\":\"recipient_name\","
20 " \"address_line\":"
21 " ["
22 " \"address_line_1\","
23 " \"address_line_2\""
24 " ],"
25 " \"locality_name\":\"locality_name\","
26 " \"administrative_area_name\":\"administrative_area_name\","
27 " \"postal_code_number\":\"postal_code_number\","
28 " \"country_name_code\":\"country_name_code\""
29 " }"
30 "}";
31
32 const char kAddressMissingCountryNameCode[] =
33 "{"
34 " \"id\":\"id\","
35 " \"phone_number\":\"phone_number\","
36 " \"postal_address\":"
37 " {"
38 " \"recipient_name\":\"recipient_name\","
39 " \"address_line\":"
40 " ["
41 " \"address_line_1\","
42 " \"address_line_2\""
43 " ],"
44 " \"locality_name\":\"locality_name\","
45 " \"administrative_area_name\":\"administrative_area_name\","
46 " \"postal_code_number\":\"postal_code_number\""
47 " }"
48 "}";
49
50 const char kAddressMissingRecipientName[] =
51 "{"
52 " \"id\":\"id\","
53 " \"phone_number\":\"phone_number\","
54 " \"postal_address\":"
55 " {"
56 " \"address_line\":"
57 " ["
58 " \"address_line_1\","
59 " \"address_line_2\""
60 " ],"
61 " \"locality_name\":\"locality_name\","
62 " \"administrative_area_name\":\"administrative_area_name\","
63 " \"postal_code_number\":\"postal_code_number\","
64 " \"country_name_code\":\"country_name_code\""
65 " }"
66 "}";
67
68 const char kAddressMissingPostalCodeNumber[] =
69 "{"
70 " \"id\":\"id\","
71 " \"phone_number\":\"phone_number\","
72 " \"postal_address\":"
73 " {"
74 " \"recipient_name\":\"recipient_name\","
75 " \"address_line\":"
76 " ["
77 " \"address_line_1\","
78 " \"address_line_2\""
79 " ],"
80 " \"locality_name\":\"locality_name\","
81 " \"administrative_area_name\":\"administrative_area_name\","
82 " \"country_name_code\":\"country_name_code\""
83 " }"
84 "}";
85
86 const char kValidAddress[] =
87 "{"
88 " \"id\":\"id\","
89 " \"phone_number\":\"phone_number\","
90 " \"postal_address\":"
91 " {"
92 " \"recipient_name\":\"recipient_name\","
93 " \"address_line\":"
94 " ["
95 " \"address_line_1\","
96 " \"address_line_2\""
97 " ],"
98 " \"locality_name\":\"locality_name\","
99 " \"administrative_area_name\":\"administrative_area_name\","
100 " \"country_name_code\":\"country_name_code\","
101 " \"postal_code_number\":\"postal_code_number\""
102 " }"
103 "}";
104
105 const char kClientAddressMissingCountryCode[] =
106 "{"
107 " \"name\":\"name\","
108 " \"address1\":\"address1\","
109 " \"address2\":\"address2\","
110 " \"city\":\"city\","
111 " \"state\":\"state\","
112 " \"postal_code\":\"postal_code\","
113 " \"phone_number\":\"phone_number\""
114 "}";
115
116 const char kClientAddressMissingPostalCode[] =
117 "{"
118 " \"name\":\"name\","
119 " \"address1\":\"address1\","
120 " \"address2\":\"address2\","
121 " \"city\":\"city\","
122 " \"state\":\"state\","
123 " \"phone_number\":\"phone_number\","
124 " \"country_code\":\"country_code\""
125 "}";
126
127 const char kClientAddressMissingName[] =
128 "{"
129 " \"address1\":\"address1\","
130 " \"address2\":\"address2\","
131 " \"city\":\"city\","
132 " \"state\":\"state\","
133 " \"postal_code\":\"postal_code\","
134 " \"phone_number\":\"phone_number\","
135 " \"country_code\":\"country_code\""
136 "}";
137
138 const char kClientValidAddress[] =
139 "{"
140 " \"name\":\"name\","
141 " \"address1\":\"address1\","
142 " \"address2\":\"address2\","
143 " \"city\":\"city\","
144 " \"state\":\"state\","
145 " \"postal_code\":\"postal_code\","
146 " \"phone_number\":\"phone_number\","
147 " \"country_code\":\"country_code\""
148 "}";
149
150 } // end anonymous namespace
151
152 namespace wallet {
153
154 class WalletAddressTest : public testing::Test {
155 public:
156 WalletAddressTest() {}
157 virtual void SetUp() {
158 dict.reset();
159 }
160 protected:
161 void SetUpDictionary(const std::string& json) {
162 scoped_ptr<Value> value(base::JSONReader::Read(json));
163 DCHECK(value.get());
164 DCHECK(value->IsType(Value::TYPE_DICTIONARY));
165 dict.reset(static_cast<DictionaryValue*>(value.release()));
166 }
167 scoped_ptr<const DictionaryValue> dict;
168 };
169
170 TEST_F(WalletAddressTest, CreateAddressWithIDMissingObjectId) {
171 SetUpDictionary(kAddressMissingObjectId);
172 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
173 }
174
175 TEST_F(WalletAddressTest, CreateAddressWithIDMissingCountryNameCode) {
176 SetUpDictionary(kAddressMissingCountryNameCode);
177 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
178 }
179
180 TEST_F(WalletAddressTest, CreateAddressWithIDMissingRecipientName) {
181 SetUpDictionary(kAddressMissingRecipientName);
182 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
183 }
184
185 TEST_F(WalletAddressTest, CreateAddressWithIDMissingPostalCodeNumber) {
186 SetUpDictionary(kAddressMissingPostalCodeNumber);
187 ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
188 }
189
190 TEST_F(WalletAddressTest, CreateAddressWithID) {
191 SetUpDictionary(kValidAddress);
192 Address address("country_name_code",
193 "recipient_name",
194 "address_line_1",
195 "address_line_2",
196 "locality_name",
197 "administrative_area_name",
198 "postal_code_number",
199 "phone_number",
200 "id");
201 ASSERT_EQ(address, *Address::CreateAddressWithID(*dict));
202 }
203
204 TEST_F(WalletAddressTest, CreateDisplayAddressMissingCountryNameCode) {
205 SetUpDictionary(kClientAddressMissingCountryCode);
206 ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict));
207 }
208
209 TEST_F(WalletAddressTest, CreateDisplayAddressMissingName) {
210 SetUpDictionary(kClientAddressMissingName);
211 ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict));
212 }
213
214 TEST_F(WalletAddressTest, CreateDisplayAddressMissingPostalCode) {
215 SetUpDictionary(kClientAddressMissingPostalCode);
216 ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict));
217 }
218
219 TEST_F(WalletAddressTest, CreateDisplayAddress) {
220 SetUpDictionary(kClientValidAddress);
221 Address address("country_code",
222 "name",
223 "address1",
224 "address2",
225 "city",
226 "state",
227 "postal_code",
228 "phone_number",
229 "");
230 ASSERT_EQ(address, *Address::CreateDisplayAddress(*dict));
231 }
232
233 } // end wallet namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698