diff options
author | paisa@chromium.org <paisa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-21 16:43:02 +0000 |
---|---|---|
committer | paisa@chromium.org <paisa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-21 16:43:02 +0000 |
commit | 692eec4f8f41cf55531e6c5ba552f56b88f672db (patch) | |
tree | 82b68462e63525dfc65bdec8b6bd7b905dd19af0 | |
parent | fcc06522316c5a3d6c42c809f96af61845286052 (diff) | |
download | chromium_src-692eec4f8f41cf55531e6c5ba552f56b88f672db.zip chromium_src-692eec4f8f41cf55531e6c5ba552f56b88f672db.tar.gz chromium_src-692eec4f8f41cf55531e6c5ba552f56b88f672db.tar.bz2 |
Handle amex_disallowed field in Wallet response.
BUG=286438
Review URL: https://chromiumcodereview.appspot.com/24163003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224598 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 164 insertions, 62 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index 2cda6e0..f870455 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -567,7 +567,8 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, WalletCreditCardDisabled) { controller()->OnUserNameFetchSuccess("user@example.com"); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); // An expired card will be forced into edit mode. wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentWithDetails( "instrument_id", @@ -732,7 +733,8 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_PreservedSections) { // Set up some Wallet state. controller()->OnUserNameFetchSuccess("user@example.com"); - controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); ui::MenuModel* account_chooser = controller()->MenuModelForAccountChooser(); ASSERT_TRUE(account_chooser->IsItemCheckedAt(0)); diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index f6c08287..6872a86 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -141,10 +141,13 @@ class ScopedViewUpdates { }; // Returns true if |card_type| is supported by Wallet. -bool IsWalletSupportedCard(const std::string& card_type) { +bool IsWalletSupportedCard(const std::string& card_type, + const wallet::WalletItems& wallet_items) { return card_type == autofill::kVisaCard || card_type == autofill::kMasterCard || - card_type == autofill::kDiscoverCard; + card_type == autofill::kDiscoverCard || + (card_type == autofill::kAmericanExpressCard && + wallet_items.is_amex_allowed()); } // Returns true if |input| should be used to fill a site-requested |field| which @@ -2875,7 +2878,8 @@ base::string16 AutofillDialogControllerImpl::CreditCardNumberValidityMessage( // Wallet only accepts MasterCard, Visa and Discover. No AMEX. if (IsPayingWithWallet() && - !IsWalletSupportedCard(CreditCard::GetCreditCardType(number))) { + !IsWalletSupportedCard(CreditCard::GetCreditCardType(number), + *wallet_items_)) { return l10n_util::GetStringUTF16( IDS_AUTOFILL_DIALOG_VALIDATION_CREDIT_CARD_NOT_SUPPORTED_BY_WALLET); } diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index d229e5d..73d8cf9 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -106,7 +106,8 @@ void CopyInitialValues(const DetailInputs& inputs, DetailOutputMap* outputs) { } scoped_ptr<wallet::WalletItems> CompleteAndValidWalletItems() { - scoped_ptr<wallet::WalletItems> items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); items->AddInstrument(wallet::GetTestMaskedInstrument()); items->AddAddress(wallet::GetTestShippingAddress()); return items.Pass(); @@ -803,7 +804,8 @@ TEST_F(AutofillDialogControllerTest, BillingNameValidation) { SwitchToWallet(); // Setup some wallet state. - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); controller()->OnDidGetWalletItems(wallet_items.Pass()); DetailOutputMap wallet_outputs; @@ -871,24 +873,36 @@ TEST_F(AutofillDialogControllerTest, CreditCardNumberValidation) { ValidateCCNumber(SECTION_CC, kTestCCNumberMaster, true); ValidateCCNumber(SECTION_CC, kTestCCNumberDiscover, true); ValidateCCNumber(SECTION_CC, kTestCCNumberAmex, true); - ValidateCCNumber(SECTION_CC, kTestCCNumberIncomplete, false); ValidateCCNumber(SECTION_CC, kTestCCNumberInvalid, false); // Switch to Wallet which will not accept AMEX. SwitchToWallet(); - // Setup some wallet state. - controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); + // Setup some wallet state on a merchant for which Wallet doesn't + // support AMEX. + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); // Should accept Visa, Master and Discover, but not AMEX. ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberVisa, true); ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberMaster, true); ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true); - ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberAmex, false); ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberIncomplete, false); ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberInvalid, false); + + // Setup some wallet state on a merchant for which Wallet supports AMEX. + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_ALLOWED)); + + // Should accept Visa, Master, Discover, and AMEX. + ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberVisa, true); + ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberMaster, true); + ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberDiscover, true); + ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberAmex, true); + ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberIncomplete, false); + ValidateCCNumber(SECTION_CC_BILLING, kTestCCNumberInvalid, false); } TEST_F(AutofillDialogControllerTest, AutofillProfiles) { @@ -1260,7 +1274,8 @@ TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) { // Makes sure the default object IDs are respected. TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); @@ -1289,7 +1304,8 @@ TEST_F(AutofillDialogControllerTest, WalletDefaultItems) { // Tests that invalid and AMEX default instruments are ignored. TEST_F(AutofillDialogControllerTest, SelectInstrument) { - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); // Tests if default instrument is invalid, then, the first valid instrument is // selected instead of the default instrument. wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); @@ -1304,12 +1320,14 @@ TEST_F(AutofillDialogControllerTest, SelectInstrument) { EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> IsItemCheckedAt(0)); - // Tests if default instrument is AMEX, then, the first valid instrument is + // Tests if default instrument is AMEX but Wallet doesn't support + // AMEX on this merchant, then the first valid instrument is // selected instead of the default instrument. - wallet_items = wallet::GetTestWalletItems(); + wallet_items = wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); - wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex()); + wallet_items->AddInstrument( + wallet::GetTestMaskedInstrumentAmex(wallet::AMEX_DISALLOWED)); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -1319,10 +1337,27 @@ TEST_F(AutofillDialogControllerTest, SelectInstrument) { EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> IsItemCheckedAt(0)); + // Tests if default instrument is AMEX and it is allowed on this merchant, + // then it is selected. + wallet_items = wallet::GetTestWalletItems(wallet::AMEX_ALLOWED); + wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); + wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); + wallet_items->AddInstrument( + wallet::GetTestMaskedInstrumentAmex(wallet::AMEX_ALLOWED)); + wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); + + controller()->OnDidGetWalletItems(wallet_items.Pass()); + // 4 suggestions and "add", "manage". + EXPECT_EQ(6, + controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); + EXPECT_TRUE(controller()->MenuModelForSection(SECTION_CC_BILLING)-> + IsItemCheckedAt(2)); + // Tests if only have AMEX and invalid instrument, then "add" is selected. - wallet_items = wallet::GetTestWalletItems(); + wallet_items = wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); - wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentAmex()); + wallet_items->AddInstrument( + wallet::GetTestMaskedInstrumentAmex(wallet::AMEX_DISALLOWED)); controller()->OnDidGetWalletItems(wallet_items.Pass()); // 2 suggestions and "add", "manage". @@ -1340,7 +1375,8 @@ TEST_F(AutofillDialogControllerTest, SaveAddress) { testing::NotNull(), _)).Times(1); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); // If there is no shipping address in wallet, it will default to @@ -1359,7 +1395,8 @@ TEST_F(AutofillDialogControllerTest, SaveInstrument) { testing::IsNull(), _)).Times(1); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddAddress(wallet::GetTestShippingAddress()); SubmitWithWalletItems(wallet_items.Pass()); } @@ -1371,7 +1408,8 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) { testing::IsNull(), _)).Times(1); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddAddress(wallet::GetTestShippingAddress()); wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentInvalid()); SubmitWithWalletItems(wallet_items.Pass()); @@ -1383,7 +1421,8 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) { testing::NotNull(), _)).Times(1); - controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); AcceptAndLoadFakeFingerprint(); } @@ -1416,7 +1455,8 @@ TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) { EXPECT_CALL(*controller()->GetTestingWalletClient(), SaveToWalletMock(_, _, _)).Times(0); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument = wallet::GetTestMaskedInstrument(); // Copy billing address as shipping address, and assign an id to it. @@ -1437,7 +1477,8 @@ TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) { // Test that the local view contents is used when saving a new instrument and // the user has selected "Same as billing". TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) { - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -1478,7 +1519,8 @@ TEST_F(AutofillDialogControllerTest, CancelNoSave) { EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); - controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); controller()->OnCancel(); } @@ -1497,7 +1539,8 @@ TEST_F(AutofillDialogControllerTest, ManageItem) { EXPECT_EQ("chrome", autofill_manage_url.scheme()); SwitchToWallet(); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -1658,7 +1701,8 @@ TEST_F(AutofillDialogControllerTest, ChangeAccountDuringVerifyCvv) { // |WalletClientDelegate::OnDid{Save,Update}*()| call. This can happen if Online // Wallet's server validation differs from Chrome's local validation. TEST_F(AutofillDialogControllerTest, WalletServerSideValidation) { - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); controller()->OnAccept(); @@ -1680,7 +1724,8 @@ TEST_F(AutofillDialogControllerTest, WalletServerSideValidation) { // Simulates receiving unrecoverable Wallet server validation errors. TEST_F(AutofillDialogControllerTest, WalletServerSideValidationUnrecoverable) { - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); controller()->OnAccept(); @@ -1728,7 +1773,8 @@ TEST_F(AutofillDialogControllerTest, WalletBanners) { // Start over and sign in a user with an incomplete account. SetUpControllerWithFormData(DefaultFormData()); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -1835,7 +1881,8 @@ TEST_F(AutofillDialogControllerTest, ViewSubmitSetsPref) { SetUpControllerWithFormData(DefaultFormData()); SwitchToWallet(); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); controller()->OnAccept(); @@ -1936,7 +1983,8 @@ TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) { // view. Called once for each incomplete suggestion. EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentWithIdAndAddress( "id", wallet::GetTestMinimalAddress())); scoped_ptr<wallet::Address> address(wallet::GetTestShippingAddress()); @@ -1954,7 +2002,8 @@ TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) { TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) { EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); controller()->OnAccept(); @@ -1963,7 +2012,8 @@ TEST_F(AutofillDialogControllerTest, RiskNeverLoadsWithPendingLegalDocuments) { TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) { EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddLegalDocument(wallet::GetTestLegalDocument()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -1980,7 +2030,8 @@ TEST_F(AutofillDialogControllerTest, RiskLoadsAfterAcceptingLegalDocuments) { TEST_F(AutofillDialogControllerTest, NoManageMenuItemForNewWalletUsers) { // Make sure the menu model item is created for a returning Wallet user. - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); wallet_items->AddAddress(wallet::GetTestShippingAddress()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -2050,7 +2101,8 @@ TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHiddenForWallet) { EXPECT_CALL(*controller()->GetTestingWalletClient(), GetFullWallet(_)).Times(1); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); SubmitWithWalletItems(wallet_items.Pass()); controller()->OnDidGetFullWallet(wallet::GetTestFullWalletInstrumentOnly()); @@ -2060,7 +2112,8 @@ TEST_F(AutofillDialogControllerTest, ShippingSectionCanBeHiddenForWallet) { TEST_F(AutofillDialogControllerTest, NotProdNotification) { // To make IsPayingWithWallet() true. - controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); CommandLine* command_line = CommandLine::ForCurrentProcess(); ASSERT_FALSE(command_line->HasSwitch(switches::kWalletServiceUseProd)); @@ -2074,7 +2127,8 @@ TEST_F(AutofillDialogControllerTest, NotProdNotification) { // Ensure Wallet instruments marked expired by the server are shown as invalid. TEST_F(AutofillDialogControllerTest, WalletExpiredCard) { - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); controller()->OnDidGetWalletItems(wallet_items.Pass()); @@ -2159,7 +2213,8 @@ TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { // Switch into Wallet mode and initialize some Wallet data. SwitchToWallet(); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); @@ -2194,7 +2249,7 @@ TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { controller()->TabActivated(); // Simulate a response that includes different items. - wallet_items = wallet::GetTestWalletItems(); + wallet_items = wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); @@ -2217,7 +2272,8 @@ TEST_F(AutofillDialogControllerTest, // Switch into Wallet mode and initialize some Wallet data. SwitchToWallet(); - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); + scoped_ptr<wallet::WalletItems> wallet_items = + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); @@ -2244,7 +2300,8 @@ TEST_F(AutofillDialogControllerTest, // Simulate a response that includes different default values. wallet_items = wallet::GetTestWalletItemsWithDefaultIds("new_default_instrument_id", - "new_default_address_id"); + "new_default_address_id", + wallet::AMEX_DISALLOWED); scoped_ptr<wallet::Address> other_address = wallet::GetTestShippingAddress(); other_address->set_object_id("other_address_id"); scoped_ptr<wallet::Address> new_default_address = @@ -2278,7 +2335,8 @@ TEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); controller()->TabActivated(); - controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); + controller()->OnDidGetWalletItems( + wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); EXPECT_EQ( diff --git a/components/autofill/content/browser/wallet/wallet_items.cc b/components/autofill/content/browser/wallet/wallet_items.cc index cbd3d66..0ef44d2 100644 --- a/components/autofill/content/browser/wallet/wallet_items.cc +++ b/components/autofill/content/browser/wallet/wallet_items.cc @@ -392,12 +392,14 @@ WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions, const std::string& google_transaction_id, const std::string& default_instrument_id, const std::string& default_address_id, - const std::string& obfuscated_gaia_id) + const std::string& obfuscated_gaia_id, + AmexPermission amex_permission) : required_actions_(required_actions), google_transaction_id_(google_transaction_id), default_instrument_id_(default_instrument_id), default_address_id_(default_address_id), - obfuscated_gaia_id_(obfuscated_gaia_id) {} + obfuscated_gaia_id_(obfuscated_gaia_id), + amex_permission_(amex_permission) {} WalletItems::~WalletItems() {} @@ -441,11 +443,18 @@ scoped_ptr<WalletItems> if (!dictionary.GetString("obfuscated_gaia_id", &obfuscated_gaia_id)) DVLOG(1) << "Response from Google wallet missing obfuscated gaia id"; + bool amex_disallowed = true; + if (!dictionary.GetBoolean("amex_disallowed", &amex_disallowed)) + DVLOG(1) << "Response from Google wallet missing the amex_disallowed field"; + AmexPermission amex_permission = + amex_disallowed ? AMEX_DISALLOWED : AMEX_ALLOWED; + scoped_ptr<WalletItems> wallet_items(new WalletItems(required_action, google_transaction_id, default_instrument_id, default_address_id, - obfuscated_gaia_id)); + obfuscated_gaia_id, + amex_permission)); const ListValue* legal_docs; if (dictionary.GetList("required_legal_document", &legal_docs)) { diff --git a/components/autofill/content/browser/wallet/wallet_items.h b/components/autofill/content/browser/wallet/wallet_items.h index 48820d0..9838ec83d 100644 --- a/components/autofill/content/browser/wallet/wallet_items.h +++ b/components/autofill/content/browser/wallet/wallet_items.h @@ -38,6 +38,11 @@ namespace wallet { class WalletItemsTest; +enum AmexPermission { + AMEX_ALLOWED, + AMEX_DISALLOWED, +}; + // WalletItems is a collection of cards and addresses that a user picks from to // construct a full wallet. However, it also provides a transaction ID which // must be used throughout all API calls being made using this data. @@ -252,11 +257,12 @@ class WalletItems { const std::vector<LegalDocument*>& legal_documents() const { return legal_documents_.get(); } + bool is_amex_allowed() const { return amex_permission_ == AMEX_ALLOWED; } private: friend class WalletItemsTest; friend scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( - const std::string&, const std::string&); + const std::string&, const std::string&, AmexPermission); FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItemsWithRequiredActions); @@ -265,7 +271,8 @@ class WalletItems { const std::string& google_transaction_id, const std::string& default_instrument_id, const std::string& default_address_id, - const std::string& obfuscated_gaia_id); + const std::string& obfuscated_gaia_id, + AmexPermission amex_permission); // Actions that must be completed by the user before a FullWallet can be // issued to them by the Online Wallet service. @@ -292,6 +299,9 @@ class WalletItems { // Legal documents the user must accept before using Online Wallet. ScopedVector<LegalDocument> legal_documents_; + // Whether Google Wallet allows American Express card for this merchant. + AmexPermission amex_permission_; + DISALLOW_COPY_AND_ASSIGN(WalletItems); }; diff --git a/components/autofill/content/browser/wallet/wallet_items_unittest.cc b/components/autofill/content/browser/wallet/wallet_items_unittest.cc index 83f8b19..75da0fd 100644 --- a/components/autofill/content/browser/wallet/wallet_items_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_items_unittest.cc @@ -63,7 +63,8 @@ const char kMaskedInstrumentMissingStatus[] = " \"phone_number\":\"phone_number\"," " \"country_code\":\"country_code\"" " }," - " \"object_id\":\"object_id\"" + " \"object_id\":\"object_id\"," + " \"amex_disallowed\":true" "}"; const char kMaskedInstrumentMissingType[] = @@ -278,6 +279,7 @@ const char kWalletItemsMissingGoogleTransactionId[] = " ]," " \"default_address_id\":\"default_address_id\"," " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," + " \"amex_disallowed\":true," " \"required_legal_document\":" " [" " {" @@ -343,7 +345,8 @@ const char kWalletItems[] = " }" " ]," " \"default_address_id\":\"default_address_id\"," - " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\""; + " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," + " \"amex_disallowed\":true"; const char kRequiredLegalDocument[] = " ," @@ -484,7 +487,8 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), - std::string()); + std::string(), + AMEX_DISALLOWED); EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); ASSERT_FALSE(required_actions.empty()); @@ -493,7 +497,8 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), - std::string()); + std::string(), + AMEX_DISALLOWED); EXPECT_NE(expected, different_required_actions); } @@ -507,6 +512,12 @@ TEST_F(WalletItemsTest, CreateWalletItemsMissingGoogleTransactionId) { EXPECT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); } +TEST_F(WalletItemsTest, CreateWalletItemsMissingAmexDisallowed) { + SetUpDictionary(std::string(kWalletItems) + std::string(kCloseJson)); + EXPECT_TRUE(dict->Remove("amex_disallowed", NULL)); + EXPECT_FALSE(WalletItems::CreateWalletItems(*dict)->is_amex_allowed()); +} + TEST_F(WalletItemsTest, CreateWalletItems) { SetUpDictionary(std::string(kWalletItems) + std::string(kCloseJson)); std::vector<RequiredAction> required_actions; @@ -514,7 +525,8 @@ TEST_F(WalletItemsTest, CreateWalletItems) { "google_transaction_id", "default_instrument_id", "default_address_id", - "obfuscated_gaia_id"); + "obfuscated_gaia_id", + AMEX_DISALLOWED); scoped_ptr<Address> billing_address(new Address("country_code", ASCIIToUTF16("name"), diff --git a/components/autofill/content/browser/wallet/wallet_test_util.cc b/components/autofill/content/browser/wallet/wallet_test_util.cc index 2311e5c..0a15c3e 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.cc +++ b/components/autofill/content/browser/wallet/wallet_test_util.cc @@ -179,13 +179,15 @@ scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentInvalid() { WalletItems::MaskedInstrument::DECLINED); } -scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentAmex() { +scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentAmex( + AmexPermission amex_permission) { return GetTestMaskedInstrumentWithDetails( "default_instrument_id", GetTestAddress(), WalletItems::MaskedInstrument::AMEX, - // Amex cards are marked with status AMEX_NOT_SUPPORTED by the server. - WalletItems::MaskedInstrument::AMEX_NOT_SUPPORTED); + (amex_permission == AMEX_ALLOWED) + ? WalletItems::MaskedInstrument::VALID + : WalletItems::MaskedInstrument::AMEX_NOT_SUPPORTED); } scoped_ptr<WalletItems::MaskedInstrument> GetTestNonDefaultMaskedInstrument() { @@ -224,20 +226,23 @@ scoped_ptr<Address> GetTestNonDefaultShippingAddress() { return address.Pass(); } -scoped_ptr<WalletItems> GetTestWalletItems() { +scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { return GetTestWalletItemsWithDefaultIds("default_instrument_id", - "default_address_id"); + "default_address_id", + amex_permission); } scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( const std::string& default_instrument_id, - const std::string& default_address_id) { + const std::string& default_address_id, + AmexPermission amex_permission) { return scoped_ptr<WalletItems>( new wallet::WalletItems(std::vector<RequiredAction>(), "google_transaction_id", default_instrument_id, default_address_id, - "obfuscated_gaia_id")); + "obfuscated_gaia_id", + amex_permission)); } } // namespace wallet diff --git a/components/autofill/content/browser/wallet/wallet_test_util.h b/components/autofill/content/browser/wallet/wallet_test_util.h index 781ea19..b9bfbdd 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.h +++ b/components/autofill/content/browser/wallet/wallet_test_util.h @@ -27,7 +27,8 @@ scoped_ptr<WalletItems::LegalDocument> GetTestLegalDocument(); scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrument(); scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentExpired(); scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentInvalid(); -scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentAmex(); +scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentAmex( + AmexPermission amex_permission); scoped_ptr<WalletItems::MaskedInstrument> GetTestNonDefaultMaskedInstrument(); scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentWithId( const std::string& id); @@ -42,10 +43,11 @@ scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentWithDetails( scoped_ptr<Address> GetTestSaveableAddress(); scoped_ptr<Address> GetTestShippingAddress(); scoped_ptr<Address> GetTestNonDefaultShippingAddress(); -scoped_ptr<WalletItems> GetTestWalletItems(); +scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission); scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( const std::string& default_instrument_id, - const std::string& default_address_id); + const std::string& default_address_id, + AmexPermission amex_permission); } // namespace wallet } // namespace autofill |