| Index: ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm
|
| diff --git a/ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm b/ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm
|
| index 0abd05493b117e56d6aced105f133a4d19dac6d2..15c77b4f27bc2e052b013b48384b74f24a0dea4d 100644
|
| --- a/ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm
|
| +++ b/ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm
|
| @@ -9,9 +9,13 @@
|
| #include "base/test/ios/wait_util.h"
|
| #include "components/autofill/core/browser/autofill_profile.h"
|
| #include "components/autofill/core/browser/autofill_test_utils.h"
|
| +#include "components/autofill/core/browser/autofill_type.h"
|
| +#include "components/autofill/core/browser/field_types.h"
|
| #include "components/autofill/core/browser/test_personal_data_manager.h"
|
| -#include "ios/chrome/browser/payments/payment_request.h"
|
| +#include "components/autofill/core/browser/test_region_data_loader.h"
|
| +#include "components/prefs/pref_service.h"
|
| #include "ios/chrome/browser/payments/payment_request_test_util.h"
|
| +#include "ios/chrome/browser/payments/test_payment_request.h"
|
| #import "ios/chrome/browser/ui/payments/payment_request_selector_view_controller.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/platform_test.h"
|
| @@ -27,13 +31,24 @@ class PaymentRequestBillingAddressSelectionCoordinatorTest
|
| protected:
|
| PaymentRequestBillingAddressSelectionCoordinatorTest()
|
| : autofill_profile1_(autofill::test::GetFullProfile()),
|
| - autofill_profile2_(autofill::test::GetFullProfile2()) {
|
| - // Add testing profiles to autofill::TestPersonalDataManager.
|
| + autofill_profile2_(autofill::test::GetFullProfile2()),
|
| + pref_service_(autofill::test::PrefServiceForTesting()) {
|
| + personal_data_manager_.SetTestingPrefService(pref_service_.get());
|
| + // Add testing profiles to autofill::TestPersonalDataManager. Make the less
|
| + // frequently used one incomplete.
|
| + autofill_profile1_.set_use_count(10U);
|
| personal_data_manager_.AddTestingProfile(&autofill_profile1_);
|
| + autofill_profile2_.set_use_count(5U);
|
| + autofill_profile2_.SetInfo(
|
| + autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
|
| + base::string16(), "en-US");
|
| personal_data_manager_.AddTestingProfile(&autofill_profile2_);
|
| - payment_request_ = base::MakeUnique<PaymentRequest>(
|
| + payment_request_ = base::MakeUnique<TestPaymentRequest>(
|
| payment_request_test_util::CreateTestWebPaymentRequest(),
|
| &personal_data_manager_);
|
| +
|
| + test_region_data_loader_.set_synchronous_callback(true);
|
| + payment_request_->SetRegionDataLoader(&test_region_data_loader_);
|
| }
|
|
|
| void SetUp() override {
|
| @@ -46,6 +61,10 @@ class PaymentRequestBillingAddressSelectionCoordinatorTest
|
| [coordinator_ setPaymentRequest:payment_request_.get()];
|
| }
|
|
|
| + void TearDown() override {
|
| + personal_data_manager_.SetTestingPrefService(nullptr);
|
| + }
|
| +
|
| UINavigationController* GetNavigationController() {
|
| return navigation_controller_;
|
| }
|
| @@ -57,8 +76,10 @@ class PaymentRequestBillingAddressSelectionCoordinatorTest
|
|
|
| autofill::AutofillProfile autofill_profile1_;
|
| autofill::AutofillProfile autofill_profile2_;
|
| + std::unique_ptr<PrefService> pref_service_;
|
| autofill::TestPersonalDataManager personal_data_manager_;
|
| - std::unique_ptr<PaymentRequest> payment_request_;
|
| + autofill::TestRegionDataLoader test_region_data_loader_;
|
| + std::unique_ptr<TestPaymentRequest> payment_request_;
|
| };
|
|
|
| // Tests that invoking start and stop on the coordinator presents and dismisses
|
| @@ -84,15 +105,20 @@ TEST_F(PaymentRequestBillingAddressSelectionCoordinatorTest, StartAndStop) {
|
|
|
| // Tests that calling the view controller delegate method which notifies the
|
| // delegate about selection of a billing address invokes the corresponding
|
| -// coordinator delegate method.
|
| +// coordinator delegate method, only if the payment method is complete.
|
| TEST_F(PaymentRequestBillingAddressSelectionCoordinatorTest,
|
| SelectedBillingAddress) {
|
| // Mock the coordinator delegate.
|
| id delegate = [OCMockObject
|
| mockForProtocol:@protocol(BillingAddressSelectionCoordinatorDelegate)];
|
| - autofill::AutofillProfile* profile = payment_request_->billing_profiles()[1];
|
| - [[delegate expect] billingAddressSelectionCoordinator:GetCoordinator()
|
| - didSelectBillingAddress:profile];
|
| + [[delegate expect]
|
| + billingAddressSelectionCoordinator:GetCoordinator()
|
| + didSelectBillingAddress:payment_request_
|
| + ->billing_profiles()[0]];
|
| + [[delegate reject]
|
| + billingAddressSelectionCoordinator:GetCoordinator()
|
| + didSelectBillingAddress:payment_request_
|
| + ->billing_profiles()[1]];
|
| [GetCoordinator() setDelegate:delegate];
|
|
|
| EXPECT_EQ(1u, GetNavigationController().viewControllers.count);
|
| @@ -102,13 +128,16 @@ TEST_F(PaymentRequestBillingAddressSelectionCoordinatorTest,
|
| base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
|
| EXPECT_EQ(2u, GetNavigationController().viewControllers.count);
|
|
|
| - // Call the controller delegate method.
|
| + // Call the controller delegate method for both selectable items.
|
| PaymentRequestSelectorViewController* view_controller =
|
| base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
|
| GetNavigationController().visibleViewController);
|
| [GetCoordinator() paymentRequestSelectorViewController:view_controller
|
| + didSelectItemAtIndex:0];
|
| + // Wait for the coordinator delegate to be notified.
|
| + base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
|
| + [GetCoordinator() paymentRequestSelectorViewController:view_controller
|
| didSelectItemAtIndex:1];
|
| -
|
| // Wait for the coordinator delegate to be notified.
|
| base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
|
|
|
|
|