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

Side by Side Diff: ios/chrome/browser/ui/payments/address_edit_coordinator_unittest.mm

Issue 2970233002: [Payment Request] Adds a JourneyLogger instance to the PaymentRequest (Closed)
Patch Set: Initial Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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
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
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()) {
please use gerrit instead 2017/07/06 14:52:24 chrome_browser_state_(TestChromeBrowserState::Buil
Moe 2017/07/07 02:24:54 Done.
108 autofill::CountryNames::SetLocaleString("en-US"); 114 autofill::CountryNames::SetLocaleString("en-US");
109 personal_data_manager_.SetTestingPrefService(pref_service_.get()); 115 personal_data_manager_.SetTestingPrefService(pref_service_.get());
116
117 TestChromeBrowserState::Builder test_cbs_builder;
118 chrome_browser_state_ = test_cbs_builder.Build();
119
110 payment_request_ = base::MakeUnique<MockTestPaymentRequest>( 120 payment_request_ = base::MakeUnique<MockTestPaymentRequest>(
111 payment_request_test_util::CreateTestWebPaymentRequest(), 121 payment_request_test_util::CreateTestWebPaymentRequest(),
112 &personal_data_manager_); 122 chrome_browser_state_.get(), &web_state_, &personal_data_manager_);
113 123
114 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>( 124 profile_comparator_ = base::MakeUnique<MockPaymentsProfileComparator>(
115 GetApplicationContext()->GetApplicationLocale(), 125 GetApplicationContext()->GetApplicationLocale(),
116 *payment_request_.get()); 126 *payment_request_.get());
117 payment_request_->SetProfileComparator(profile_comparator_.get()); 127 payment_request_->SetProfileComparator(profile_comparator_.get());
118 128
119 test_region_data_loader_.set_synchronous_callback(true); 129 test_region_data_loader_.set_synchronous_callback(true);
120 payment_request_->SetRegionDataLoader(&test_region_data_loader_); 130 payment_request_->SetRegionDataLoader(&test_region_data_loader_);
121 } 131 }
122 132
123 void TearDown() override { 133 void TearDown() override {
124 personal_data_manager_.SetTestingPrefService(nullptr); 134 personal_data_manager_.SetTestingPrefService(nullptr);
125 } 135 }
126 136
127 base::test::ScopedTaskEnvironment scoped_task_evironment_; 137 base::test::ScopedTaskEnvironment scoped_task_evironment_;
128 138
139 web::TestWebState web_state_;
129 std::unique_ptr<PrefService> pref_service_; 140 std::unique_ptr<PrefService> pref_service_;
130 MockTestPersonalDataManager personal_data_manager_; 141 MockTestPersonalDataManager personal_data_manager_;
131 autofill::TestRegionDataLoader test_region_data_loader_; 142 autofill::TestRegionDataLoader test_region_data_loader_;
132 std::unique_ptr<MockPaymentsProfileComparator> profile_comparator_; 143 std::unique_ptr<MockPaymentsProfileComparator> profile_comparator_;
133 std::unique_ptr<MockTestPaymentRequest> payment_request_; 144 std::unique_ptr<MockTestPaymentRequest> payment_request_;
145 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
please use gerrit instead 2017/07/06 14:52:24 payment_request_ uses chrome_browser_state_, so le
Moe 2017/07/07 02:24:54 You have a point. Done.
134 }; 146 };
135 147
136 // Tests that invoking start and stop on the coordinator presents and dismisses 148 // Tests that invoking start and stop on the coordinator presents and dismisses
137 // the address edit view controller, respectively. 149 // the address edit view controller, respectively.
138 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) { 150 TEST_F(PaymentRequestAddressEditCoordinatorTest, StartAndStop) {
139 UIViewController* base_view_controller = [[UIViewController alloc] init]; 151 UIViewController* base_view_controller = [[UIViewController alloc] init];
140 ScopedKeyWindow scoped_key_window_; 152 ScopedKeyWindow scoped_key_window_;
141 [scoped_key_window_.Get() setRootViewController:base_view_controller]; 153 [scoped_key_window_.Get() setRootViewController:base_view_controller];
142 154
143 AddressEditCoordinator* coordinator = [[AddressEditCoordinator alloc] 155 AddressEditCoordinator* coordinator = [[AddressEditCoordinator alloc]
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 UINavigationController* navigation_controller = 333 UINavigationController* navigation_controller =
322 base::mac::ObjCCastStrict<UINavigationController>( 334 base::mac::ObjCCastStrict<UINavigationController>(
323 base_view_controller.presentedViewController); 335 base_view_controller.presentedViewController);
324 PaymentRequestEditViewController* view_controller = 336 PaymentRequestEditViewController* view_controller =
325 base::mac::ObjCCastStrict<PaymentRequestEditViewController>( 337 base::mac::ObjCCastStrict<PaymentRequestEditViewController>(
326 navigation_controller.visibleViewController); 338 navigation_controller.visibleViewController);
327 [coordinator paymentRequestEditViewControllerDidCancel:view_controller]; 339 [coordinator paymentRequestEditViewControllerDidCancel:view_controller];
328 340
329 EXPECT_OCMOCK_VERIFY(delegate); 341 EXPECT_OCMOCK_VERIFY(delegate);
330 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698