Chromium Code Reviews| 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/credit_card_edit_view_controller.h" | 5 #import "ios/chrome/browser/ui/payments/credit_card_edit_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/field_types.h" | 9 #include "components/autofill/core/browser/field_types.h" |
| 10 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 10 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 11 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 11 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
| 12 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" | 12 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" |
| 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" | |
| 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" |
| 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" | 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" |
| 16 #import "ios/chrome/browser/ui/collection_view/cells/test_utils.h" | 15 #import "ios/chrome/browser/ui/collection_view/cells/test_utils.h" |
| 17 #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 " |
| 18 #import "ios/chrome/browser/ui/payments/cells/accepted_payment_methods_item.h" | 17 #import "ios/chrome/browser/ui/payments/cells/accepted_payment_methods_item.h" |
| 19 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" | 18 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" |
| 19 #import "ios/chrome/browser/ui/payments/cells/payments_selector_edit_item.h" | |
| 20 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 20 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 21 #include "ios/web/public/payments/payment_request.h" | 21 #include "ios/web/public/payments/payment_request.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 @interface TestCreditCardEditViewControllerMediator | 28 @interface TestCreditCardEditViewControllerMediator |
| 29 : NSObject<CreditCardEditViewControllerDataSource> | 29 : NSObject<CreditCardEditViewControllerDataSource> |
| 30 | 30 |
| 31 @end | 31 @end |
| 32 | 32 |
| 33 @implementation TestCreditCardEditViewControllerMediator | 33 @implementation TestCreditCardEditViewControllerMediator |
| 34 | 34 |
| 35 @synthesize state = _state; | 35 @synthesize state = _state; |
| 36 | 36 |
| 37 - (CollectionViewItem*)serverCardSummaryItem { | 37 - (CollectionViewItem*)headerItem { |
| 38 return [[PaymentMethodItem alloc] init]; | 38 return [[PaymentMethodItem alloc] init]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 - (CollectionViewItem*)acceptedPaymentMethodsItem { | 41 - (BOOL)shouldHideBackgroundForHeaderItem { |
| 42 return [[AcceptedPaymentMethodsItem alloc] init]; | 42 return NO; |
| 43 } | 43 } |
| 44 | 44 |
| 45 - (NSArray<EditorField*>*)editorFields { | 45 - (NSArray<EditorField*>*)editorFields { |
| 46 return @[ | 46 return @[ |
| 47 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardNumber | 47 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardNumber |
| 48 fieldType:EditorFieldTypeTextField | |
| 48 label:@"Credit Card Number" | 49 label:@"Credit Card Number" |
| 49 value:@"4111111111111111" /* Visa */ | 50 value:@"4111111111111111" /* Visa */ |
| 50 required:YES], | 51 required:YES], |
| 51 [[EditorField alloc] | 52 [[EditorField alloc] |
| 52 initWithAutofillUIType:AutofillUITypeCreditCardHolderFullName | 53 initWithAutofillUIType:AutofillUITypeCreditCardHolderFullName |
| 54 fieldType:EditorFieldTypeTextField | |
| 53 label:@"Cardholder Name" | 55 label:@"Cardholder Name" |
| 54 value:@"John Doe" | 56 value:@"John Doe" |
| 55 required:YES], | 57 required:YES], |
| 56 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpMonth | 58 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpMonth |
| 59 fieldType:EditorFieldTypeTextField | |
| 57 label:@"Expiration Month" | 60 label:@"Expiration Month" |
| 58 value:@"12" | 61 value:@"12" |
| 59 required:YES], | 62 required:YES], |
| 60 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpYear | 63 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpYear |
| 64 fieldType:EditorFieldTypeTextField | |
| 61 label:@"Expiration Year" | 65 label:@"Expiration Year" |
| 62 value:@"2090" | 66 value:@"2090" |
| 63 required:YES], | 67 required:YES], |
| 68 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpYear | |
|
macourteau
2017/05/11 18:59:40
ExpYear?
Moe
2017/05/11 19:39:38
Done.
| |
| 69 fieldType:EditorFieldTypeSelector | |
| 70 label:@"Billing Address" | |
| 71 value:@"12345" | |
| 72 required:YES], | |
| 64 ]; | 73 ]; |
| 65 } | 74 } |
| 66 | 75 |
| 67 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { | |
| 68 return nil; | |
| 69 } | |
| 70 | |
| 71 - (UIImage*)cardTypeIconFromCardNumber:(NSString*)cardNumber { | 76 - (UIImage*)cardTypeIconFromCardNumber:(NSString*)cardNumber { |
| 72 return nil; | 77 return nil; |
| 73 } | 78 } |
| 74 | 79 |
| 75 @end | 80 @end |
| 76 | 81 |
| 77 class PaymentRequestCreditCardEditViewControllerTest | 82 class PaymentRequestCreditCardEditViewControllerTest |
| 78 : public CollectionViewControllerTest { | 83 : public CollectionViewControllerTest { |
| 79 protected: | 84 protected: |
| 80 CollectionViewController* InstantiateController() override { | 85 CollectionViewController* InstantiateController() override { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 92 } | 97 } |
| 93 | 98 |
| 94 TestCreditCardEditViewControllerMediator* mediator_ = nil; | 99 TestCreditCardEditViewControllerMediator* mediator_ = nil; |
| 95 }; | 100 }; |
| 96 | 101 |
| 97 // Tests that the correct number of items are displayed after loading the model. | 102 // Tests that the correct number of items are displayed after loading the model. |
| 98 TEST_F(PaymentRequestCreditCardEditViewControllerTest, TestModel) { | 103 TEST_F(PaymentRequestCreditCardEditViewControllerTest, TestModel) { |
| 99 CreateController(); | 104 CreateController(); |
| 100 CheckController(); | 105 CheckController(); |
| 101 | 106 |
| 102 [mediator_ setState:CreditCardEditViewControllerStateEdit]; | 107 [mediator_ setState:EditViewControllerStateEdit]; |
| 103 [GetCreditCardEditViewController() loadModel]; | 108 [GetCreditCardEditViewController() loadModel]; |
| 104 | 109 |
| 105 // There is one section containing the credit card type icons for the accepted | 110 // There is one section containing the credit card type icons for the accepted |
| 106 // payment methods. In addition to that, there is one section for every | 111 // payment methods. In addition to that, there is one section for every |
| 107 // textfield (there are four textfields in total), one for the server card | 112 // textfield (there are four textfields in total), one for the server card |
| 108 // summary section, one for the footer, and one for the billing address ID | 113 // summary section, one for the footer, and one for the billing address ID |
| 109 // item. | 114 // item. |
| 110 ASSERT_EQ(8, NumberOfSections()); | 115 ASSERT_EQ(7, NumberOfSections()); |
|
macourteau
2017/05/11 18:59:40
Please update comment, which describes 8 sections
Moe
2017/05/11 19:39:38
Done.
| |
| 111 | 116 |
| 112 // The server card summary section is the first section and has one item of | 117 // The server card summary section is the first section and has one item of |
| 113 // the type PaymentMethodItem. | 118 // the type PaymentMethodItem. |
| 114 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 119 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 115 id item = GetCollectionViewItem(0, 0); | 120 id item = GetCollectionViewItem(0, 0); |
| 116 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); | 121 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); |
| 117 | 122 |
| 118 // The next section is the accepted payment methods section and has one item | 123 // The next four sections have only one item of the type AutofillEditItem. |
| 119 // of the type AcceptedPaymentMethodsItem. | |
| 120 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); | 124 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 121 item = GetCollectionViewItem(1, 0); | 125 item = GetCollectionViewItem(1, 0); |
| 122 EXPECT_TRUE([item isMemberOfClass:[AcceptedPaymentMethodsItem class]]); | 126 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); |
| 123 | 127 |
| 124 // The next four sections have only one item of the type AutofillEditItem. | |
| 125 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); | 128 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); |
| 126 item = GetCollectionViewItem(2, 0); | 129 item = GetCollectionViewItem(2, 0); |
| 127 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); | 130 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); |
| 128 | 131 |
| 129 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); | 132 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 130 item = GetCollectionViewItem(3, 0); | 133 item = GetCollectionViewItem(3, 0); |
| 131 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); | 134 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); |
| 132 | 135 |
| 133 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(4))); | 136 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(4))); |
| 134 item = GetCollectionViewItem(4, 0); | 137 item = GetCollectionViewItem(4, 0); |
| 135 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); | 138 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); |
| 136 | 139 |
| 140 // The billing address section contains one item which is of the type | |
| 141 // PaymentsSelectorEditItem. | |
| 137 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(5))); | 142 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(5))); |
| 138 item = GetCollectionViewItem(5, 0); | 143 item = GetCollectionViewItem(5, 0); |
| 139 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); | 144 EXPECT_TRUE([item isMemberOfClass:[PaymentsSelectorEditItem class]]); |
| 140 | 145 PaymentsSelectorEditItem* billing_address_item = item; |
| 141 // The billing address section contains one item which is of the type | |
| 142 // CollectionViewDetailItem. | |
| 143 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(6))); | |
| 144 item = GetCollectionViewItem(6, 0); | |
| 145 EXPECT_TRUE([item isMemberOfClass:[CollectionViewDetailItem class]]); | |
| 146 CollectionViewDetailItem* billing_address_item = item; | |
| 147 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | 146 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, |
| 148 billing_address_item.accessoryType); | 147 billing_address_item.accessoryType); |
| 149 | 148 |
| 150 // The footer section contains one item which is of the type | 149 // The footer section contains one item which is of the type |
| 151 // CollectionViewFooterItem. | 150 // CollectionViewFooterItem. |
| 152 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(7))); | 151 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(6))); |
| 153 item = GetCollectionViewItem(7, 0); | 152 item = GetCollectionViewItem(6, 0); |
| 154 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); | 153 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); |
| 155 } | 154 } |
| 156 | 155 |
| 157 // Tests that the correct number of items are displayed after loading the model, | 156 // Tests that the correct number of items are displayed after loading the model, |
| 158 // when creating a new credit card. | 157 // when creating a new credit card. |
| 159 TEST_F(PaymentRequestCreditCardEditViewControllerTest, | 158 TEST_F(PaymentRequestCreditCardEditViewControllerTest, |
| 160 TestModelCreateNewCreditCard) { | 159 TestModelCreateNewCreditCard) { |
| 161 CreateController(); | 160 CreateController(); |
| 162 CheckController(); | 161 CheckController(); |
| 163 | 162 |
| 164 [mediator_ setState:CreditCardEditViewControllerStateCreate]; | 163 [mediator_ setState:EditViewControllerStateCreate]; |
| 165 [GetCreditCardEditViewController() loadModel]; | 164 [GetCreditCardEditViewController() loadModel]; |
| 166 | 165 |
| 167 // There is an extra section containing a switch that allows the user to save | 166 // There is an extra section containing a switch that allows the user to save |
| 168 // the credit card locally. | 167 // the credit card locally. |
| 169 ASSERT_EQ(9, NumberOfSections()); | 168 ASSERT_EQ(8, NumberOfSections()); |
| 170 | 169 |
| 171 // The switch section is the last section before the footer and has one item | 170 // The switch section is the last section before the footer and has one item |
| 172 // of the type CollectionViewSwitchItem. The switch is on by defualt. | 171 // of the type CollectionViewSwitchItem. The switch is on by defualt. |
| 173 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(7))); | 172 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(6))); |
| 174 id item = GetCollectionViewItem(7, 0); | 173 id item = GetCollectionViewItem(6, 0); |
| 175 EXPECT_TRUE([item isMemberOfClass:[CollectionViewSwitchItem class]]); | 174 EXPECT_TRUE([item isMemberOfClass:[CollectionViewSwitchItem class]]); |
| 176 CollectionViewSwitchItem* switch_item = item; | 175 CollectionViewSwitchItem* switch_item = item; |
| 177 EXPECT_EQ(YES, [switch_item isOn]); | 176 EXPECT_EQ(YES, [switch_item isOn]); |
| 178 } | 177 } |
| OLD | NEW |