| Index: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| index a80557634dcd821d8f14a0eed449018f1ea8ffb4..a022effe258f6bf235ab5ef5a1375f9360ef19c9 100644
|
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| @@ -169,46 +169,28 @@ class TestWalletClient : public wallet::WalletClient {
|
| const std::string& google_transaction_id,
|
| const GURL& source_url));
|
|
|
| - MOCK_METHOD3(AuthenticateInstrument,
|
| + MOCK_METHOD2(AuthenticateInstrument,
|
| void(const std::string& instrument_id,
|
| - const std::string& card_verification_number,
|
| - const std::string& obfuscated_gaia_id));
|
| + const std::string& card_verification_number));
|
|
|
| MOCK_METHOD1(GetFullWallet,
|
| void(const wallet::WalletClient::FullWalletRequest& request));
|
|
|
| MOCK_METHOD1(GetWalletItems, void(const GURL& source_url));
|
|
|
| - MOCK_METHOD2(SaveAddress,
|
| - void(const wallet::Address& address, const GURL& source_url));
|
| -
|
| - MOCK_METHOD3(SaveInstrument,
|
| - void(const wallet::Instrument& instrument,
|
| - const std::string& obfuscated_gaia_id,
|
| - const GURL& source_url));
|
| -
|
| - MOCK_METHOD4(SaveInstrumentAndAddress,
|
| - void(const wallet::Instrument& instrument,
|
| - const wallet::Address& address,
|
| - const std::string& obfuscated_gaia_id,
|
| - const GURL& source_url));
|
| -
|
| - MOCK_METHOD2(UpdateAddress,
|
| - void(const wallet::Address& address, const GURL& source_url));
|
| -
|
| - virtual void UpdateInstrument(
|
| - const wallet::WalletClient::UpdateInstrumentRequest& update_request,
|
| - scoped_ptr<wallet::Address> billing_address) {
|
| - updated_billing_address_ = billing_address.Pass();
|
| + // Methods with scoped_ptrs can't be mocked but by using the implementation
|
| + // below the same effect can be achieved.
|
| + virtual void SaveToWallet(scoped_ptr<wallet::Instrument> instrument,
|
| + scoped_ptr<wallet::Address> address,
|
| + const GURL& source_url) OVERRIDE {
|
| + SaveToWalletMock(instrument.get(), address.get(), source_url);
|
| }
|
|
|
| - const wallet::Address* updated_billing_address() {
|
| - return updated_billing_address_.get();
|
| - }
|
| + MOCK_METHOD3(SaveToWalletMock, void(wallet::Instrument* instrument,
|
| + wallet::Address* address,
|
| + const GURL& source_url));
|
|
|
| private:
|
| - scoped_ptr<wallet::Address> updated_billing_address_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(TestWalletClient);
|
| };
|
|
|
| @@ -1107,7 +1089,9 @@ TEST_F(AutofillDialogControllerTest, SelectInstrument) {
|
| TEST_F(AutofillDialogControllerTest, SaveAddress) {
|
| EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveAddress(_, _)).Times(1);
|
| + SaveToWalletMock(testing::IsNull(),
|
| + testing::NotNull(),
|
| + _)).Times(1);
|
|
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
|
| @@ -1124,7 +1108,9 @@ TEST_F(AutofillDialogControllerTest, SaveAddress) {
|
| TEST_F(AutofillDialogControllerTest, SaveInstrument) {
|
| EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveInstrument(_, _, _)).Times(1);
|
| + SaveToWalletMock(testing::NotNull(),
|
| + testing::IsNull(),
|
| + _)).Times(1);
|
|
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| @@ -1134,7 +1120,9 @@ TEST_F(AutofillDialogControllerTest, SaveInstrument) {
|
| TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) {
|
| EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveInstrument(_, _, _)).Times(1);
|
| + SaveToWalletMock(testing::NotNull(),
|
| + testing::IsNull(),
|
| + _)).Times(1);
|
|
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| @@ -1144,17 +1132,25 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentWithInvalidInstruments) {
|
|
|
| TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveInstrumentAndAddress(_, _, _, _)).Times(1);
|
| + SaveToWalletMock(testing::NotNull(),
|
| + testing::NotNull(),
|
| + _)).Times(1);
|
|
|
| controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
|
| AcceptAndLoadFakeFingerprint();
|
| }
|
|
|
| +MATCHER(IsUpdatingExistingData, "updating existing Wallet data") {
|
| + return !arg->object_id().empty();
|
| +}
|
| +
|
| // Tests that editing an address (in wallet mode0 and submitting the dialog
|
| // should update the existing address on the server via WalletClient.
|
| TEST_F(AutofillDialogControllerTest, UpdateAddress) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - UpdateAddress(_, _)).Times(1);
|
| + SaveToWalletMock(testing::IsNull(),
|
| + IsUpdatingExistingData(),
|
| + _)).Times(1);
|
|
|
| controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
|
|
|
| @@ -1165,20 +1161,24 @@ TEST_F(AutofillDialogControllerTest, UpdateAddress) {
|
| // Tests that editing an instrument (CC + address) in wallet mode updates an
|
| // existing instrument on the server via WalletClient.
|
| TEST_F(AutofillDialogControllerTest, UpdateInstrument) {
|
| + EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| + SaveToWalletMock(IsUpdatingExistingData(),
|
| + testing::IsNull(),
|
| + _)).Times(1);
|
| +
|
| controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
|
|
|
| controller()->EditClickedForSection(SECTION_CC_BILLING);
|
| AcceptAndLoadFakeFingerprint();
|
| -
|
| - EXPECT_TRUE(
|
| - controller()->GetTestingWalletClient()->updated_billing_address());
|
| }
|
|
|
| // Test that a user is able to edit their instrument and add a new address in
|
| // the same submission.
|
| TEST_F(AutofillDialogControllerTest, UpdateInstrumentSaveAddress) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveAddress(_, _)).Times(1);
|
| + SaveToWalletMock(IsUpdatingExistingData(),
|
| + testing::NotNull(),
|
| + _)).Times(1);
|
|
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
|
| @@ -1186,17 +1186,14 @@ TEST_F(AutofillDialogControllerTest, UpdateInstrumentSaveAddress) {
|
|
|
| controller()->EditClickedForSection(SECTION_CC_BILLING);
|
| AcceptAndLoadFakeFingerprint();
|
| -
|
| - EXPECT_TRUE(
|
| - controller()->GetTestingWalletClient()->updated_billing_address());
|
| }
|
|
|
| // Test that saving a new instrument and editing an address works.
|
| TEST_F(AutofillDialogControllerTest, SaveInstrumentUpdateAddress) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveInstrument(_, _, _)).Times(1);
|
| - EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - UpdateAddress(_, _)).Times(1);
|
| + SaveToWalletMock(testing::NotNull(),
|
| + IsUpdatingExistingData(),
|
| + _)).Times(1);
|
|
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| @@ -1208,14 +1205,16 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentUpdateAddress) {
|
| }
|
|
|
| MATCHER(UsesLocalBillingAddress, "uses the local billing address") {
|
| - return arg.address_line_1() == ASCIIToUTF16(kEditedBillingAddress);
|
| + return arg->address_line_1() == ASCIIToUTF16(kEditedBillingAddress);
|
| }
|
|
|
| // Tests that when using billing address for shipping, and there is no exact
|
| // matched shipping address, then a shipping address should be added.
|
| TEST_F(AutofillDialogControllerTest, BillingForShipping) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveAddress(_, _)).Times(1);
|
| + SaveToWalletMock(testing::IsNull(),
|
| + testing::NotNull(),
|
| + _)).Times(1);
|
|
|
| controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
|
| // Select "Same as billing" in the address menu.
|
| @@ -1228,7 +1227,7 @@ TEST_F(AutofillDialogControllerTest, BillingForShipping) {
|
| // matched shipping address, then a shipping address should not be added.
|
| TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveAddress(_, _)).Times(0);
|
| + SaveToWalletMock(_, _, _)).Times(0);
|
|
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument =
|
| @@ -1248,22 +1247,6 @@ TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) {
|
| AcceptAndLoadFakeFingerprint();
|
| }
|
|
|
| -// Tests that adding new instrument and also using billing address for shipping,
|
| -// then a shipping address should not be added.
|
| -TEST_F(AutofillDialogControllerTest, BillingForShippingNewInstrument) {
|
| - EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveInstrumentAndAddress(_, _, _, _)).Times(1);
|
| -
|
| - scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| - wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| -
|
| - controller()->OnDidGetWalletItems(wallet_items.Pass());
|
| - // Select "Same as billing" in the address menu.
|
| - UseBillingForShipping();
|
| -
|
| - AcceptAndLoadFakeFingerprint();
|
| -}
|
| -
|
| // 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) {
|
| @@ -1285,16 +1268,15 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) {
|
| controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs);
|
|
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveAddress(UsesLocalBillingAddress(), _)).Times(1);
|
| + SaveToWalletMock(testing::NotNull(),
|
| + UsesLocalBillingAddress(),
|
| + _)).Times(1);
|
| AcceptAndLoadFakeFingerprint();
|
| -
|
| - EXPECT_TRUE(
|
| - controller()->GetTestingWalletClient()->updated_billing_address());
|
| }
|
|
|
| TEST_F(AutofillDialogControllerTest, CancelNoSave) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - SaveInstrumentAndAddress(_, _, _, _)).Times(0);
|
| + SaveToWalletMock(_, _, _)).Times(0);
|
|
|
| EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
|
|
|
| @@ -1497,7 +1479,7 @@ TEST_F(AutofillDialogControllerTest, VerifyCvv) {
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| GetFullWallet(_)).Times(1);
|
| EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| - AuthenticateInstrument(_, _, _)).Times(1);
|
| + AuthenticateInstrument(_, _)).Times(1);
|
|
|
| SubmitWithWalletItems(CompleteAndValidWalletItems());
|
|
|
| @@ -1613,7 +1595,10 @@ TEST_F(AutofillDialogControllerTest, WalletServerSideValidation) {
|
| wallet::FormFieldError::SHIPPING_ADDRESS));
|
|
|
| EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1);
|
| - controller()->OnDidSaveAddress(std::string(), required_actions, form_errors);
|
| + controller()->OnDidSaveToWallet(std::string(),
|
| + std::string(),
|
| + required_actions,
|
| + form_errors);
|
| }
|
|
|
| // Simulates receiving unrecoverable Wallet server validation errors.
|
| @@ -1632,7 +1617,10 @@ TEST_F(AutofillDialogControllerTest, WalletServerSideValidationUnrecoverable) {
|
| wallet::FormFieldError::UNKNOWN_LOCATION));
|
|
|
| EXPECT_CALL(*controller()->GetView(), UpdateForErrors()).Times(1);
|
| - controller()->OnDidSaveAddress(std::string(), required_actions, form_errors);
|
| + controller()->OnDidSaveToWallet(std::string(),
|
| + std::string(),
|
| + required_actions,
|
| + form_errors);
|
|
|
| EXPECT_EQ(1U, NotificationsOfType(
|
| DialogNotification::REQUIRED_ACTION).size());
|
|
|