| 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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/ios/wait_util.h" | 11 #include "base/test/ios/wait_util.h" |
| 12 #include "base/test/scoped_task_environment.h" | 12 #include "base/test/scoped_task_environment.h" |
| 13 #include "components/autofill/core/browser/autofill_profile.h" | 13 #include "components/autofill/core/browser/autofill_profile.h" |
| 14 #include "components/autofill/core/browser/autofill_test_utils.h" | 14 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 15 #include "components/autofill/core/browser/country_names.h" | 15 #include "components/autofill/core/browser/country_names.h" |
| 16 #include "components/autofill/core/browser/test_personal_data_manager.h" | 16 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 17 #include "components/autofill/core/browser/test_region_data_loader.h" | 17 #include "components/autofill/core/browser/test_region_data_loader.h" |
| 18 #include "components/payments/core/payments_profile_comparator.h" | 18 #include "components/payments/core/payments_profile_comparator.h" |
| 19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 20 #include "ios/chrome/browser/application_context.h" | 20 #include "ios/chrome/browser/application_context.h" |
| 21 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 21 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 22 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 22 #include "ios/chrome/browser/payments/test_payment_request.h" | 23 #include "ios/chrome/browser/payments/test_payment_request.h" |
| 23 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" | 24 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" |
| 24 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 25 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 25 #import "ios/chrome/test/scoped_key_window.h" | 26 #import "ios/chrome/test/scoped_key_window.h" |
| 27 #import "ios/web/public/test/fakes/test_web_state.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "testing/platform_test.h" | 30 #include "testing/platform_test.h" |
| 29 #include "third_party/ocmock/OCMock/OCMock.h" | 31 #include "third_party/ocmock/OCMock/OCMock.h" |
| 30 #include "third_party/ocmock/gtest_support.h" | 32 #include "third_party/ocmock/gtest_support.h" |
| 31 | 33 |
| 32 #if !defined(__has_feature) || !__has_feature(objc_arc) | 34 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 33 #error "This file requires ARC support." | 35 #error "This file requires ARC support." |
| 34 #endif | 36 #endif |
| 35 | 37 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 public: | 48 public: |
| 47 MockPaymentsProfileComparator(const std::string& app_locale, | 49 MockPaymentsProfileComparator(const std::string& app_locale, |
| 48 const payments::PaymentOptionsProvider& options) | 50 const payments::PaymentOptionsProvider& options) |
| 49 : PaymentsProfileComparator(app_locale, options) {} | 51 : PaymentsProfileComparator(app_locale, options) {} |
| 50 MOCK_METHOD1(Invalidate, void(const autofill::AutofillProfile&)); | 52 MOCK_METHOD1(Invalidate, void(const autofill::AutofillProfile&)); |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 class MockTestPaymentRequest : public payments::TestPaymentRequest { | 55 class MockTestPaymentRequest : public payments::TestPaymentRequest { |
| 54 public: | 56 public: |
| 55 MockTestPaymentRequest(web::PaymentRequest web_payment_request, | 57 MockTestPaymentRequest(web::PaymentRequest web_payment_request, |
| 58 ios::ChromeBrowserState* browser_state, |
| 59 web::WebState* web_state, |
| 56 autofill::PersonalDataManager* personal_data_manager) | 60 autofill::PersonalDataManager* personal_data_manager) |
| 57 : payments::TestPaymentRequest(web_payment_request, | 61 : payments::TestPaymentRequest(web_payment_request, |
| 62 browser_state, |
| 63 web_state, |
| 58 personal_data_manager) {} | 64 personal_data_manager) {} |
| 59 MOCK_METHOD1(AddAutofillProfile, | 65 MOCK_METHOD1(AddAutofillProfile, |
| 60 autofill::AutofillProfile*(const autofill::AutofillProfile&)); | 66 autofill::AutofillProfile*(const autofill::AutofillProfile&)); |
| 61 }; | 67 }; |
| 62 | 68 |
| 63 MATCHER_P4(ProfileMatches, name, country, state, phone_number, "") { | 69 MATCHER_P4(ProfileMatches, name, country, state, phone_number, "") { |
| 64 return arg.GetRawInfo(autofill::NAME_FULL) == base::ASCIIToUTF16(name) && | 70 return arg.GetRawInfo(autofill::NAME_FULL) == base::ASCIIToUTF16(name) && |
| 65 arg.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY) == | 71 arg.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY) == |
| 66 base::ASCIIToUTF16(country) && | 72 base::ASCIIToUTF16(country) && |
| 67 arg.GetRawInfo(autofill::ADDRESS_HOME_STATE) == | 73 arg.GetRawInfo(autofill::ADDRESS_HOME_STATE) == |
| (...skipping 29 matching lines...) Expand all Loading... |
| 97 required:YES], | 103 required:YES], |
| 98 ]; | 104 ]; |
| 99 } | 105 } |
| 100 | 106 |
| 101 using ::testing::_; | 107 using ::testing::_; |
| 102 } // namespace | 108 } // namespace |
| 103 | 109 |
| 104 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { | 110 class PaymentRequestAddressEditCoordinatorTest : public PlatformTest { |
| 105 protected: | 111 protected: |
| 106 PaymentRequestAddressEditCoordinatorTest() | 112 PaymentRequestAddressEditCoordinatorTest() |
| 107 : pref_service_(autofill::test::PrefServiceForTesting()) { | 113 : pref_service_(autofill::test::PrefServiceForTesting()), |
| 114 chrome_browser_state_(TestChromeBrowserState::Builder().Build()) { |
| 108 autofill::CountryNames::SetLocaleString("en-US"); | 115 autofill::CountryNames::SetLocaleString("en-US"); |
| 109 personal_data_manager_.SetTestingPrefService(pref_service_.get()); | 116 personal_data_manager_.SetTestingPrefService(pref_service_.get()); |
| 117 |
| 110 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( | 118 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( |
| 111 payment_request_test_util::CreateTestWebPaymentRequest(), | 119 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 112 &personal_data_manager_); | 120 chrome_browser_state_.get(), &web_state_, &personal_data_manager_); |
| 113 | 121 |
| 114 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>( | 122 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>( |
| 115 GetApplicationContext()->GetApplicationLocale(), | 123 GetApplicationContext()->GetApplicationLocale(), |
| 116 *payment_request_.get()); | 124 *payment_request_.get()); |
| 117 payment_request_->SetProfileComparator(profile_comparator_.get()); | 125 payment_request_->SetProfileComparator(profile_comparator_.get()); |
| 118 | 126 |
| 119 test_region_data_loader_.set_synchronous_callback(true); | 127 test_region_data_loader_.set_synchronous_callback(true); |
| 120 payment_request_->SetRegionDataLoader(&test_region_data_loader_); | 128 payment_request_->SetRegionDataLoader(&test_region_data_loader_); |
| 121 } | 129 } |
| 122 | 130 |
| 123 void TearDown() override { | 131 void TearDown() override { |
| 124 personal_data_manager_.SetTestingPrefService(nullptr); | 132 personal_data_manager_.SetTestingPrefService(nullptr); |
| 125 } | 133 } |
| 126 | 134 |
| 127 base::test::ScopedTaskEnvironment scoped_task_evironment_; | 135 base::test::ScopedTaskEnvironment scoped_task_evironment_; |
| 128 | 136 |
| 137 web::TestWebState web_state_; |
| 129 std::unique_ptr<PrefService> pref_service_; | 138 std::unique_ptr<PrefService> pref_service_; |
| 130 MockTestPersonalDataManager personal_data_manager_; | 139 MockTestPersonalDataManager personal_data_manager_; |
| 131 autofill::TestRegionDataLoader test_region_data_loader_; | 140 autofill::TestRegionDataLoader test_region_data_loader_; |
| 132 std::unique_ptr<MockPaymentsProfileComparator> profile_comparator_; | 141 std::unique_ptr<MockPaymentsProfileComparator> profile_comparator_; |
| 142 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 133 std::unique_ptr<MockTestPaymentRequest> payment_request_; | 143 std::unique_ptr<MockTestPaymentRequest> payment_request_; |
| 134 }; | 144 }; |
| 135 | 145 |
| 136 // Tests that invoking start and stop on the coordinator presents and dismisses | 146 // Tests that invoking start and stop on the coordinator presents and dismisses |
| 137 // the address edit view controller, respectively. | 147 // the address edit view controller, respectively. |
| 138 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { | 148 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { |
| 139 UIViewController* base_view_controller = [[UIViewController alloc] init]; | 149 UIViewController* base_view_controller = [[UIViewController alloc] init]; |
| 140 ScopedKeyWindow scoped_key_window_; | 150 ScopedKeyWindow scoped_key_window_; |
| 141 [scoped_key_window_.Get() setRootViewController:base_view_controller]; | 151 [scoped_key_window_.Get() setRootViewController:base_view_controller]; |
| 142 | 152 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 UINavigationController* navigation_controller = | 331 UINavigationController* navigation_controller = |
| 322 base::mac::ObjCCastStrict<UINavigationController>( | 332 base::mac::ObjCCastStrict<UINavigationController>( |
| 323 base_view_controller.presentedViewController); | 333 base_view_controller.presentedViewController); |
| 324 PaymentRequestEditViewController* view_controller = | 334 PaymentRequestEditViewController* view_controller = |
| 325 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( | 335 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( |
| 326 navigation_controller.visibleViewController); | 336 navigation_controller.visibleViewController); |
| 327 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; | 337 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; |
| 328 | 338 |
| 329 EXPECT_OCMOCK_VERIFY(delegate); | 339 EXPECT_OCMOCK_VERIFY(delegate); |
| 330 } | 340 } |
| OLD | NEW |