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

Unified Diff: chrome/browser/ui/views/payments/credit_card_editor_view_controller_browsertest.cc

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix Created 3 years, 7 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/views/payments/credit_card_editor_view_controller_browsertest.cc
diff --git a/chrome/browser/ui/views/payments/credit_card_editor_view_controller_browsertest.cc b/chrome/browser/ui/views/payments/credit_card_editor_view_controller_browsertest.cc
index 4fc96048e44eb063707370d04d37059d0cca5a4e..3dbf8884fc6789004e75d37d5b89affc55aae358 100644
--- a/chrome/browser/ui/views/payments/credit_card_editor_view_controller_browsertest.cc
+++ b/chrome/browser/ui/views/payments/credit_card_editor_view_controller_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
#include <vector>
#include "base/macros.h"
@@ -10,6 +11,7 @@
#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
#include "chrome/browser/ui/views/payments/validating_textfield.h"
+#include "components/autofill/core/browser/address_combobox_model.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/personal_data_manager.h"
@@ -20,6 +22,7 @@
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/controls/combobox/combobox.h"
namespace payments {
@@ -28,6 +31,7 @@ namespace {
const base::Time kJanuary2017 = base::Time::FromDoubleT(1484505871);
const base::Time kJune2017 = base::Time::FromDoubleT(1497552271);
+const auto kBillingAddressType = autofill::MAX_VALID_FIELD_TYPE;
} // namespace
class PaymentRequestCreditCardEditorTest
@@ -37,6 +41,16 @@ class PaymentRequestCreditCardEditorTest
: PaymentRequestBrowserTestBase(
"/payment_request_no_shipping_test.html") {}
+ void SelectBillingAddress(const std::string& billing_address_id) {
+ views::Combobox* address_combobox(static_cast<views::Combobox*>(
+ dialog_view()->GetViewByID(static_cast<int>(kBillingAddressType))));
+ ASSERT_NE(address_combobox, nullptr);
+ autofill::AddressComboboxModel* address_combobox_model(
+ static_cast<autofill::AddressComboboxModel*>(
+ address_combobox->model()));
+ address_combobox->SetSelectedIndex(
+ address_combobox_model->GetIndexOfIdentifier(billing_address_id));
+ }
PersonalDataLoadedObserverMock personal_data_observer_;
private:
@@ -54,6 +68,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EnteringValidData) {
EXPECT_EQ(0U, request->state()->available_instruments().size());
EXPECT_EQ(nullptr, request->state()->selected_instrument());
+ // But there must be at least one address available for billing.
+ autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile());
+ PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile);
+
OpenCreditCardEditorScreen();
SetEditorTextfieldValue(base::ASCIIToUTF16("Bob Jones"),
@@ -63,6 +81,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EnteringValidData) {
SetComboboxValue(base::ASCIIToUTF16("05"), autofill::CREDIT_CARD_EXP_MONTH);
SetComboboxValue(base::ASCIIToUTF16("2026"),
autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
+ SelectBillingAddress(billing_profile.guid());
// Verifying the data is in the DB.
autofill::PersonalDataManager* personal_data_manager = GetDataManager();
@@ -236,6 +255,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
EnteringInvalidCardNumber_AndFixingIt) {
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kJune2017);
+ autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile());
+ PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile);
InvokePaymentRequestUI();
@@ -251,6 +272,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
SetComboboxValue(base::ASCIIToUTF16("05"), autofill::CREDIT_CARD_EXP_MONTH);
SetComboboxValue(base::ASCIIToUTF16("2026"),
autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
+ SelectBillingAddress(billing_profile.guid());
ClickOnDialogViewAndWait(DialogViewID::EDITOR_SAVE_BUTTON);
@@ -296,6 +318,9 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EditingExpiredCard) {
card.set_use_date(kJanuary2017);
card.SetExpirationMonth(1);
card.SetExpirationYear(2017);
+ autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile());
+ PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile);
Mathieu 2017/05/04 20:29:19 no need for PaymentRequestBrowserTestBase:
MAD 2017/05/05 00:50:07 Done.
+ card.set_billing_address_id(billing_profile.guid());
AddCreditCard(card);
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kJune2017);
@@ -357,6 +382,158 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EditingExpiredCard) {
request->state()->selected_instrument());
}
+IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
+ EditingCardWithoutBillingAddress) {
+ autofill::CreditCard card = autofill::test::GetCreditCard();
+ // Make sure to clear billing address.
+ card.set_billing_address_id("");
+ AddCreditCard(card);
+
+ autofill::TestAutofillClock test_clock;
+ test_clock.SetNow(kJune2017);
+ autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile());
+ PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile);
+
+ InvokePaymentRequestUI();
+
+ // One instrument is available, but it's not selected.
+ PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
+ EXPECT_EQ(1U, request->state()->available_instruments().size());
+ EXPECT_EQ(nullptr, request->state()->selected_instrument());
+
+ OpenPaymentMethodScreen();
+
+ ResetEventObserver(DialogEvent::CREDIT_CARD_EDITOR_OPENED);
+ ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1,
+ DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW);
+
+ // Fixing the billing address.
+ SelectBillingAddress(billing_profile.guid());
+
+ // Verifying the data is in the DB.
+ autofill::PersonalDataManager* personal_data_manager = GetDataManager();
+ personal_data_manager->AddObserver(&personal_data_observer_);
+
+ ResetEventObserver(DialogEvent::BACK_TO_PAYMENT_SHEET_NAVIGATION);
+
+ // Wait until the web database has been updated and the notification sent.
+ base::RunLoop data_loop;
+ EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
+ .WillOnce(QuitMessageLoop(&data_loop));
+ ClickOnDialogViewAndWait(DialogViewID::EDITOR_SAVE_BUTTON);
+ data_loop.Run();
+
+ EXPECT_EQ(1u, personal_data_manager->GetCreditCards().size());
+ autofill::CreditCard* credit_card =
+ personal_data_manager->GetCreditCards()[0];
+ EXPECT_EQ(billing_profile.guid(), credit_card->billing_address_id());
+ // It retains other properties.
+ EXPECT_EQ(card.guid(), credit_card->guid());
+ EXPECT_EQ(base::ASCIIToUTF16("4111111111111111"), credit_card->number());
+ EXPECT_EQ(base::ASCIIToUTF16("Test User"),
+ credit_card->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL));
+
+ // Still have one instrument, but now it's selected.
+ EXPECT_EQ(1U, request->state()->available_instruments().size());
+ EXPECT_EQ(request->state()->available_instruments().back().get(),
+ request->state()->selected_instrument());
+}
+
+IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
+ CreateNewBillingAddress) {
+ autofill::CreditCard card = autofill::test::GetCreditCard();
+ // Make sure to clear billing address.
+ card.set_billing_address_id("");
+ AddCreditCard(card);
+
+ autofill::TestAutofillClock test_clock;
+ test_clock.SetNow(kJune2017);
+ autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile());
+ PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile);
+
+ InvokePaymentRequestUI();
+
+ // One instrument is available, but it's not selected.
+ PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
+ EXPECT_EQ(1U, request->state()->available_instruments().size());
+ EXPECT_EQ(nullptr, request->state()->selected_instrument());
+
+ OpenPaymentMethodScreen();
+
+ ResetEventObserver(DialogEvent::CREDIT_CARD_EDITOR_OPENED);
+ ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1,
+ DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW);
+ // Click to open the address editor
+ ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED);
+ ClickOnDialogViewAndWait(DialogViewID::ADD_BILLING_ADDRESS_BUTTON);
+
+ // Set valid address values.
+ SetEditorTextfieldValue(base::ASCIIToUTF16("Bob"), autofill::NAME_FULL);
+ SetEditorTextfieldValue(base::ASCIIToUTF16("42 BobStreet"),
+ autofill::ADDRESS_HOME_STREET_ADDRESS);
+ SetEditorTextfieldValue(base::ASCIIToUTF16("BobCity"),
+ autofill::ADDRESS_HOME_CITY);
+ SetEditorTextfieldValue(base::ASCIIToUTF16("BobZip"),
+ autofill::ADDRESS_HOME_ZIP);
+
+ // Come back to credit card editor.
+ ResetEventObserver(DialogEvent::BACK_NAVIGATION);
+ ClickOnDialogViewAndWait(DialogViewID::SAVE_ADDRESS_BUTTON);
+
+ // And then save credit card state and come back to payment sheet.
+ ResetEventObserver(DialogEvent::BACK_TO_PAYMENT_SHEET_NAVIGATION);
+
+ // Verifying the data is in the DB.
+ autofill::PersonalDataManager* personal_data_manager = GetDataManager();
+ personal_data_manager->AddObserver(&personal_data_observer_);
+
+ // Wait until the web database has been updated and the notification sent.
+ base::RunLoop data_loop;
+ EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
+ .WillOnce(QuitMessageLoop(&data_loop));
+ ClickOnDialogViewAndWait(DialogViewID::EDITOR_SAVE_BUTTON);
+ data_loop.Run();
+
+ // Still have one instrument, but now it's selected.
+ EXPECT_EQ(1U, request->state()->available_instruments().size());
+ EXPECT_EQ(request->state()->available_instruments().back().get(),
+ request->state()->selected_instrument());
+}
+
+IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
+ NonexistentBillingAddres) {
+ autofill::CreditCard card = autofill::test::GetCreditCard();
+ // Set a billing address that is not yet added to the personal data.
+ autofill::AutofillProfile billing_profile(autofill::test::GetFullProfile());
+ card.set_billing_address_id(billing_profile.guid());
+ AddCreditCard(card);
+
+ autofill::TestAutofillClock test_clock;
+ test_clock.SetNow(kJune2017);
+
+ InvokePaymentRequestUI();
+
+ // One instrument is available, but it's not selected.
+ PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
+ EXPECT_EQ(1U, request->state()->available_instruments().size());
+ EXPECT_EQ(nullptr, request->state()->selected_instrument());
+
+ // Now add the billing address to the personal data.
+ PaymentRequestBrowserTestBase::AddAutofillProfile(billing_profile);
+
+ // Go back and re-invoke.
+ ResetEventObserver(DialogEvent::DIALOG_CLOSED);
+ ClickOnDialogViewAndWait(DialogViewID::CANCEL_BUTTON,
+ /*wait_for_animation=*/false);
+ InvokePaymentRequestUI();
+
+ // Still have one instrument, but now it's selected.
+ request = GetPaymentRequests(GetActiveWebContents()).front();
+ EXPECT_EQ(1U, request->state()->available_instruments().size());
+ EXPECT_EQ(request->state()->available_instruments().back().get(),
+ request->state()->selected_instrument());
+}
+
IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EnteringEmptyData) {
InvokePaymentRequestUI();

Powered by Google App Engine
This is Rietveld 408576698