Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/payments/shipping_option_selection_coordinator.h" | 5 #import "ios/chrome/browser/payments/shipping_option_selection_coordinator.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/test/ios/wait_util.h" | 9 #include "base/test/ios/wait_util.h" |
| 10 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
| 11 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
| 12 #include "components/autofill/core/browser/test_personal_data_manager.h" | 12 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 13 #include "ios/chrome/browser/payments/payment_request.h" | 13 #include "ios/chrome/browser/payments/payment_request.h" |
| 14 #import "ios/chrome/browser/payments/payment_request_selector_view_controller.h" | |
| 14 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 15 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 15 #import "ios/chrome/browser/payments/shipping_option_selection_view_controller.h " | |
| 16 #include "ios/web/public/payments/payment_request.h" | 16 #include "ios/web/public/payments/payment_request.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 19 #include "third_party/ocmock/OCMock/OCMock.h" | 19 #include "third_party/ocmock/OCMock/OCMock.h" |
| 20 #include "third_party/ocmock/gtest_support.h" | 20 #include "third_party/ocmock/gtest_support.h" |
| 21 | 21 |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) | 22 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 23 #error "This file requires ARC support." | 23 #error "This file requires ARC support." |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 class PaymentRequestShippingOptionSelectionCoordinatorTest | 26 class PaymentRequestShippingOptionSelectionCoordinatorTest |
| 27 : public PlatformTest { | 27 : public PlatformTest { |
| 28 protected: | 28 protected: |
| 29 PaymentRequestShippingOptionSelectionCoordinatorTest() { | 29 PaymentRequestShippingOptionSelectionCoordinatorTest() { |
| 30 payment_request_ = base::MakeUnique<PaymentRequest>( | 30 payment_request_ = base::MakeUnique<PaymentRequest>( |
| 31 payment_request_test_util::CreateTestWebPaymentRequest(), | 31 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 32 &personal_data_manager_); | 32 &personal_data_manager_); |
| 33 } | 33 } |
| 34 | 34 |
| 35 autofill::TestPersonalDataManager personal_data_manager_; | 35 autofill::TestPersonalDataManager personal_data_manager_; |
| 36 std::unique_ptr<PaymentRequest> payment_request_; | 36 std::unique_ptr<PaymentRequest> payment_request_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Tests that invoking start and stop on the coordinator presents and dismisses | 39 // Tests that invoking start and stop on the coordinator presents and dismisses |
| 40 // the ShippingOptionSelectionViewController, respectively. | 40 // the PaymentRequestSelectorViewController, respectively. |
| 41 TEST_F(PaymentRequestShippingOptionSelectionCoordinatorTest, StartAndStop) { | 41 TEST_F(PaymentRequestShippingOptionSelectionCoordinatorTest, StartAndStop) { |
| 42 UIViewController* base_view_controller = [[UIViewController alloc] init]; | 42 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
| 43 UINavigationController* navigation_controller = | 43 UINavigationController* navigation_controller = |
| 44 [[UINavigationController alloc] | 44 [[UINavigationController alloc] |
| 45 initWithRootViewController:base_view_controller]; | 45 initWithRootViewController:base_view_controller]; |
| 46 | 46 |
| 47 ShippingOptionSelectionCoordinator* coordinator = | 47 ShippingOptionSelectionCoordinator* coordinator = |
| 48 [[ShippingOptionSelectionCoordinator alloc] | 48 [[ShippingOptionSelectionCoordinator alloc] |
| 49 initWithBaseViewController:base_view_controller]; | 49 initWithBaseViewController:base_view_controller]; |
| 50 [coordinator setPaymentRequest:payment_request_.get()]; | 50 [coordinator setPaymentRequest:payment_request_.get()]; |
| 51 | 51 |
| 52 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 52 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
| 53 | 53 |
| 54 [coordinator start]; | 54 [coordinator start]; |
| 55 // Short delay to allow animation to complete. | 55 // Short delay to allow animation to complete. |
| 56 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 56 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
| 57 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 57 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
| 58 | 58 |
| 59 UIViewController* view_controller = | 59 UIViewController* view_controller = |
| 60 navigation_controller.visibleViewController; | 60 navigation_controller.visibleViewController; |
| 61 EXPECT_TRUE([view_controller | 61 EXPECT_TRUE([view_controller |
| 62 isMemberOfClass:[ShippingOptionSelectionViewController class]]); | 62 isMemberOfClass:[PaymentRequestSelectorViewController class]]); |
| 63 | 63 |
| 64 [coordinator stop]; | 64 [coordinator stop]; |
| 65 // Short delay to allow animation to complete. | 65 // Short delay to allow animation to complete. |
| 66 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 66 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
| 67 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 67 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Tests that calling the view controller delegate method which notifies the | 70 // Tests that calling the view controller delegate method which notifies the |
| 71 // delegate about selection of a shipping option invokes the corresponding | 71 // delegate about selection of a shipping option invokes the corresponding |
| 72 // coordinator delegate method. | 72 // coordinator delegate method. |
| 73 TEST_F(PaymentRequestShippingOptionSelectionCoordinatorTest, | 73 TEST_F(PaymentRequestShippingOptionSelectionCoordinatorTest, |
| 74 SelectedShippingOption) { | 74 SelectedShippingOption) { |
| 75 UIViewController* base_view_controller = [[UIViewController alloc] init]; | 75 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
| 76 UINavigationController* navigation_controller = | 76 UINavigationController* navigation_controller = |
| 77 [[UINavigationController alloc] | 77 [[UINavigationController alloc] |
| 78 initWithRootViewController:base_view_controller]; | 78 initWithRootViewController:base_view_controller]; |
| 79 | 79 |
| 80 ShippingOptionSelectionCoordinator* coordinator = | 80 ShippingOptionSelectionCoordinator* coordinator = |
| 81 [[ShippingOptionSelectionCoordinator alloc] | 81 [[ShippingOptionSelectionCoordinator alloc] |
| 82 initWithBaseViewController:base_view_controller]; | 82 initWithBaseViewController:base_view_controller]; |
| 83 [coordinator setPaymentRequest:payment_request_.get()]; | 83 [coordinator setPaymentRequest:payment_request_.get()]; |
| 84 | 84 |
| 85 // Mock the coordinator delegate. | 85 // Mock the coordinator delegate. |
| 86 id delegate = [OCMockObject | 86 id delegate = [OCMockObject |
| 87 mockForProtocol:@protocol(ShippingOptionSelectionCoordinatorDelegate)]; | 87 mockForProtocol:@protocol(ShippingOptionSelectionCoordinatorDelegate)]; |
| 88 web::PaymentShippingOption option; | 88 web::PaymentShippingOption* option = payment_request_->shipping_options()[1]; |
|
macourteau
2017/04/19 18:03:13
Why index 1?
Moe
2017/04/19 20:12:44
ditto.
macourteau
2017/04/20 14:42:59
Ack.
| |
| 89 [[delegate expect] shippingOptionSelectionCoordinator:coordinator | 89 [[delegate expect] shippingOptionSelectionCoordinator:coordinator |
| 90 didSelectShippingOption:&option]; | 90 didSelectShippingOption:option]; |
| 91 [coordinator setDelegate:delegate]; | 91 [coordinator setDelegate:delegate]; |
| 92 | 92 |
| 93 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 93 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
| 94 | 94 |
| 95 [coordinator start]; | 95 [coordinator start]; |
| 96 // Short delay to allow animation to complete. | 96 // Short delay to allow animation to complete. |
| 97 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 97 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
| 98 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 98 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
| 99 | 99 |
| 100 // Call the controller delegate method. | 100 // Call the controller delegate method. |
| 101 ShippingOptionSelectionViewController* view_controller = | 101 PaymentRequestSelectorViewController* view_controller = |
| 102 base::mac::ObjCCastStrict<ShippingOptionSelectionViewController>( | 102 base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>( |
| 103 navigation_controller.visibleViewController); | 103 navigation_controller.visibleViewController); |
| 104 [coordinator shippingOptionSelectionViewController:view_controller | 104 [coordinator paymentRequestSelectorViewController:view_controller |
| 105 didSelectShippingOption:&option]; | 105 didSelectItemAtIndex:1]; |
| 106 | 106 |
| 107 // Wait for the coordinator delegate to be notified. | 107 // Wait for the coordinator delegate to be notified. |
| 108 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5)); | 108 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5)); |
| 109 | 109 |
| 110 EXPECT_OCMOCK_VERIFY(delegate); | 110 EXPECT_OCMOCK_VERIFY(delegate); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Tests that calling the view controller delegate method which notifies the | 113 // Tests that calling the view controller delegate method which notifies the |
| 114 // delegate that the user has chosen to return without making a selection | 114 // delegate that the user has chosen to return without making a selection |
| 115 // invokes the coordinator delegate method. | 115 // invokes the coordinator delegate method. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 131 [coordinator setDelegate:delegate]; | 131 [coordinator setDelegate:delegate]; |
| 132 | 132 |
| 133 EXPECT_EQ(1u, navigation_controller.viewControllers.count); | 133 EXPECT_EQ(1u, navigation_controller.viewControllers.count); |
| 134 | 134 |
| 135 [coordinator start]; | 135 [coordinator start]; |
| 136 // Short delay to allow animation to complete. | 136 // Short delay to allow animation to complete. |
| 137 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); | 137 base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0)); |
| 138 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 138 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
| 139 | 139 |
| 140 // Call the controller delegate method. | 140 // Call the controller delegate method. |
| 141 ShippingOptionSelectionViewController* view_controller = | 141 PaymentRequestSelectorViewController* view_controller = |
| 142 base::mac::ObjCCastStrict<ShippingOptionSelectionViewController>( | 142 base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>( |
| 143 navigation_controller.visibleViewController); | 143 navigation_controller.visibleViewController); |
| 144 [coordinator shippingOptionSelectionViewControllerDidReturn:view_controller]; | 144 [coordinator paymentRequestSelectorViewControllerDidFinish:view_controller]; |
| 145 | 145 |
| 146 EXPECT_OCMOCK_VERIFY(delegate); | 146 EXPECT_OCMOCK_VERIFY(delegate); |
| 147 } | 147 } |
| OLD | NEW |