| Index: chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc
|
| diff --git a/chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc b/chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f8710d2944e6a768cdf255ff406909c408ffe755
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc
|
| @@ -0,0 +1,198 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#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/autofill_country.h"
|
| +#include "components/autofill/core/browser/country_combobox_model.h"
|
| +#include "components/autofill/core/browser/personal_data_manager.h"
|
| +#include "components/autofill/core/browser/region_combobox_model.h"
|
| +#include "components/payments/content/payment_request_spec.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/views/controls/combobox/combobox.h"
|
| +
|
| +namespace payments {
|
| +
|
| +namespace {
|
| +
|
| +const char kNameFull[] = "Bob Jones";
|
| +const char kHomeAddress[] = "42 Answers-All Avenue";
|
| +const char kHomeCity[] = "Question-City";
|
| +const char kHomeZip[] = "ziiiiiip";
|
| +
|
| +} // namespace
|
| +
|
| +class PaymentRequestShippingAddressEditorTest
|
| + : public PaymentRequestBrowserTestBase {
|
| + protected:
|
| + PaymentRequestShippingAddressEditorTest()
|
| + : PaymentRequestBrowserTestBase(
|
| + "/payment_request_dynamic_shipping_test.html") {}
|
| +
|
| + PersonalDataLoadedObserverMock personal_data_observer_;
|
| +
|
| + void SetRequiredFields() {
|
| + SetEditorTextfieldValue(base::ASCIIToUTF16(kNameFull), autofill::NAME_FULL);
|
| + SetEditorTextfieldValue(base::ASCIIToUTF16(kHomeAddress),
|
| + autofill::ADDRESS_HOME_STREET_ADDRESS);
|
| + SetEditorTextfieldValue(base::ASCIIToUTF16(kHomeCity),
|
| + autofill::ADDRESS_HOME_CITY);
|
| + SetEditorTextfieldValue(base::ASCIIToUTF16(kHomeZip),
|
| + autofill::ADDRESS_HOME_ZIP);
|
| + }
|
| +
|
| + std::string GetSelectedCountryCode() {
|
| + views::Combobox* country_combobox =
|
| + static_cast<views::Combobox*>(dialog_view()->GetViewByID(
|
| + static_cast<int>(autofill::ADDRESS_HOME_COUNTRY)));
|
| + DCHECK(country_combobox);
|
| + int selected_country_row = country_combobox->GetSelectedRow();
|
| + autofill::CountryComboboxModel* model =
|
| + static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
|
| +
|
| + return model->countries()[selected_country_row]->country_code();
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(PaymentRequestShippingAddressEditorTest);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
|
| + EnteringValidDataWithDefaultCountry) {
|
| + InvokePaymentRequestUI();
|
| +
|
| + OpenShippingAddressSectionScreen();
|
| +
|
| + OpenShippingAddressEditorScreen();
|
| +
|
| + std::string country_code(GetSelectedCountryCode());
|
| +
|
| + SetRequiredFields();
|
| +
|
| + ResetEventObserver(DialogEvent::BACK_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();
|
| +
|
| + ASSERT_EQ(1UL, personal_data_manager->GetProfiles().size());
|
| + autofill::AutofillProfile* profile = personal_data_manager->GetProfiles()[0];
|
| + DCHECK(profile);
|
| + EXPECT_EQ(base::ASCIIToUTF16(country_code),
|
| + profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
|
| + EXPECT_EQ(base::ASCIIToUTF16(kNameFull),
|
| + profile->GetRawInfo(autofill::NAME_FULL));
|
| + EXPECT_EQ(base::ASCIIToUTF16(kHomeAddress),
|
| + profile->GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS));
|
| + EXPECT_EQ(base::ASCIIToUTF16(kHomeCity),
|
| + profile->GetRawInfo(autofill::ADDRESS_HOME_CITY));
|
| + EXPECT_EQ(base::ASCIIToUTF16(kHomeZip),
|
| + profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
|
| + SwitchingCountryUpdatesView) {
|
| + InvokePaymentRequestUI();
|
| +
|
| + OpenShippingAddressSectionScreen();
|
| +
|
| + OpenShippingAddressEditorScreen();
|
| +
|
| + views::Combobox* country_combobox =
|
| + static_cast<views::Combobox*>(dialog_view()->GetViewByID(
|
| + static_cast<int>(autofill::ADDRESS_HOME_COUNTRY)));
|
| + ASSERT_NE(nullptr, country_combobox);
|
| + ASSERT_EQ(0, country_combobox->GetSelectedRow());
|
| + autofill::CountryComboboxModel* model =
|
| + static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
|
| + size_t num_countries = model->countries().size();
|
| + ASSERT_GT(num_countries, 10UL);
|
| + for (size_t country_index = 1; country_index < num_countries;
|
| + country_index += num_countries / 10) {
|
| + // The editor updates asynchronously when the country changes.
|
| + ResetEventObserver(DialogEvent::EDITOR_VIEW_UPDATED);
|
| + country_combobox->SetSelectedRow(country_index);
|
| + country_combobox->OnBlur();
|
| +
|
| + // The view update will invalidate the country_combobox / model pointers.
|
| + country_combobox = nullptr;
|
| + model = nullptr;
|
| + WaitForObservedEvent();
|
| +
|
| + // Make sure the country combo box was properly reset to the chosen country.
|
| + country_combobox = static_cast<views::Combobox*>(dialog_view()->GetViewByID(
|
| + static_cast<int>(autofill::ADDRESS_HOME_COUNTRY)));
|
| + DCHECK(country_combobox);
|
| + EXPECT_EQ(country_index,
|
| + static_cast<size_t>(country_combobox->GetSelectedRow()));
|
| +
|
| + country_combobox = static_cast<views::Combobox*>(dialog_view()->GetViewByID(
|
| + static_cast<int>(autofill::ADDRESS_HOME_COUNTRY)));
|
| + DCHECK(country_combobox);
|
| + model =
|
| + static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
|
| + ASSERT_EQ(num_countries, model->countries().size());
|
| + }
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
|
| + FailToLoadRegionData) {
|
| + InvokePaymentRequestUI();
|
| +
|
| + OpenShippingAddressSectionScreen();
|
| +
|
| + OpenShippingAddressEditorScreen();
|
| +
|
| + // The editor updates asynchronously when the regions fail to load.
|
| + ResetEventObserver(DialogEvent::EDITOR_VIEW_UPDATED);
|
| + views::Combobox* country_combobox =
|
| + static_cast<views::Combobox*>(dialog_view()->GetViewByID(
|
| + static_cast<int>(autofill::ADDRESS_HOME_STATE)));
|
| + ASSERT_NE(nullptr, country_combobox);
|
| + autofill::RegionComboboxModel* model =
|
| + static_cast<autofill::RegionComboboxModel*>(country_combobox->model());
|
| + model->SetFailureModeForTests(true);
|
| +
|
| + // The view update will invalidate the country_combobox / model pointers.
|
| + country_combobox = nullptr;
|
| + model = nullptr;
|
| + WaitForObservedEvent();
|
| +
|
| + // Now any textual value can be set as the state.
|
| + SetEditorTextfieldValue(base::ASCIIToUTF16("any state"),
|
| + autofill::ADDRESS_HOME_STATE);
|
| + SetRequiredFields();
|
| + ResetEventObserver(DialogEvent::BACK_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();
|
| +
|
| + ASSERT_EQ(1UL, personal_data_manager->GetProfiles().size());
|
| + autofill::AutofillProfile* profile = personal_data_manager->GetProfiles()[0];
|
| + DCHECK(profile);
|
| + EXPECT_EQ(base::ASCIIToUTF16("any state"),
|
| + profile->GetRawInfo(autofill::ADDRESS_HOME_STATE));
|
| +}
|
| +
|
| +} // namespace payments
|
|
|