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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 17970003: New encryption/escrow endpoints for Wallet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dane's review 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 side-by-side diff with in-line comments
Download patch
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..f11d3970c97a392d9f2741ed029913612e89dee2 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 {
+ SaveToWalletTester(instrument.get(), address.get(), source_url);
Dan Beam 2013/07/02 01:25:52 nit: SaveToWalletMock, IMO
ahutter 2013/07/02 15:44:23 Done.
}
- const wallet::Address* updated_billing_address() {
- return updated_billing_address_.get();
- }
+ MOCK_METHOD3(SaveToWalletTester, 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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(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(),
+ SaveToWalletTester(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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(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);
+ SaveToWalletTester(_, _, _)).Times(0);
scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument =
@@ -1248,11 +1247,12 @@ TEST_F(AutofillDialogControllerTest, BillingForShippingHasMatch) {
AcceptAndLoadFakeFingerprint();
}
+// HUH??
Dan Beam 2013/07/02 01:25:52 // WHA??
Raman Kakilate 2013/07/02 01:41:24 ??
// Tests that adding new instrument and also using billing address for shipping,
// then a shipping address should not be added.
Dan Beam 2013/07/02 01:25:52 "Tests that adding new instrument and while using
ahutter 2013/07/02 15:44:23 But then the test should have been failing...
TEST_F(AutofillDialogControllerTest, BillingForShippingNewInstrument) {
EXPECT_CALL(*controller()->GetTestingWalletClient(),
- SaveInstrumentAndAddress(_, _, _, _)).Times(1);
+ SaveToWalletTester(_, _, _)).Times(1);
scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
wallet_items->AddAddress(wallet::GetTestShippingAddress());
@@ -1285,16 +1285,15 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) {
controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs);
EXPECT_CALL(*controller()->GetTestingWalletClient(),
- SaveAddress(UsesLocalBillingAddress(), _)).Times(1);
+ SaveToWalletTester(testing::NotNull(),
+ UsesLocalBillingAddress(),
+ _)).Times(1);
AcceptAndLoadFakeFingerprint();
-
- EXPECT_TRUE(
- controller()->GetTestingWalletClient()->updated_billing_address());
}
TEST_F(AutofillDialogControllerTest, CancelNoSave) {
EXPECT_CALL(*controller()->GetTestingWalletClient(),
- SaveInstrumentAndAddress(_, _, _, _)).Times(0);
+ SaveToWalletTester(_, _, _)).Times(0);
EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
@@ -1497,7 +1496,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 +1612,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 +1634,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());

Powered by Google App Engine
This is Rietveld 408576698