Home | History | Annotate | Download | only in wallet
      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 using base::ASCIIToUTF16;
     13 
     14 namespace {
     15 
     16 const char kPrimaryAccountNumber[] = "4444444444444448";
     17 const char kCardVerificationNumber[] = "123";
     18 const char kLastFourDigits[] = "4448";
     19 
     20 }
     21 
     22 namespace autofill {
     23 namespace wallet {
     24 
     25 TEST(Instrument, LastFourDigits) {
     26   Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
     27                         ASCIIToUTF16(kCardVerificationNumber),
     28                         12,
     29                         2015,
     30                         Instrument::VISA,
     31                         GetTestShippingAddress().Pass());
     32 
     33   EXPECT_EQ(ASCIIToUTF16(kLastFourDigits), instrument.last_four_digits());
     34 }
     35 
     36 TEST(Instrument, ToDictionary) {
     37   base::DictionaryValue expected;
     38   expected.SetString("type", "CREDIT_CARD");
     39   expected.SetInteger("credit_card.exp_month", 12);
     40   expected.SetInteger("credit_card.exp_year", 2015);
     41   expected.SetString("credit_card.last_4_digits", kLastFourDigits);
     42   expected.SetString("credit_card.fop_type", "VISA");
     43   expected.SetString("credit_card.address.country_name_code", "US");
     44   expected.SetString("credit_card.address.recipient_name",
     45                      "ship_recipient_name");
     46   expected.SetString("credit_card.address.locality_name",
     47                      "ship_locality_name");
     48   expected.SetString("credit_card.address.dependent_locality_name",
     49                      "ship_dependent_locality_name");
     50   expected.SetString("credit_card.address.administrative_area_name",
     51                      "ship_admin_area_name");
     52   expected.SetString("credit_card.address.postal_code_number",
     53                      "ship_postal_code_number");
     54   expected.SetString("credit_card.address.sorting_code",
     55                      "ship_sorting_code");
     56   base::ListValue* address_lines = new base::ListValue();
     57   address_lines->AppendString("ship_address_line_1");
     58   address_lines->AppendString("ship_address_line_2");
     59   expected.Set("credit_card.address.address_line", address_lines);
     60   expected.SetString("credit_card.address.language_code", "ship_language_code");
     61 
     62   Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
     63                         ASCIIToUTF16(kCardVerificationNumber),
     64                         12,
     65                         2015,
     66                         Instrument::VISA,
     67                         GetTestShippingAddress().Pass());
     68 
     69   EXPECT_TRUE(expected.Equals(instrument.ToDictionary().get()));
     70 }
     71 
     72 }  // namespace wallet
     73 }  // namespace autofill
     74