Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/payment_items_display_view_controller.h" | 5 #import "ios/chrome/browser/ui/payments/payment_items_display_view_controller.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/scoped_task_environment.h" | 9 #include "base/test/scoped_task_environment.h" |
| 10 #include "components/autofill/core/browser/test_personal_data_manager.h" | 10 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | |
| 12 #include "ios/chrome/browser/payments/payment_request.h" | 13 #include "ios/chrome/browser/payments/payment_request.h" |
| 13 #import "ios/chrome/browser/payments/payment_request_test_util.h" | 14 #import "ios/chrome/browser/payments/payment_request_test_util.h" |
| 14 #include "ios/chrome/browser/payments/test_payment_request.h" | 15 #include "ios/chrome/browser/payments/test_payment_request.h" |
| 15 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h " | 16 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h " |
| 16 #import "ios/chrome/browser/ui/payments/cells/price_item.h" | 17 #import "ios/chrome/browser/ui/payments/cells/price_item.h" |
| 17 #import "ios/chrome/browser/ui/payments/payment_items_display_view_controller_da ta_source.h" | 18 #import "ios/chrome/browser/ui/payments/payment_items_display_view_controller_da ta_source.h" |
| 18 #include "ios/chrome/grit/ios_strings.h" | 19 #include "ios/chrome/grit/ios_strings.h" |
| 19 #include "ios/web/public/payments/payment_request.h" | 20 #include "ios/web/public/payments/payment_request.h" |
| 21 #import "ios/web/public/test/fakes/test_web_state.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 23 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 @interface TestPaymentItemsDisplayMediator | 28 @interface TestPaymentItemsDisplayMediator |
| 27 : NSObject<PaymentItemsDisplayViewControllerDataSource> | 29 : NSObject<PaymentItemsDisplayViewControllerDataSource> |
| 28 | 30 |
| 29 @end | 31 @end |
| 30 | 32 |
| 31 @implementation TestPaymentItemsDisplayMediator | 33 @implementation TestPaymentItemsDisplayMediator |
| 32 | 34 |
| 33 #pragma mark - PaymentItemsDisplayViewControllerDataSource | 35 #pragma mark - PaymentItemsDisplayViewControllerDataSource |
| 34 | 36 |
| 35 - (CollectionViewItem*)totalItem { | 37 - (CollectionViewItem*)totalItem { |
| 36 return [[PriceItem alloc] init]; | 38 return [[PriceItem alloc] init]; |
| 37 } | 39 } |
| 38 | 40 |
| 39 - (NSArray<CollectionViewItem*>*)lineItems { | 41 - (NSArray<CollectionViewItem*>*)lineItems { |
| 40 return @[ [[PriceItem alloc] init] ]; | 42 return @[ [[PriceItem alloc] init] ]; |
| 41 } | 43 } |
| 42 | 44 |
| 43 @end | 45 @end |
| 44 | 46 |
| 45 class PaymentRequestPaymentItemsDisplayViewControllerTest | 47 class PaymentRequestPaymentItemsDisplayViewControllerTest |
| 46 : public CollectionViewControllerTest { | 48 : public CollectionViewControllerTest { |
| 47 protected: | 49 protected: |
| 48 CollectionViewController* InstantiateController() override { | 50 CollectionViewController* InstantiateController() override { |
| 51 TestChromeBrowserState::Builder test_cbs_builder; | |
| 52 chrome_browser_state_ = test_cbs_builder.Build(); | |
| 53 | |
| 49 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( | 54 payment_request_ = base::MakeUnique<payments::TestPaymentRequest>( |
| 50 payment_request_test_util::CreateTestWebPaymentRequest(), | 55 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 51 &personal_data_manager_); | 56 chrome_browser_state_.get(), &web_state_, &personal_data_manager_); |
| 52 mediator_ = [[TestPaymentItemsDisplayMediator alloc] init]; | 57 mediator_ = [[TestPaymentItemsDisplayMediator alloc] init]; |
| 53 PaymentItemsDisplayViewController* viewController = [ | 58 PaymentItemsDisplayViewController* viewController = [ |
| 54 [PaymentItemsDisplayViewController alloc] initWithPayButtonEnabled:YES]; | 59 [PaymentItemsDisplayViewController alloc] initWithPayButtonEnabled:YES]; |
| 55 [viewController setDataSource:mediator_]; | 60 [viewController setDataSource:mediator_]; |
| 56 return viewController; | 61 return viewController; |
| 57 } | 62 } |
| 58 | 63 |
| 59 PaymentItemsDisplayViewController* GetPaymentItemsViewController() { | 64 PaymentItemsDisplayViewController* GetPaymentItemsViewController() { |
| 60 return base::mac::ObjCCastStrict<PaymentItemsDisplayViewController>( | 65 return base::mac::ObjCCastStrict<PaymentItemsDisplayViewController>( |
| 61 controller()); | 66 controller()); |
| 62 } | 67 } |
| 63 | 68 |
| 64 base::test::ScopedTaskEnvironment scoped_task_evironment_; | 69 base::test::ScopedTaskEnvironment scoped_task_evironment_; |
| 65 | 70 |
| 71 web::TestWebState web_state_; | |
| 66 autofill::TestPersonalDataManager personal_data_manager_; | 72 autofill::TestPersonalDataManager personal_data_manager_; |
| 67 std::unique_ptr<payments::TestPaymentRequest> payment_request_; | 73 std::unique_ptr<payments::TestPaymentRequest> payment_request_; |
| 74 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | |
|
please use gerrit instead
2017/07/06 14:52:25
Ditto
Moe
2017/07/07 02:24:54
Done.
| |
| 68 TestPaymentItemsDisplayMediator* mediator_ = nil; | 75 TestPaymentItemsDisplayMediator* mediator_ = nil; |
| 69 }; | 76 }; |
| 70 | 77 |
| 71 // Tests that the correct number of items are displayed after loading the model. | 78 // Tests that the correct number of items are displayed after loading the model. |
| 72 TEST_F(PaymentRequestPaymentItemsDisplayViewControllerTest, TestModel) { | 79 TEST_F(PaymentRequestPaymentItemsDisplayViewControllerTest, TestModel) { |
| 73 CreateController(); | 80 CreateController(); |
| 74 CheckController(); | 81 CheckController(); |
| 75 CheckTitleWithId(IDS_PAYMENTS_ORDER_SUMMARY_LABEL); | 82 CheckTitleWithId(IDS_PAYMENTS_ORDER_SUMMARY_LABEL); |
| 76 | 83 |
| 77 [GetPaymentItemsViewController() loadModel]; | 84 [GetPaymentItemsViewController() loadModel]; |
| 78 | 85 |
| 79 ASSERT_EQ(1, NumberOfSections()); | 86 ASSERT_EQ(1, NumberOfSections()); |
| 80 // There should be one item for the total and another one for sub-total. | 87 // There should be one item for the total and another one for sub-total. |
| 81 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 88 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 82 | 89 |
| 83 // They both should be of type PriceItem. | 90 // They both should be of type PriceItem. |
| 84 id item = GetCollectionViewItem(0, 0); | 91 id item = GetCollectionViewItem(0, 0); |
| 85 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); | 92 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); |
| 86 item = GetCollectionViewItem(0, 1); | 93 item = GetCollectionViewItem(0, 1); |
| 87 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); | 94 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); |
| 88 } | 95 } |
| OLD | NEW |