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

Unified Diff: ios/chrome/browser/ui/payments/shipping_address_selection_coordinator_unittest.mm

Issue 2958873002: [Payment Request] Unit tests for incomplete shipping/billing address selection (Closed)
Patch Set: Created 3 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
« no previous file with comments | « ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/payments/shipping_address_selection_coordinator_unittest.mm
diff --git a/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator_unittest.mm b/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator_unittest.mm
index 3eb3d5103be7ad17e0f2730be69ef8e67330eab2..a9c3bdb0310bb04ed8e91dbe9fff62572768d125 100644
--- a/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator_unittest.mm
+++ b/ios/chrome/browser/ui/payments/shipping_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,19 +31,36 @@ class PaymentRequestShippingAddressSelectionCoordinatorTest
protected:
PaymentRequestShippingAddressSelectionCoordinatorTest()
: 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 TearDown() override {
+ personal_data_manager_.SetTestingPrefService(nullptr);
}
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
@@ -75,7 +96,7 @@ TEST_F(PaymentRequestShippingAddressSelectionCoordinatorTest, StartAndStop) {
// Tests that calling the view controller delegate method which notifies the
// delegate about selection of a shipping address invokes the corresponding
-// coordinator delegate method.
+// coordinator delegate method, only if the payment method is complete.
TEST_F(PaymentRequestShippingAddressSelectionCoordinatorTest,
SelectedShippingAddress) {
UIViewController* base_view_controller = [[UIViewController alloc] init];
@@ -91,9 +112,14 @@ TEST_F(PaymentRequestShippingAddressSelectionCoordinatorTest,
// Mock the coordinator delegate.
id delegate = [OCMockObject
mockForProtocol:@protocol(ShippingAddressSelectionCoordinatorDelegate)];
- autofill::AutofillProfile* profile = payment_request_->shipping_profiles()[1];
- [[delegate expect] shippingAddressSelectionCoordinator:coordinator
- didSelectShippingAddress:profile];
+ [[delegate expect]
+ shippingAddressSelectionCoordinator:coordinator
+ didSelectShippingAddress:payment_request_
+ ->shipping_profiles()[0]];
+ [[delegate reject]
+ shippingAddressSelectionCoordinator:coordinator
+ didSelectShippingAddress:payment_request_
+ ->shipping_profiles()[1]];
[coordinator setDelegate:delegate];
EXPECT_EQ(1u, navigation_controller.viewControllers.count);
@@ -103,13 +129,16 @@ TEST_F(PaymentRequestShippingAddressSelectionCoordinatorTest,
base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
EXPECT_EQ(2u, navigation_controller.viewControllers.count);
- // Call the controller delegate method.
+ // Call the controller delegate method for both selectable items.
PaymentRequestSelectorViewController* view_controller =
base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
navigation_controller.visibleViewController);
[coordinator paymentRequestSelectorViewController:view_controller
+ didSelectItemAtIndex:0];
+ // Wait for the coordinator delegate to be notified.
+ base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
+ [coordinator paymentRequestSelectorViewController:view_controller
didSelectItemAtIndex:1];
-
// Wait for the coordinator delegate to be notified.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
« no previous file with comments | « ios/chrome/browser/ui/payments/billing_address_selection_coordinator_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698