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

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: Fixing HexStringToInt 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 } // anonymous namespace
284
285 namespace wallet {
286
287 class WalletItemsTest : public testing::Test {
288 public:
289 WalletItemsTest() {}
290 protected:
291 void SetUpDictionary(const std::string& json) {
292 scoped_ptr<Value> value(base::JSONReader::Read(json));
293 DCHECK(value.get());
294 DCHECK(value->IsType(Value::TYPE_DICTIONARY));
295 dict.reset(static_cast<DictionaryValue*>(value.release()));
296 }
297 scoped_ptr<DictionaryValue> dict;
298 };
299
300 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingStatus) {
301 SetUpDictionary(kMaskedInstrumentMissingStatus);
302 ASSERT_EQ(NULL,
303 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get());
304 }
305
306 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingType) {
307 SetUpDictionary(kMaskedInstrumentMissingType);
308 ASSERT_EQ(NULL,
309 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get());
310 }
311
312 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingLastFourDigits) {
313 SetUpDictionary(kMaskedInstrumentMissingLastFourDigits);
314 ASSERT_EQ(NULL,
315 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get());
316 }
317
318 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingAddress) {
319 SetUpDictionary(kMaskedInstrumentMissingAddress);
320 ASSERT_EQ(NULL,
321 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get());
322 }
323
324 TEST_F(WalletItemsTest, CreateMaskedInstrumentMalformedAddress) {
325 SetUpDictionary(kMaskedInstrumentMalformedAddress);
326 ASSERT_EQ(NULL,
327 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get());
328 }
329
330 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingObjectId) {
331 SetUpDictionary(kMaskedInstrumentMissingObjectId);
332 ASSERT_EQ(NULL,
333 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get());
334 }
335
336 TEST_F(WalletItemsTest, CreateMaskedInstrument) {
337 SetUpDictionary(kMaskedInstrument);
338 scoped_ptr<Address> address(new Address("country_code",
339 "name",
340 "address1",
341 "address2",
342 "city",
343 "state",
344 "postal_code",
345 "phone_number",
346 ""));
347 std::vector<std::string> supported_currencies;
348 supported_currencies.push_back("currency");
349 WalletItems::MaskedInstrument masked_instrument(
350 "descriptive_name",
351 WalletItems::MaskedInstrument::VISA,
352 supported_currencies,
353 "last_four_digits",
354 12,
355 2012,
356 "brand",
357 address.Pass(),
358 WalletItems::MaskedInstrument::VALID,
359 "object_id");
360 ASSERT_EQ(masked_instrument,
361 *WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict));
362 }
363
364 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDocId) {
365 SetUpDictionary(kLegalDocumentMissingDocumentId);
366 ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get());
367 }
368
369 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDisplayName) {
370 SetUpDictionary(kLegalDocumentMissingDisplayName);
371 ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get());
372 }
373
374 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDocBody) {
375 SetUpDictionary(kLegalDocumentMissingDocumentBody);
376 ASSERT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get());
377 }
378
379 TEST_F(WalletItemsTest, CreateLegalDocument) {
380 SetUpDictionary(kLegalDocument);
381 WalletItems::LegalDocument expected("doc_id", "display_name", "doc_body");
382 ASSERT_EQ(expected,
383 *WalletItems::LegalDocument::CreateLegalDocument(*dict));
384 }
385
386 TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) {
387 SetUpDictionary(kWalletItemsWithRequiredActions);
388 std::vector<std::string> required_actions;
389 required_actions.push_back("required_action");
390 WalletItems expected(required_actions, "google_transaction_id", "", "");
391 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict));
392 }
393
394 TEST_F(WalletItemsTest, CreateWalletItems) {
395 SetUpDictionary(kWalletItems);
396 std::vector<std::string> required_actions;
397 WalletItems expected(required_actions,
398 "google_transaction_id",
399 "default_instrument_id",
400 "default_address_id");
401
402 scoped_ptr<Address> billing_address(new Address("country_code",
403 "name",
404 "address1",
405 "address2",
406 "city",
407 "state",
408 "postal_code",
409 "phone_number",
410 ""));
411 std::vector<std::string> supported_currencies;
412 supported_currencies.push_back("currency");
413 scoped_ptr<WalletItems::MaskedInstrument> masked_instrument(
414 new WalletItems::MaskedInstrument("descriptive_name",
415 WalletItems::MaskedInstrument::VISA,
416 supported_currencies,
417 "last_four_digits",
418 12,
419 2012,
420 "brand",
421 billing_address.Pass(),
422 WalletItems::MaskedInstrument::VALID,
423 "object_id"));
424 expected.AddInstrument(masked_instrument.Pass());
425
426 scoped_ptr<Address> shipping_address(new Address("country_code",
427 "name",
428 "address1",
429 "address2",
430 "city",
431 "state",
432 "postal_code",
433 "phone_number",
434 "id"));
435 expected.AddAddress(shipping_address.Pass());
436
437 scoped_ptr<WalletItems::LegalDocument> legal_document(
438 new WalletItems::LegalDocument("doc_id",
439 "display_name",
440 "doc_body"));
441 expected.AddLegalDocument(legal_document.Pass());
442
443 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict));
444 }
445
446 } // namespace wallet
447
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_items.cc ('k') | chrome/browser/autofill/wallet/wallet_service_url.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698