diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-09 22:56:56 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-09 22:56:56 +0000 |
commit | e4b2fa31a1f25cfc80a422bcf1c76317c9e00cf2 (patch) | |
tree | f2b18dd29be63dddf88dfd728b8ebcf0ab87834b /components/autofill/browser/credit_card_field_unittest.cc | |
parent | 3a8a6d92816b0e5b4cd67a74516fbda36fdc692d (diff) | |
download | chromium_src-e4b2fa31a1f25cfc80a422bcf1c76317c9e00cf2.zip chromium_src-e4b2fa31a1f25cfc80a422bcf1c76317c9e00cf2.tar.gz chromium_src-e4b2fa31a1f25cfc80a422bcf1c76317c9e00cf2.tar.bz2 |
Move remaining Autofill code to //components/autofill.
This leaves behind all browser tests, the AutofillCCInfobarDelegate
and PersonalDataManagerFactory, which remain Chrome-specific.
All source files were moved using //tools/git/move_source_file.py,
which updates includes of moved files, sorts include order, and
updates header guards.
The only manual bits of this change were:
- Move .proto file
- Move .cc.utf8 file
- Update .gypi files
- Update DEPS files
- Remove an unnecessary include from autofill_manager.cc
TBR=ben@chromium.org
BUG=140037
Review URL: https://chromiumcodereview.appspot.com/12434004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187173 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/autofill/browser/credit_card_field_unittest.cc')
-rw-r--r-- | components/autofill/browser/credit_card_field_unittest.cc | 318 |
1 files changed, 318 insertions, 0 deletions
diff --git a/components/autofill/browser/credit_card_field_unittest.cc b/components/autofill/browser/credit_card_field_unittest.cc new file mode 100644 index 0000000..b077b70 --- /dev/null +++ b/components/autofill/browser/credit_card_field_unittest.cc @@ -0,0 +1,318 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" +#include "base/utf_string_conversions.h" +#include "components/autofill/browser/autofill_field.h" +#include "components/autofill/browser/autofill_scanner.h" +#include "components/autofill/browser/credit_card_field.h" +#include "components/autofill/common/form_field_data.h" +#include "testing/gtest/include/gtest/gtest.h" + +class CreditCardFieldTest : public testing::Test { + public: + CreditCardFieldTest() {} + + protected: + ScopedVector<const AutofillField> list_; + scoped_ptr<CreditCardField> field_; + FieldTypeMap field_type_map_; + + // Downcast for tests. + static CreditCardField* Parse(AutofillScanner* scanner) { + return static_cast<CreditCardField*>(CreditCardField::Parse(scanner)); + } + + private: + DISALLOW_COPY_AND_ASSIGN(CreditCardFieldTest); +}; + +TEST_F(CreditCardFieldTest, Empty) { + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get()); +} + +TEST_F(CreditCardFieldTest, NonParse) { + list_.push_back(new AutofillField); + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get()); +} + +TEST_F(CreditCardFieldTest, ParseCreditCardNoNumber) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Exp Month"); + field.name = ASCIIToUTF16("ccmonth"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("month1"))); + + field.label = ASCIIToUTF16("Exp Year"); + field.name = ASCIIToUTF16("ccyear"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("year2"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get()); +} + +TEST_F(CreditCardFieldTest, ParseCreditCardNoDate) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number1"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get()); +} + +TEST_F(CreditCardFieldTest, ParseMiniumCreditCard) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number1"))); + + field.label = ASCIIToUTF16("Exp Month"); + field.name = ASCIIToUTF16("ccmonth"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("month2"))); + + field.label = ASCIIToUTF16("Exp Year"); + field.name = ASCIIToUTF16("ccyear"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("year3"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("number1")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("month2")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month2")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("year3")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, + field_type_map_[ASCIIToUTF16("year3")]); +} + +TEST_F(CreditCardFieldTest, ParseFullCreditCard) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Card Type"); + field.name = ASCIIToUTF16("card_type"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("type"))); + + field.label = ASCIIToUTF16("Name on Card"); + field.name = ASCIIToUTF16("name_on_card"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("name"))); + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number"))); + + field.label = ASCIIToUTF16("Exp Month"); + field.name = ASCIIToUTF16("ccmonth"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("month"))); + + field.label = ASCIIToUTF16("Exp Year"); + field.name = ASCIIToUTF16("ccyear"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("year"))); + + field.label = ASCIIToUTF16("Verification"); + field.name = ASCIIToUTF16("verification"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("cvc"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("type")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_TYPE, field_type_map_[ASCIIToUTF16("type")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("name")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("number")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("month")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("year")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, + field_type_map_[ASCIIToUTF16("year")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("cvc")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, + field_type_map_[ASCIIToUTF16("cvc")]); +} + +TEST_F(CreditCardFieldTest, ParseExpMonthYear) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Name on Card"); + field.name = ASCIIToUTF16("name_on_card"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("name1"))); + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number2"))); + + field.label = ASCIIToUTF16("ExpDate Month / Year"); + field.name = ASCIIToUTF16("ExpDate"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("month3"))); + + field.label = ASCIIToUTF16("ExpDate Month / Year"); + field.name = ASCIIToUTF16("ExpDate"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("year4"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("month3")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month3")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("year4")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, + field_type_map_[ASCIIToUTF16("year4")]); +} + +TEST_F(CreditCardFieldTest, ParseExpMonthYear2) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Name on Card"); + field.name = ASCIIToUTF16("name_on_card"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("name1"))); + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number2"))); + + field.label = ASCIIToUTF16("Expiration date Month / Year"); + field.name = ASCIIToUTF16("ExpDate"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("month3"))); + + field.label = ASCIIToUTF16("Expiration date Month / Year"); + field.name = ASCIIToUTF16("ExpDate"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("year4"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("month3")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month3")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("year4")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, + field_type_map_[ASCIIToUTF16("year4")]); +} + +TEST_F(CreditCardFieldTest, ParseExpField) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Name on Card"); + field.name = ASCIIToUTF16("name_on_card"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("name1"))); + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number2"))); + + field.label = ASCIIToUTF16("Expiration Date (MM/YYYY)"); + field.name = ASCIIToUTF16("cc_exp"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("exp3"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("exp3")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, + field_type_map_[ASCIIToUTF16("exp3")]); +} + +TEST_F(CreditCardFieldTest, ParseExpField2DigitYear) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Name on Card"); + field.name = ASCIIToUTF16("name_on_card"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("name1"))); + + field.label = ASCIIToUTF16("Card Number"); + field.name = ASCIIToUTF16("card_number"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("number2"))); + + field.label = ASCIIToUTF16("Expiration Date (MM/YY)"); + field.name = ASCIIToUTF16("cc_exp"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("exp3"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("exp3")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, + field_type_map_[ASCIIToUTF16("exp3")]); +} + +TEST_F(CreditCardFieldTest, ParseCreditCardHolderNameWithCCFullName) { + FormFieldData field; + field.form_control_type = "text"; + + field.label = ASCIIToUTF16("Name"); + field.name = ASCIIToUTF16("ccfullname"); + list_.push_back(new AutofillField(field, ASCIIToUTF16("name1"))); + + AutofillScanner scanner(list_.get()); + field_.reset(Parse(&scanner)); + ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get()); + ASSERT_TRUE(field_->ClassifyField(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end()); + EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]); +} |