1 // Copyright 2013 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/strings/utf_string_conversions.h" 6 #include "base/values.h" 7 #include "components/autofill/content/browser/wallet/instrument.h" 8 #include "components/autofill/content/browser/wallet/wallet_address.h" 9 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 namespace { 13 14 const char kPrimaryAccountNumber[] = "4444444444444448"; 15 const char kCardVerificationNumber[] = "123"; 16 const char kLastFourDigits[] = "4448"; 17 18 } 19 20 namespace autofill { 21 namespace wallet { 22 23 TEST(Instrument, LastFourDigits) { 24 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), 25 ASCIIToUTF16(kCardVerificationNumber), 26 12, 27 2015, 28 Instrument::VISA, 29 GetTestShippingAddress().Pass()); 30 31 EXPECT_EQ(ASCIIToUTF16(kLastFourDigits), instrument.last_four_digits()); 32 } 33 34 TEST(Instrument, ToDictionary) { 35 base::DictionaryValue expected; 36 expected.SetString("type", "CREDIT_CARD"); 37 expected.SetInteger("credit_card.exp_month", 12); 38 expected.SetInteger("credit_card.exp_year", 2015); 39 expected.SetString("credit_card.last_4_digits", kLastFourDigits); 40 expected.SetString("credit_card.fop_type", "VISA"); 41 expected.SetString("credit_card.address.country_name_code", "US"); 42 expected.SetString("credit_card.address.recipient_name", 43 "ship_recipient_name"); 44 expected.SetString("credit_card.address.locality_name", 45 "ship_locality_name"); 46 expected.SetString("credit_card.address.administrative_area_name", 47 "ship_admin_area_name"); 48 expected.SetString("credit_card.address.postal_code_number", 49 "ship_postal_code_number"); 50 base::ListValue* address_lines = new base::ListValue(); 51 address_lines->AppendString("ship_address_line_1"); 52 address_lines->AppendString("ship_address_line_2"); 53 expected.Set("credit_card.address.address_line", address_lines); 54 55 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), 56 ASCIIToUTF16(kCardVerificationNumber), 57 12, 58 2015, 59 Instrument::VISA, 60 GetTestShippingAddress().Pass()); 61 62 EXPECT_TRUE(expected.Equals(instrument.ToDictionary().get())); 63 } 64 65 } // namespace wallet 66 } // namespace autofill 67