| 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/ui/payments/address_edit_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/address_edit_coordinator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/test/ios/wait_util.h" | 10 #include "base/test/ios/wait_util.h" |
| 11 #include "components/autofill/core/browser/autofill_profile.h" | 11 #include "components/autofill/core/browser/autofill_profile.h" |
| 12 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 12 #include "components/autofill/core/browser/test_personal_data_manager.h" | 13 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 13 #include "ios/chrome/browser/payments/payment_request.h" | 14 #include "components/autofill/core/browser/test_region_data_loader.h" |
| 15 #include "components/prefs/pref_service.h" |
| 14 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 16 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 17 #include "ios/chrome/browser/payments/test_payment_request.h" |
| 15 #import "ios/chrome/browser/ui/payments/address_edit_view_controller.h" | 18 #import "ios/chrome/browser/ui/payments/address_edit_view_controller.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
| 18 #include "third_party/ocmock/OCMock/OCMock.h" | 21 #include "third_party/ocmock/OCMock/OCMock.h" |
| 19 #include "third_party/ocmock/gtest_support.h" | 22 #include "third_party/ocmock/gtest_support.h" |
| 20 | 23 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 23 #endif | 26 #endif |
| 24 | 27 |
| 25 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { | 28 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { |
| 26 protected: | 29 protected: |
| 27 PaymentRequestAddressEditCoordinatorTest() { | 30 PaymentRequestAddressEditCoordinatorTest() |
| 28 payment_request_ = base::MakeUnique<PaymentRequest>( | 31 : pref_service_(autofill::test::PrefServiceForTesting()) { |
| 32 personal_data_manager_.SetTestingPrefService(pref_service_.get()); |
| 33 payment_request_ = base::MakeUnique<TestPaymentRequest>( |
| 29 payment_request_test_util::CreateTestWebPaymentRequest(), | 34 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 30 &personal_data_manager_); | 35 &personal_data_manager_); |
| 36 test_region_data_loader_.set_synchronous_callback(true); |
| 37 payment_request_->SetRegionDataLoader(&test_region_data_loader_); |
| 38 } |
| 39 |
| 40 void TearDown() override { |
| 41 personal_data_manager_.SetTestingPrefService(nullptr); |
| 31 } | 42 } |
| 32 | 43 |
| 33 autofill::TestPersonalDataManager personal_data_manager_; | 44 autofill::TestPersonalDataManager personal_data_manager_; |
| 34 std::unique_ptr<PaymentRequest> payment_request_; | 45 std::unique_ptr<PrefService> pref_service_; |
| 46 std::unique_ptr<TestPaymentRequest> payment_request_; |
| 47 autofill::TestRegionDataLoader test_region_data_loader_; |
| 35 }; | 48 }; |
| 36 | 49 |
| 37 // Tests that invoking start and stop on the coordinator presents and dismisses | 50 // Tests that invoking start and stop on the coordinator presents and dismisses |
| 38 // the address edit view controller, respectively. | 51 // the address edit view controller, respectively. |
| 39 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { | 52 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { |
| 40 UIViewController* base_view_controller = [[UIViewController alloc] init]; | 53 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
| 41 UINavigationController* navigation_controller = | 54 UINavigationController* navigation_controller = |
| 42 [[UINavigationController alloc] | 55 [[UINavigationController alloc] |
| 43 initWithRootViewController:base_view_controller]; | 56 initWithRootViewController:base_view_controller]; |
| 44 | 57 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 EXPECT_EQ(2u, navigation_controller.viewControllers.count); | 138 EXPECT_EQ(2u, navigation_controller.viewControllers.count); |
| 126 | 139 |
| 127 // Call the controller delegate method. | 140 // Call the controller delegate method. |
| 128 AddressEditViewController* view_controller = | 141 AddressEditViewController* view_controller = |
| 129 base::mac::ObjCCastStrict<AddressEditViewController>( | 142 base::mac::ObjCCastStrict<AddressEditViewController>( |
| 130 navigation_controller.visibleViewController); | 143 navigation_controller.visibleViewController); |
| 131 [coordinator addressEditViewControllerDidCancel:view_controller]; | 144 [coordinator addressEditViewControllerDidCancel:view_controller]; |
| 132 | 145 |
| 133 EXPECT_OCMOCK_VERIFY(delegate); | 146 EXPECT_OCMOCK_VERIFY(delegate); |
| 134 } | 147 } |
| OLD | NEW |