| 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 754fd7840515e3b64bedb0f72fe8ef8bd77e9fac..221ee4fcb9c65895fa34e8cc764ec54ea994d3e0 100644
|
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
|
| @@ -12,6 +12,7 @@
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "components/autofill/browser/autofill_common_test.h"
|
| #include "components/autofill/browser/autofill_metrics.h"
|
| +#include "components/autofill/browser/wallet/full_wallet.h"
|
| #include "components/autofill/browser/wallet/instrument.h"
|
| #include "components/autofill/browser/wallet/wallet_address.h"
|
| #include "components/autofill/browser/wallet/wallet_client.h"
|
| @@ -93,6 +94,11 @@ class TestWalletClient : public wallet::WalletClient {
|
| const std::string& google_transaction_id,
|
| const GURL& source_url));
|
|
|
| + MOCK_METHOD3(AuthenticateInstrument,
|
| + void(const std::string& instrument_id,
|
| + const std::string& card_verification_number,
|
| + const std::string& obfuscated_gaia_id));
|
| +
|
| MOCK_METHOD1(GetFullWallet,
|
| void(const wallet::WalletClient::FullWalletRequest& request));
|
|
|
| @@ -224,6 +230,17 @@ class AutofillDialogControllerTest : public testing::Test {
|
| }
|
|
|
| protected:
|
| + size_t CountNotificationsOfType(DialogNotification::Type type) {
|
| + size_t count = 0;
|
| + const std::vector<DialogNotification>& notifications =
|
| + controller()->CurrentNotifications();
|
| + for (size_t i = 0; i < notifications.size(); ++i) {
|
| + if (notifications[i].type() == type)
|
| + ++count;
|
| + }
|
| + return count;
|
| + }
|
| +
|
| TestAutofillDialogController* controller() { return controller_; }
|
|
|
| TestingProfile* profile() { return &profile_; }
|
| @@ -323,9 +340,11 @@ TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
|
| EXPECT_EQ(3, email_model->GetItemCount());
|
|
|
| email_model->ActivatedAt(0);
|
| - EXPECT_EQ(kEmail1, controller()->SuggestionTextForSection(SECTION_EMAIL));
|
| + EXPECT_EQ(kEmail1,
|
| + controller()->SuggestionStateForSection(SECTION_EMAIL).text);
|
| email_model->ActivatedAt(1);
|
| - EXPECT_EQ(kEmail2, controller()->SuggestionTextForSection(SECTION_EMAIL));
|
| + EXPECT_EQ(kEmail2,
|
| + controller()->SuggestionStateForSection(SECTION_EMAIL).text);
|
|
|
| controller()->EditClickedForSection(SECTION_EMAIL);
|
| const DetailInputs& inputs =
|
| @@ -347,7 +366,7 @@ TEST_F(AutofillDialogControllerTest, AcceptLegalDocuments) {
|
| wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
|
| wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| controller()->OnDidGetWalletItems(wallet_items.Pass());
|
| - controller()->OnSubmit();
|
| + controller()->OnAccept();
|
| }
|
|
|
| TEST_F(AutofillDialogControllerTest, SaveAddress) {
|
| @@ -360,7 +379,7 @@ TEST_F(AutofillDialogControllerTest, SaveAddress) {
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
|
| controller()->OnDidGetWalletItems(wallet_items.Pass());
|
| - controller()->OnSubmit();
|
| + controller()->OnAccept();
|
| }
|
|
|
| TEST_F(AutofillDialogControllerTest, SaveInstrument) {
|
| @@ -373,7 +392,7 @@ TEST_F(AutofillDialogControllerTest, SaveInstrument) {
|
| scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| controller()->OnDidGetWalletItems(wallet_items.Pass());
|
| - controller()->OnSubmit();
|
| + controller()->OnAccept();
|
| }
|
|
|
| TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
|
| @@ -384,11 +403,13 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentAndAddress) {
|
| SaveInstrumentAndAddress(_, _, _, _)).Times(1);
|
|
|
| controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
|
| - controller()->OnSubmit();
|
| + controller()->OnAccept();
|
| }
|
|
|
| -TEST_F(AutofillDialogControllerTest, Cancel) {
|
| +TEST_F(AutofillDialogControllerTest, CancelNoSave) {
|
| controller()->set_is_paying_with_wallet(true);
|
| + EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| + SaveInstrumentAndAddress(_, _, _, _)).Times(0);
|
|
|
| EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
|
|
|
| @@ -413,21 +434,73 @@ TEST_F(AutofillDialogControllerTest, EditClickedCancelled) {
|
| const DetailInputs& inputs0 =
|
| controller()->RequestedFieldsForSection(SECTION_EMAIL);
|
| EXPECT_EQ(string16(), inputs0[0].autofilled_value);
|
| - EXPECT_EQ(kEmail, controller()->SuggestionTextForSection(SECTION_EMAIL));
|
| + EXPECT_EQ(kEmail,
|
| + controller()->SuggestionStateForSection(SECTION_EMAIL).text);
|
|
|
| // When edited, the autofilled_value should contain the value.
|
| controller()->EditClickedForSection(SECTION_EMAIL);
|
| const DetailInputs& inputs1 =
|
| controller()->RequestedFieldsForSection(SECTION_EMAIL);
|
| EXPECT_EQ(kEmail, inputs1[0].autofilled_value);
|
| - EXPECT_EQ(string16(), controller()->SuggestionTextForSection(SECTION_EMAIL));
|
| + EXPECT_EQ(string16(),
|
| + controller()->SuggestionStateForSection(SECTION_EMAIL).text);
|
|
|
| // When edit is cancelled, the autofilled_value should be empty.
|
| controller()->EditCancelledForSection(SECTION_EMAIL);
|
| const DetailInputs& inputs2 =
|
| controller()->RequestedFieldsForSection(SECTION_EMAIL);
|
| - EXPECT_EQ(kEmail, controller()->SuggestionTextForSection(SECTION_EMAIL));
|
| + EXPECT_EQ(kEmail,
|
| + controller()->SuggestionStateForSection(SECTION_EMAIL).text);
|
| EXPECT_EQ(string16(), inputs2[0].autofilled_value);
|
| }
|
|
|
| +TEST_F(AutofillDialogControllerTest, VerifyCvv) {
|
| + controller()->set_is_paying_with_wallet(true);
|
| +
|
| + EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(2);
|
| + EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| + GetFullWallet(_)).Times(1);
|
| + EXPECT_CALL(*controller()->GetTestingWalletClient(),
|
| + AuthenticateInstrument(_, _, _)).Times(1);
|
| +
|
| + scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
|
| + wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
|
| + wallet_items->AddAddress(wallet::GetTestShippingAddress());
|
| + controller()->OnDidGetWalletItems(wallet_items.Pass());
|
| + controller()->OnAccept();
|
| +
|
| + EXPECT_EQ(0U, CountNotificationsOfType(DialogNotification::REQUIRED_ACTION));
|
| + EXPECT_TRUE(controller()->SectionIsActive(SECTION_EMAIL));
|
| + EXPECT_TRUE(controller()->SectionIsActive(SECTION_SHIPPING));
|
| + EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
|
| + EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
|
| + EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
|
| +
|
| + SuggestionState suggestion_state =
|
| + controller()->SuggestionStateForSection(SECTION_CC_BILLING);
|
| + EXPECT_TRUE(suggestion_state.extra_text.empty());
|
| +
|
| + base::DictionaryValue dict;
|
| + scoped_ptr<base::ListValue> list(new base::ListValue());
|
| + list->AppendString("verify_cvv");
|
| + dict.Set("required_action", list.release());
|
| + controller()->OnDidGetFullWallet(wallet::FullWallet::CreateFullWallet(dict));
|
| +
|
| + EXPECT_EQ(1U, CountNotificationsOfType(DialogNotification::REQUIRED_ACTION));
|
| + EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL));
|
| + EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING));
|
| + EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING));
|
| +
|
| + suggestion_state =
|
| + controller()->SuggestionStateForSection(SECTION_CC_BILLING);
|
| + EXPECT_FALSE(suggestion_state.extra_text.empty());
|
| + EXPECT_EQ(
|
| + 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount());
|
| +
|
| + EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
|
| + EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL));
|
| +
|
| + controller()->OnAccept();
|
| +}
|
| +
|
| } // namespace autofill
|
|
|