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

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

Powered by Google App Engine
This is Rietveld 408576698