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

Side by Side Diff: chrome/browser/autofill/wallet/wallet_items_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_items.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 const char kMaskedInstrument[] =
15 "{"
16 " \"descriptive_name\":\"descriptive_name\","
17 " \"type\":\"VISA\","
18 " \"supported_currency\":"
19 " ["
20 " \"currency\""
21 " ],"
22 " \"last_four_digits\":\"last_four_digits\","
23 " \"expiration_month\":12,"
24 " \"expiration_year\":2012,"
25 " \"brand\":\"brand\","
26 " \"billing_address\":"
27 " {"
28 " \"name\":\"name\","
29 " \"address1\":\"address1\","
30 " \"address2\":\"address2\","
31 " \"city\":\"city\","
32 " \"state\":\"state\","
33 " \"postal_code\":\"postal_code\","
34 " \"phone_number\":\"phone_number\","
35 " \"country_code\":\"country_code\""
36 " },"
37 " \"status\":\"VALID\","
38 " \"object_id\":\"object_id\""
39 "}";
40
41 const char kMaskedInstrumentMissingStatus[] =
42 "{"
43 " \"descriptive_name\":\"descriptive_name\","
44 " \"type\":\"VISA\","
45 " \"supported_currency\":"
46 " ["
47 " \"currency\""
48 " ],"
49 " \"last_four_digits\":\"last_four_digits\","
50 " \"expiration_month\":12,"
51 " \"expiration_year\":2012,"
52 " \"brand\":\"brand\","
53 " \"billing_address\":"
54 " {"
55 " \"name\":\"name\","
56 " \"address1\":\"address1\","
57 " \"address2\":\"address2\","
58 " \"city\":\"city\","
59 " \"state\":\"state\","
60 " \"postal_code\":\"postal_code\","
61 " \"phone_number\":\"phone_number\","
62 " \"country_code\":\"country_code\""
63 " },"
64 " \"object_id\":\"object_id\""
65 "}";
66
67 const char kMaskedInstrumentMissingType[] =
68 "{"
69 " \"descriptive_name\":\"descriptive_name\","
70 " \"supported_currency\":"
71 " ["
72 " \"currency\""
73 " ],"
74 " \"last_four_digits\":\"last_four_digits\","
75 " \"expiration_month\":12,"
76 " \"expiration_year\":2012,"
77 " \"brand\":\"brand\","
78 " \"billing_address\":"
79 " {"
80 " \"name\":\"name\","
81 " \"address1\":\"address1\","
82 " \"address2\":\"address2\","
83 " \"city\":\"city\","
84 " \"state\":\"state\","
85 " \"postal_code\":\"postal_code\","
86 " \"phone_number\":\"phone_number\","
87 " \"country_code\":\"country_code\""
88 " },"
89 " \"status\":\"VALID\","
90 " \"object_id\":\"object_id\""
91 "}";
92
93 const char kMaskedInstrumentMissingLastFourDigits[] =
94 "{"
95 " \"descriptive_name\":\"descriptive_name\","
96 " \"type\":\"VISA\","
97 " \"supported_currency\":"
98 " ["
99 " \"currency\""
100 " ],"
101 " \"expiration_month\":12,"
102 " \"expiration_year\":2012,"
103 " \"brand\":\"brand\","
104 " \"billing_address\":"
105 " {"
106 " \"name\":\"name\","
107 " \"address1\":\"address1\","
108 " \"address2\":\"address2\","
109 " \"city\":\"city\","
110 " \"state\":\"state\","
111 " \"postal_code\":\"postal_code\","
112 " \"phone_number\":\"phone_number\","
113 " \"country_code\":\"country_code\""
114 " },"
115 " \"status\":\"VALID\","
116 " \"object_id\":\"object_id\""
117 "}";
118
119 const char kMaskedInstrumentMissingAddress[] =
120 "{"
121 " \"descriptive_name\":\"descriptive_name\","
122 " \"type\":\"VISA\","
123 " \"supported_currency\":"
124 " ["
125 " \"currency\""
126 " ],"
127 " \"last_four_digits\":\"last_four_digits\","
128 " \"expiration_month\":12,"
129 " \"expiration_year\":2012,"
130 " \"brand\":\"brand\","
131 " \"status\":\"VALID\","
132 " \"object_id\":\"object_id\""
133 "}";
134
135 const char kMaskedInstrumentMalformedAddress[] =
136 "{"
137 " \"descriptive_name\":\"descriptive_name\","
138 " \"type\":\"VISA\","
139 " \"supported_currency\":"
140 " ["
141 " \"currency\""
142 " ],"
143 " \"last_four_digits\":\"last_four_digits\","
144 " \"expiration_month\":12,"
145 " \"expiration_year\":2012,"
146 " \"brand\":\"brand\","
147 " \"billing_address\":"
148 " {"
149 " \"address1\":\"address1\","
150 " \"address2\":\"address2\","
151 " \"city\":\"city\","
152 " \"state\":\"state\","
153 " \"phone_number\":\"phone_number\","
154 " \"country_code\":\"country_code\""
155 " },"
156 " \"status\":\"VALID\","
157 " \"object_id\":\"object_id\""
158 "}";
159
160 const char kMaskedInstrumentMissingObjectId[] =
161 "{"
162 " \"descriptive_name\":\"descriptive_name\","
163 " \"type\":\"VISA\","
164 " \"supported_currency\":"
165 " ["
166 " \"currency\""
167 " ],"
168 " \"last_four_digits\":\"last_four_digits\","
169 " \"expiration_month\":12,"
170 " \"expiration_year\":2012,"
171 " \"brand\":\"brand\","
172 " \"billing_address\":"
173 " {"
174 " \"name\":\"name\","
175 " \"address1\":\"address1\","
176 " \"address2\":\"address2\","
177 " \"city\":\"city\","
178 " \"state\":\"state\","
179 " \"postal_code\":\"postal_code\","
180 " \"phone_number\":\"phone_number\","
181 " \"country_code\":\"country_code\""
182 " },"
183 " \"status\":\"VALID\""
184 "}";
185
186 const char kLegalDocument[] =
187 "{"
188 " \"legal_document_id\":\"doc_id\","
189 " \"display_name\":\"display_name\","
190 " \"document\":\"doc_body\""
191 "}";
192
193 const char kLegalDocumentMissingDocumentId[] =
194 "{"
195 " \"display_name\":\"display_name\","
196 " \"document\":\"doc_body\""
197 "}";
198
199 const char kLegalDocumentMissingDisplayName[] =
200 "{"
201 " \"legal_document_id\":\"doc_id\","
202 " \"document\":\"doc_body\""
203 "}";
204
205 const char kLegalDocumentMissingDocumentBody[] =
206 "{"
207 " \"legal_document_id\":\"doc_id\","
208 " \"display_name\":\"display_name\""
209 "}";
210
211 const char kWalletItemsWithRequiredActions[] =
212 "{"
213 " \"google_transaction_id\":\"google_transaction_id\","
214 " \"required_action\":"
215 " ["
216 " \"required_action\""
217 " ]"
218 "}";
219
220 const char kWalletItems[] =
221 "{"
222 " \"required_action\":"
223 " ["
224 " ],"
225 " \"google_transaction_id\":\"google_transaction_id\","
226 " \"instrument\":"
227 " ["
228 " {"
229 " \"descriptive_name\":\"descriptive_name\","
230 " \"type\":\"VISA\","
231 " \"supported_currency\":"
232 " ["
233 " \"currency\""
234 " ],"
235 " \"last_four_digits\":\"last_four_digits\","
236 " \"expiration_month\":12,"
237 " \"expiration_year\":2012,"
238 " \"brand\":\"brand\","
239 " \"billing_address\":"
240 " {"
241 " \"name\":\"name\","
242 " \"address1\":\"address1\","
243 " \"address2\":\"address2\","
244 " \"city\":\"city\","
245 " \"state\":\"state\","
246 " \"postal_code\":\"postal_code\","
247 " \"phone_number\":\"phone_number\","
248 " \"country_code\":\"country_code\""
249 " },"
250 " \"status\":\"VALID\","
251 " \"object_id\":\"object_id\""
252 " }"
253 " ],"
254 " \"default_instrument_id\":\"default_instrument_id\","
255 " \"address\":"
256 " ["
257 " {"
258 " \"id\":\"id\","
259 " \"phone_number\":\"phone_number\","
260 " \"postal_address\":"
261 " {"
262 " \"recipient_name\":\"recipient_name\","
263 " \"address_line_1\":\"address_line_1\","
264 " \"address_line_2\":\"address_line_2\","
265 " \"locality_name\":\"locality_name\","
266 " \"administrative_area_name\":\"administrative_area_name\","
267 " \"postal_code_number\":\"postal_code_number\","
268 " \"country_name_code\":\"country_name_code\""
269 " }"
270 " }"
271 " ],"
272 " \"default_address_id\":\"default_address_id\","
273 " \"required_legal_document\":"
274 " ["
275 " {"
276 " \"legal_document_id\":\"doc_id\","
277 " \"display_name\":\"display_name\","
278 " \"document\":\"doc_body\""
279 " }"
280 " ]"
281 "}";
282
283 } // end anonymous namespace
284
285 namespace wallet {
286
287 class WalletItemsTest : public testing::Test {
288 public:
289 WalletItemsTest() {}
290 virtual void SetUp() {
291 dict.reset();
292 }
293 protected:
294 void SetUpDictionary(const std::string& json) {
295 scoped_ptr<Value> value(base::JSONReader::Read(json));
296 DCHECK(value.get());
297 DCHECK(value->IsType(Value::TYPE_DICTIONARY));
298 dict.reset(static_cast<DictionaryValue*>(value.release()));
299 }
300 scoped_ptr<DictionaryValue> dict;
301 };
302
303 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingStatus) {
304 SetUpDictionary(kMaskedInstrumentMissingStatus);
305 ASSERT_EQ(NULL,
306 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
307 }
308
309 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingType) {
310 SetUpDictionary(kMaskedInstrumentMissingType);
311 ASSERT_EQ(NULL,
312 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
313 }
314
315 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingLastFourDigits) {
316 SetUpDictionary(kMaskedInstrumentMissingLastFourDigits);
317 ASSERT_EQ(NULL,
318 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
319 }
320
321 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingAddress) {
322 SetUpDictionary(kMaskedInstrumentMissingAddress);
323 ASSERT_EQ(NULL,
324 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
325 }
326
327 TEST_F(WalletItemsTest, CreateMaskedInstrumentMalformedAddress) {
328 SetUpDictionary(kMaskedInstrumentMalformedAddress);
329 ASSERT_EQ(NULL,
330 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
331 }
332
333 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingObjectId) {
334 SetUpDictionary(kMaskedInstrumentMissingObjectId);
335 ASSERT_EQ(NULL,
336 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
337 }
338
339 TEST_F(WalletItemsTest, CreateMaskedInstrument) {
340 SetUpDictionary(kMaskedInstrument);
341 Address* address = new Address("country_code",
342 "name",
343 "address1",
344 "address2",
345 "city",
346 "state",
347 "postal_code",
348 "phone_number",
349 "");
350 std::vector<std::string> supported_currencies;
351 supported_currencies.push_back("currency");
352 WalletItems::MaskedInstrument masked_instrument(
353 "descriptive_name",
354 WalletItems::MaskedInstrument::VISA,
355 supported_currencies,
356 "last_four_digits",
357 12,
358 2012,
359 "brand",
360 address,
361 WalletItems::MaskedInstrument::VALID,
362 "object_id");
363 ASSERT_EQ(masked_instrument,
364 *WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
365 }
366
367 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDocId) {
368 SetUpDictionary(kLegalDocumentMissingDocumentId);
369 ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict));
370 }
371
372 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDisplayName) {
373 SetUpDictionary(kLegalDocumentMissingDisplayName);
374 ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict));
375 }
376
377 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDocBody) {
378 SetUpDictionary(kLegalDocumentMissingDocumentBody);
379 ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict));
380 }
381
382 TEST_F(WalletItemsTest, CreateLegalDocument) {
383 SetUpDictionary(kLegalDocument);
384 WalletItems::LegalDocument expected("doc_id", "display_name", "doc_body");
385 ASSERT_EQ(expected,
386 *WalletItems::LegalDocument::CreateLegalDocument(*dict));
387 }
388
389 TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) {
390 SetUpDictionary(kWalletItemsWithRequiredActions);
391 std::vector<std::string> required_actions;
392 required_actions.push_back("required_action");
393 WalletItems expected(required_actions, "google_transaction_id", "", "");
394 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict));
395 }
396
397 TEST_F(WalletItemsTest, CreateWalletItems) {
398 SetUpDictionary(kWalletItems);
399 std::vector<std::string> required_actions;
400 WalletItems expected(required_actions,
401 "google_transaction_id",
402 "default_instrument_id",
403 "default_address_id");
404
405 Address* billing_address = new Address("country_code",
406 "name",
407 "address1",
408 "address2",
409 "city",
410 "state",
411 "postal_code",
412 "phone_number",
413 "");
414 std::vector<std::string> supported_currencies;
415 supported_currencies.push_back("currency");
416 WalletItems::MaskedInstrument* masked_instrument =
417 new WalletItems::MaskedInstrument("descriptive_name",
418 WalletItems::MaskedInstrument::VISA,
419 supported_currencies,
420 "last_four_digits",
421 12,
422 2012,
423 "brand",
424 billing_address,
425 WalletItems::MaskedInstrument::VALID,
426 "object_id");
427 expected.AddInstrument(masked_instrument);
428
429 Address* shipping_address = new Address("country_code",
430 "name",
431 "address1",
432 "address2",
433 "city",
434 "state",
435 "postal_code",
436 "phone_number",
437 "id");
438 expected.AddAddress(shipping_address);
439
440 WalletItems::LegalDocument* legal_document =
441 new WalletItems::LegalDocument("doc_id",
442 "display_name",
443 "doc_body");
444 expected.AddLegalDocument(legal_document);
445
446 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict));
447 }
448
449 } // end wallet namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698