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

Side by Side Diff: chrome/browser/ui/autofill/data_model_wrapper_unittest.cc

Issue 17099006: Validate saved credit card number in interactive autocomplete (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge master Created 7 years, 6 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
8 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 9 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
9 #include "components/autofill/content/browser/wallet/wallet_items.h" 10 #include "components/autofill/content/browser/wallet/wallet_items.h"
10 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 11 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
11 #include "components/autofill/core/browser/autofill_common_test.h" 12 #include "components/autofill/core/browser/autofill_common_test.h"
12 #include "components/autofill/core/browser/autofill_profile.h" 13 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/credit_card.h" 14 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/field_types.h" 15 #include "components/autofill/core/browser/field_types.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace autofill { 18 namespace autofill {
18 19
19 TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) { 20 TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) {
20 CreditCard card; 21 CreditCard card;
21 MonthComboboxModel model; 22 MonthComboboxModel model;
22 for (int month = 1; month <= 12; ++month) { 23 for (int month = 1; month <= 12; ++month) {
23 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, base::IntToString16(month)); 24 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, base::IntToString16(month));
24 AutofillCreditCardWrapper wrapper(&card); 25 AutofillCreditCardWrapper wrapper(&card);
25 EXPECT_EQ(model.GetItemAt(month), wrapper.GetInfo(CREDIT_CARD_EXP_MONTH)); 26 EXPECT_EQ(model.GetItemAt(month), wrapper.GetInfo(CREDIT_CARD_EXP_MONTH));
26 } 27 }
27 } 28 }
28 29
29 TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) { 30 TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) {
30 CreditCard card; 31 CreditCard card;
32 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
33 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2010"));
34 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111"));
31 AutofillCreditCardWrapper wrapper(&card); 35 AutofillCreditCardWrapper wrapper(&card);
32 EXPECT_TRUE(wrapper.GetDisplayText().empty()); 36 EXPECT_TRUE(wrapper.GetDisplayText().empty());
33 } 37 }
34 38
39 TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenInvalid) {
40 CreditCard card;
41 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12"));
42 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("9999"));
43 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("41111"));
44 AutofillCreditCardWrapper wrapper(&card);
45 EXPECT_TRUE(wrapper.GetDisplayText().empty());
46 }
47
48 TEST(AutofillCreditCardWrapperTest, GetDisplayTextNotEmptyWhenValid) {
49 CreditCard card;
50 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12"));
51 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("9999"));
52 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111"));
53 AutofillCreditCardWrapper wrapper(&card);
54 EXPECT_FALSE(wrapper.GetDisplayText().empty());
55 }
56
35 TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) { 57 TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) {
36 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( 58 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument(
37 wallet::GetTestMaskedInstrument()); 59 wallet::GetTestMaskedInstrument());
38 MonthComboboxModel model; 60 MonthComboboxModel model;
39 for (int month = 1; month <= 12; ++month) { 61 for (int month = 1; month <= 12; ++month) {
40 instrument->expiration_month_ = month; 62 instrument->expiration_month_ = month;
41 WalletInstrumentWrapper wrapper(instrument.get()); 63 WalletInstrumentWrapper wrapper(instrument.get());
42 EXPECT_EQ(model.GetItemAt(month), wrapper.GetInfo(CREDIT_CARD_EXP_MONTH)); 64 EXPECT_EQ(model.GetItemAt(month), wrapper.GetInfo(CREDIT_CARD_EXP_MONTH));
43 } 65 }
44 } 66 }
(...skipping 19 matching lines...) Expand all
64 const_cast<wallet::Address*>(&instrument->address())->set_phone_number( 86 const_cast<wallet::Address*>(&instrument->address())->set_phone_number(
65 string16()); 87 string16());
66 88
67 ASSERT_TRUE(instrument_wrapper.GetInfo(PHONE_HOME_WHOLE_NUMBER).empty()); 89 ASSERT_TRUE(instrument_wrapper.GetInfo(PHONE_HOME_WHOLE_NUMBER).empty());
68 EXPECT_TRUE(instrument_wrapper.GetDisplayText().empty()); 90 EXPECT_TRUE(instrument_wrapper.GetDisplayText().empty());
69 91
70 ASSERT_TRUE(address_wrapper.GetInfo(PHONE_HOME_WHOLE_NUMBER).empty()); 92 ASSERT_TRUE(address_wrapper.GetInfo(PHONE_HOME_WHOLE_NUMBER).empty());
71 EXPECT_TRUE(address_wrapper.GetDisplayText().empty()); 93 EXPECT_TRUE(address_wrapper.GetDisplayText().empty());
72 } 94 }
73 95
74 } // autofill 96 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/data_model_wrapper.cc ('k') | components/autofill/core/browser/credit_card.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698