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

Side by Side Diff: chrome/browser/autofill/wallet/full_wallet_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/full_wallet.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 const char kFullWalletValidResponse[] =
15 "{"
16 " \"expiration_month\":12,"
17 " \"expiration_year\":2012,"
18 " \"iin\":\"iin\","
19 " \"rest\":\"rest\","
20 " \"billing_address\":"
21 " {"
22 " \"id\":\"id\","
23 " \"phone_number\":\"phone_number\","
24 " \"postal_address\":"
25 " {"
26 " \"recipient_name\":\"recipient_name\","
27 " \"address_line\":"
28 " ["
29 " \"address_line_1\","
30 " \"address_line_2\""
31 " ],"
32 " \"locality_name\":\"locality_name\","
33 " \"administrative_area_name\":\"administrative_area_name\","
34 " \"postal_code_number\":\"postal_code_number\","
35 " \"country_name_code\":\"country_name_code\""
36 " }"
37 " },"
38 " \"shipping_address\":"
39 " {"
40 " \"id\":\"ship_id\","
41 " \"phone_number\":\"ship_phone_number\","
42 " \"postal_address\":"
43 " {"
44 " \"recipient_name\":\"ship_recipient_name\","
45 " \"address_line\":"
46 " ["
47 " \"ship_address_line_1\","
48 " \"ship_address_line_2\""
49 " ],"
50 " \"locality_name\":\"ship_locality_name\","
51 " \"administrative_area_name\":\"ship_administrative_area_name\","
52 " \"postal_code_number\":\"ship_postal_code_number\","
53 " \"country_name_code\":\"ship_country_name_code\""
54 " }"
55 " },"
56 " \"required_action\":"
57 " ["
58 " ]"
59 "}";
60
61 const char kFullWalletMissingExpirationMonth[] =
62 "{"
63 " \"expiration_year\":2012,"
64 " \"iin\":\"iin\","
65 " \"rest\":\"rest\","
66 " \"billing_address\":"
67 " {"
68 " \"id\":\"id\","
69 " \"phone_number\":\"phone_number\","
70 " \"postal_address\":"
71 " {"
72 " \"recipient_name\":\"recipient_name\","
73 " \"address_line\":"
74 " ["
75 " \"address_line_1\","
76 " \"address_line_2\""
77 " ],"
78 " \"locality_name\":\"locality_name\","
79 " \"administrative_area_name\":\"administrative_area_name\","
80 " \"postal_code_number\":\"postal_code_number\","
81 " \"country_name_code\":\"country_name_code\""
82 " }"
83 " },"
84 " \"shipping_address\":"
85 " {"
86 " \"id\":\"ship_id\","
87 " \"phone_number\":\"ship_phone_number\","
88 " \"postal_address\":"
89 " {"
90 " \"recipient_name\":\"ship_recipient_name\","
91 " \"address_line\":"
92 " ["
93 " \"ship_address_line_1\","
94 " \"ship_address_line_2\""
95 " ],"
96 " \"locality_name\":\"ship_locality_name\","
97 " \"administrative_area_name\":\"ship_administrative_area_name\","
98 " \"postal_code_number\":\"ship_postal_code_number\","
99 " \"country_name_code\":\"ship_country_name_code\""
100 " }"
101 " },"
102 " \"required_action\":"
103 " ["
104 " ]"
105 "}";
106
107 const char kFullWalletMissingExpirationYear[] =
108 "{"
109 " \"expiration_month\":12,"
110 " \"iin\":\"iin\","
111 " \"rest\":\"rest\","
112 " \"billing_address\":"
113 " {"
114 " \"id\":\"id\","
115 " \"phone_number\":\"phone_number\","
116 " \"postal_address\":"
117 " {"
118 " \"recipient_name\":\"recipient_name\","
119 " \"address_line\":"
120 " ["
121 " \"address_line_1\","
122 " \"address_line_2\""
123 " ],"
124 " \"locality_name\":\"locality_name\","
125 " \"administrative_area_name\":\"administrative_area_name\","
126 " \"postal_code_number\":\"postal_code_number\","
127 " \"country_name_code\":\"country_name_code\""
128 " }"
129 " },"
130 " \"shipping_address\":"
131 " {"
132 " \"id\":\"ship_id\","
133 " \"phone_number\":\"ship_phone_number\","
134 " \"postal_address\":"
135 " {"
136 " \"recipient_name\":\"ship_recipient_name\","
137 " \"address_line\":"
138 " ["
139 " \"ship_address_line_1\","
140 " \"ship_address_line_2\""
141 " ],"
142 " \"locality_name\":\"ship_locality_name\","
143 " \"administrative_area_name\":\"ship_administrative_area_name\","
144 " \"postal_code_number\":\"ship_postal_code_number\","
145 " \"country_name_code\":\"ship_country_name_code\""
146 " }"
147 " },"
148 " \"required_action\":"
149 " ["
150 " ]"
151 "}";
152
153 const char kFullWalletMissingIin[] =
154 "{"
155 " \"expiration_month\":12,"
156 " \"expiration_year\":2012,"
157 " \"rest\":\"rest\","
158 " \"billing_address\":"
159 " {"
160 " \"id\":\"id\","
161 " \"phone_number\":\"phone_number\","
162 " \"postal_address\":"
163 " {"
164 " \"recipient_name\":\"recipient_name\","
165 " \"address_line\":"
166 " ["
167 " \"address_line_1\","
168 " \"address_line_2\""
169 " ],"
170 " \"locality_name\":\"locality_name\","
171 " \"administrative_area_name\":\"administrative_area_name\","
172 " \"postal_code_number\":\"postal_code_number\","
173 " \"country_name_code\":\"country_name_code\""
174 " }"
175 " },"
176 " \"shipping_address\":"
177 " {"
178 " \"id\":\"ship_id\","
179 " \"phone_number\":\"ship_phone_number\","
180 " \"postal_address\":"
181 " {"
182 " \"recipient_name\":\"ship_recipient_name\","
183 " \"address_line\":"
184 " ["
185 " \"ship_address_line_1\","
186 " \"ship_address_line_2\""
187 " ],"
188 " \"locality_name\":\"ship_locality_name\","
189 " \"administrative_area_name\":\"ship_administrative_area_name\","
190 " \"postal_code_number\":\"ship_postal_code_number\","
191 " \"country_name_code\":\"ship_country_name_code\""
192 " }"
193 " },"
194 " \"required_action\":"
195 " ["
196 " ]"
197 "}";
198
199 const char kFullWalletMissingRest[] =
200 "{"
201 " \"expiration_month\":12,"
202 " \"expiration_year\":2012,"
203 " \"iin\":\"iin\","
204 " \"billing_address\":"
205 " {"
206 " \"id\":\"id\","
207 " \"phone_number\":\"phone_number\","
208 " \"postal_address\":"
209 " {"
210 " \"recipient_name\":\"recipient_name\","
211 " \"address_line\":"
212 " ["
213 " \"address_line_1\","
214 " \"address_line_2\""
215 " ],"
216 " \"locality_name\":\"locality_name\","
217 " \"administrative_area_name\":\"administrative_area_name\","
218 " \"postal_code_number\":\"postal_code_number\","
219 " \"country_name_code\":\"country_name_code\""
220 " }"
221 " },"
222 " \"shipping_address\":"
223 " {"
224 " \"id\":\"ship_id\","
225 " \"phone_number\":\"ship_phone_number\","
226 " \"postal_address\":"
227 " {"
228 " \"recipient_name\":\"ship_recipient_name\","
229 " \"address_line\":"
230 " ["
231 " \"ship_address_line_1\","
232 " \"ship_address_line_2\""
233 " ],"
234 " \"locality_name\":\"ship_locality_name\","
235 " \"administrative_area_name\":\"ship_administrative_area_name\","
236 " \"postal_code_number\":\"ship_postal_code_number\","
237 " \"country_name_code\":\"ship_country_name_code\""
238 " }"
239 " },"
240 " \"required_action\":"
241 " ["
242 " ]"
243 "}";
244
245 const char kFullWalletMissingBillingAddress[] =
246 "{"
247 " \"expiration_month\":12,"
248 " \"expiration_year\":2012,"
249 " \"iin\":\"iin\","
250 " \"rest\":\"rest\","
251 " \"shipping_address\":"
252 " {"
253 " \"id\":\"ship_id\","
254 " \"phone_number\":\"ship_phone_number\","
255 " \"postal_address\":"
256 " {"
257 " \"recipient_name\":\"ship_recipient_name\","
258 " \"address_line\":"
259 " ["
260 " \"ship_address_line_1\","
261 " \"ship_address_line_2\""
262 " ],"
263 " \"locality_name\":\"ship_locality_name\","
264 " \"administrative_area_name\":\"ship_administrative_area_name\","
265 " \"postal_code_number\":\"ship_postal_code_number\","
266 " \"country_name_code\":\"ship_country_name_code\""
267 " }"
268 " },"
269 " \"required_action\":"
270 " ["
271 " ]"
272 "}";
273
274 const char kFullWalletWithRequiredActions[] =
275 "{"
276 " \"required_action\":"
277 " ["
278 " \"required_action\""
279 " ]"
280 "}";
281
282 const char kFullWalletMalformedBillingAddress[] =
283 "{"
284 " \"expiration_month\":12,"
285 " \"expiration_year\":2012,"
286 " \"iin\":\"iin\","
287 " \"rest\":\"rest\","
288 " \"billing_address\":"
289 " {"
290 " \"id\":\"id\","
291 " \"phone_number\":\"phone_number\","
292 " \"postal_address\":"
293 " {"
294 " \"recipient_name\":\"recipient_name\","
295 " \"address_line\":"
296 " ["
297 " \"address_line_1\","
298 " \"address_line_2\""
299 " ],"
300 " \"locality_name\":\"locality_name\","
301 " \"administrative_area_name\":\"administrative_area_name\""
302 " }"
303 " },"
304 " \"shipping_address\":"
305 " {"
306 " \"id\":\"ship_id\","
307 " \"phone_number\":\"ship_phone_number\","
308 " \"postal_address\":"
309 " {"
310 " \"recipient_name\":\"ship_recipient_name\","
311 " \"address_line\":"
312 " ["
313 " \"ship_address_line_1\","
314 " \"ship_address_line_2\""
315 " ],"
316 " \"locality_name\":\"ship_locality_name\","
317 " \"administrative_area_name\":\"ship_administrative_area_name\","
318 " \"postal_code_number\":\"ship_postal_code_number\","
319 " \"country_name_code\":\"ship_country_name_code\""
320 " }"
321 " },"
322 " \"required_action\":"
323 " ["
324 " ]"
325 "}";
326
327 } // end anonymous namespace
328
329 namespace wallet {
330
331 class FullWalletTest : public testing::Test {
332 public:
333 FullWalletTest() {}
334 virtual void SetUp() {
335 dict.reset();
336 }
337 protected:
338 void SetUpDictionary(const std::string& json) {
339 scoped_ptr<Value> value(base::JSONReader::Read(json));
340 DCHECK(value.get());
341 DCHECK(value->IsType(Value::TYPE_DICTIONARY));
342 dict.reset(static_cast<DictionaryValue*>(value.release()));
343 }
344 scoped_ptr<DictionaryValue> dict;
345 };
346
347 TEST_F(FullWalletTest, CreateFullWalletMissingExpirationMonth) {
348 SetUpDictionary(kFullWalletMissingExpirationMonth);
349 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict));
350 }
351
352 TEST_F(FullWalletTest, CreateFullWalletMissingExpirationYear) {
353 SetUpDictionary(kFullWalletMissingExpirationYear);
354 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict));
355 }
356
357 TEST_F(FullWalletTest, CreateFullWalletMissingIin) {
358 SetUpDictionary(kFullWalletMissingIin);
359 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict));
360 }
361
362 TEST_F(FullWalletTest, CreateFullWalletMissingRest) {
363 SetUpDictionary(kFullWalletMissingRest);
364 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict));
365 }
366
367 TEST_F(FullWalletTest, CreateFullWalletMissingBillingAddress) {
368 SetUpDictionary(kFullWalletMissingBillingAddress);
369 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict));
370 }
371
372 TEST_F(FullWalletTest, CreateFullWalletMalformedBillingAddress) {
373 SetUpDictionary(kFullWalletMalformedBillingAddress);
374 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict));
375 }
376
377 TEST_F(FullWalletTest, CreateFullWalletWithRequiredAction) {
378 SetUpDictionary(kFullWalletWithRequiredActions);
379 std::vector<std::string> required_actions;
380 required_actions.push_back("required_action");
381 FullWallet full_wallet(-1,
382 -1,
383 "",
384 "",
385 NULL,
386 NULL,
387 required_actions);
388 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict));
389 }
390
391 TEST_F(FullWalletTest, CreateFullWallet) {
392 SetUpDictionary(kFullWalletValidResponse);
393 Address* billing_address = new Address("country_name_code",
394 "recipient_name",
395 "address_line_1",
396 "address_line_2",
397 "locality_name",
398 "administrative_area_name",
399 "postal_code_number",
400 "phone_number",
401 "id");
402 Address* shipping_address = new Address("ship_country_name_code",
403 "ship_recipient_name",
404 "ship_address_line_1",
405 "ship_address_line_2",
406 "ship_locality_name",
407 "ship_administrative_area_name",
408 "ship_postal_code_number",
409 "ship_phone_number",
410 "ship_id");
411 std::vector<std::string> required_actions;
412 FullWallet full_wallet(12,
413 2012,
414 "iin",
415 "rest",
416 billing_address,
417 shipping_address,
418 required_actions);
419 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict));
420 }
421
422 } // end wallet namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698