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

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

Powered by Google App Engine
This is Rietveld 408576698