| 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/payment_request_view_controller.h" | 5 #import "ios/chrome/browser/payments/payment_request_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 "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/autofill/core/browser/autofill_test_utils.h" | 10 #include "components/autofill/core/browser/autofill_test_utils.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 #import "ios/chrome/browser/payments/cells/autofill_profile_item.h" |
| 13 #import "ios/chrome/browser/payments/cells/page_info_item.h" | 14 #import "ios/chrome/browser/payments/cells/page_info_item.h" |
| 14 #import "ios/chrome/browser/payments/cells/payment_method_item.h" | 15 #import "ios/chrome/browser/payments/cells/payment_method_item.h" |
| 15 #import "ios/chrome/browser/payments/cells/price_item.h" | 16 #import "ios/chrome/browser/payments/cells/price_item.h" |
| 16 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | |
| 17 #include "ios/chrome/browser/payments/payment_request.h" | 17 #include "ios/chrome/browser/payments/payment_request.h" |
| 18 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 18 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 19 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 19 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
| 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
| 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 21 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 22 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | 22 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 23 #include "ios/chrome/grit/ios_strings.h" | 23 #include "ios/chrome/grit/ios_strings.h" |
| 24 #include "ios/web/public/payments/payment_request.h" | 24 #include "ios/web/public/payments/payment_request.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 // Tests that the correct items are displayed after loading the model. | 67 // Tests that the correct items are displayed after loading the model. |
| 68 TEST_F(PaymentRequestViewControllerTest, TestModel) { | 68 TEST_F(PaymentRequestViewControllerTest, TestModel) { |
| 69 CreateController(); | 69 CreateController(); |
| 70 CheckController(); | 70 CheckController(); |
| 71 CheckTitleWithId(IDS_IOS_PAYMENT_REQUEST_TITLE); | 71 CheckTitleWithId(IDS_IOS_PAYMENT_REQUEST_TITLE); |
| 72 | 72 |
| 73 [GetPaymentRequestViewController() loadModel]; | 73 [GetPaymentRequestViewController() loadModel]; |
| 74 | 74 |
| 75 // There should be three sections in total. Summary, Shipping, and Payment. | 75 // There should be three sections in total. Summary, Shipping, and Payment. |
| 76 ASSERT_EQ(3, NumberOfSections()); | 76 ASSERT_EQ(4, NumberOfSections()); |
| 77 | 77 |
| 78 // The only item in the Summary section should be of type PriceItem. | 78 // The only item in the Summary section should be of type PriceItem. |
| 79 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 79 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 80 id item = GetCollectionViewItem(0, 0); | 80 id item = GetCollectionViewItem(0, 0); |
| 81 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); | 81 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); |
| 82 PriceItem* price_item = item; | 82 PriceItem* price_item = item; |
| 83 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | 83 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, |
| 84 price_item.accessoryType); | 84 price_item.accessoryType); |
| 85 | 85 |
| 86 // There should be two items in the Shipping section. | 86 // There should be two items in the Shipping section. |
| 87 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); | 87 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 88 | 88 |
| 89 // The first one should be of type ShippingAddressItem. | 89 // The first one should be of type AutofillProfileItem. |
| 90 item = GetCollectionViewItem(1, 0); | 90 item = GetCollectionViewItem(1, 0); |
| 91 EXPECT_TRUE([item isMemberOfClass:[ShippingAddressItem class]]); | 91 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 92 ShippingAddressItem* shipping_address_item = item; | 92 AutofillProfileItem* shipping_address_item = item; |
| 93 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | 93 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, |
| 94 shipping_address_item.accessoryType); | 94 shipping_address_item.accessoryType); |
| 95 | 95 |
| 96 // The next item should be of type CollectionViewTextItem. | 96 // The next item should be of type CollectionViewTextItem. |
| 97 item = GetCollectionViewItem(1, 1); | 97 item = GetCollectionViewItem(1, 1); |
| 98 EXPECT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]); | 98 EXPECT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]); |
| 99 CollectionViewTextItem* shipping_option_item = item; | 99 CollectionViewTextItem* shipping_option_item = item; |
| 100 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | 100 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, |
| 101 shipping_option_item.accessoryType); | 101 shipping_option_item.accessoryType); |
| 102 | 102 |
| 103 // The only item in the Payment section should be of type PaymentMethodItem. | 103 // The only item in the Payment section should be of type PaymentMethodItem. |
| 104 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); | 104 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); |
| 105 item = GetCollectionViewItem(2, 0); | 105 item = GetCollectionViewItem(2, 0); |
| 106 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); | 106 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); |
| 107 |
| 108 // The only item in the Contact info section should be of type |
| 109 // AutofillProfileItem. |
| 110 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 111 item = GetCollectionViewItem(3, 0); |
| 112 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 107 } | 113 } |
| 108 | 114 |
| 109 // Tests that the correct items are displayed after loading the model, when | 115 // Tests that the correct items are displayed after loading the model, when |
| 110 // there are no display items. | 116 // there are no display items. |
| 111 TEST_F(PaymentRequestViewControllerTest, TestModelNoDisplayItem) { | 117 TEST_F(PaymentRequestViewControllerTest, TestModelNoDisplayItem) { |
| 112 CreateController(); | 118 CreateController(); |
| 113 CheckController(); | 119 CheckController(); |
| 114 | 120 |
| 115 payment_request_->set_payment_details(web::PaymentDetails()); | 121 payment_request_->set_payment_details(web::PaymentDetails()); |
| 116 [GetPaymentRequestViewController() loadModel]; | 122 [GetPaymentRequestViewController() loadModel]; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 [GetPaymentRequestViewController() loadModel]; | 198 [GetPaymentRequestViewController() loadModel]; |
| 193 | 199 |
| 194 ASSERT_EQ(1, NumberOfSections()); | 200 ASSERT_EQ(1, NumberOfSections()); |
| 195 // There should be only one item. | 201 // There should be only one item. |
| 196 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 202 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 197 | 203 |
| 198 // The item should be of type StatusItem. | 204 // The item should be of type StatusItem. |
| 199 id item = GetCollectionViewItem(0, 0); | 205 id item = GetCollectionViewItem(0, 0); |
| 200 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); | 206 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); |
| 201 } | 207 } |
| OLD | NEW |