| 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/payment_request_edit_view_controller.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_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 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 9 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
| 10 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" | 10 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" |
| 11 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 11 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
| 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 13 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | 14 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 14 #import "ios/chrome/browser/ui/payments/cells/payments_selector_edit_item.h" | 15 #import "ios/chrome/browser/ui/payments/cells/payments_selector_edit_item.h" |
| 15 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" | 16 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" |
| 16 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller_dat
a_source.h" | 17 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller_dat
a_source.h" |
| 17 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 18 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 @synthesize consumer = _consumer; | 35 @synthesize consumer = _consumer; |
| 35 | 36 |
| 36 - (CollectionViewItem*)headerItem { | 37 - (CollectionViewItem*)headerItem { |
| 37 return [[CollectionViewTextItem alloc] init]; | 38 return [[CollectionViewTextItem alloc] init]; |
| 38 } | 39 } |
| 39 | 40 |
| 40 - (BOOL)shouldHideBackgroundForHeaderItem { | 41 - (BOOL)shouldHideBackgroundForHeaderItem { |
| 41 return NO; | 42 return NO; |
| 42 } | 43 } |
| 43 | 44 |
| 45 - (UIImage*)iconIdentifyingEditorFied:(EditorField*)field { |
| 46 return nil; |
| 47 } |
| 48 |
| 44 - (void)setConsumer:(id<PaymentRequestEditConsumer>)consumer { | 49 - (void)setConsumer:(id<PaymentRequestEditConsumer>)consumer { |
| 45 _consumer = consumer; | 50 _consumer = consumer; |
| 46 [self.consumer setEditorFields:@[ | 51 [self.consumer setEditorFields:@[ |
| 47 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeProfileFullName | 52 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeProfileFullName |
| 48 fieldType:EditorFieldTypeTextField | 53 fieldType:EditorFieldTypeTextField |
| 49 label:@"" | 54 label:@"" |
| 50 value:@"" | 55 value:@"" |
| 51 required:YES], | 56 required:YES], |
| 52 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpYear | 57 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeCreditCardExpYear |
| 53 fieldType:EditorFieldTypeSelector | 58 fieldType:EditorFieldTypeSelector |
| 54 label:@"" | 59 label:@"" |
| 55 value:@"" | 60 value:@"" |
| 56 required:YES], | 61 required:YES], |
| 62 [[EditorField alloc] |
| 63 initWithAutofillUIType:AutofillUITypeCreditCardSaveToChrome |
| 64 fieldType:EditorFieldTypeSwitch |
| 65 label:@"" |
| 66 value:@"YES" |
| 67 required:YES], |
| 57 ]]; | 68 ]]; |
| 58 } | 69 } |
| 59 | 70 |
| 60 @end | 71 @end |
| 61 | 72 |
| 62 class PaymentRequestEditViewControllerTest | 73 class PaymentRequestEditViewControllerTest |
| 63 : public CollectionViewControllerTest { | 74 : public CollectionViewControllerTest { |
| 64 protected: | 75 protected: |
| 65 CollectionViewController* InstantiateController() override { | 76 CollectionViewController* InstantiateController() override { |
| 66 PaymentRequestEditViewController* viewController = | 77 PaymentRequestEditViewController* viewController = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 }; | 92 }; |
| 82 | 93 |
| 83 // Tests that the correct number of items are displayed after loading the model. | 94 // Tests that the correct number of items are displayed after loading the model. |
| 84 TEST_F(PaymentRequestEditViewControllerTest, TestModel) { | 95 TEST_F(PaymentRequestEditViewControllerTest, TestModel) { |
| 85 CreateController(); | 96 CreateController(); |
| 86 CheckController(); | 97 CheckController(); |
| 87 | 98 |
| 88 [GetPaymentRequestEditViewController() loadModel]; | 99 [GetPaymentRequestEditViewController() loadModel]; |
| 89 | 100 |
| 90 // There is one section containing the header item, In addition to that, there | 101 // There is one section containing the header item, In addition to that, there |
| 91 // is one section for every form field (there are two fields in total) and one | 102 // is one section for every form field (there are three fields in total) and |
| 92 // for the footer. | 103 // one for the footer. |
| 93 ASSERT_EQ(4, NumberOfSections()); | 104 ASSERT_EQ(5, NumberOfSections()); |
| 94 | 105 |
| 95 // The header section is the first section and has one item of the type | 106 // The header section is the first section and has one item of the type |
| 96 // CollectionViewTextItem. | 107 // CollectionViewTextItem. |
| 97 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 108 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 98 id item = GetCollectionViewItem(0, 0); | 109 id item = GetCollectionViewItem(0, 0); |
| 99 EXPECT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]); | 110 EXPECT_TRUE([item isMemberOfClass:[CollectionViewTextItem class]]); |
| 100 | 111 |
| 101 // The next section has one item of the type AutofillEditItem. | 112 // The next section has one item of the type AutofillEditItem. |
| 102 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); | 113 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 103 item = GetCollectionViewItem(1, 0); | 114 item = GetCollectionViewItem(1, 0); |
| 104 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); | 115 EXPECT_TRUE([item isMemberOfClass:[AutofillEditItem class]]); |
| 105 | 116 |
| 106 // The next section has one item of the type PaymentsSelectorEditItem. | 117 // The next section has one item of the type PaymentsSelectorEditItem. |
| 107 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); | 118 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); |
| 108 item = GetCollectionViewItem(2, 0); | 119 item = GetCollectionViewItem(2, 0); |
| 109 EXPECT_TRUE([item isMemberOfClass:[PaymentsSelectorEditItem class]]); | 120 EXPECT_TRUE([item isMemberOfClass:[PaymentsSelectorEditItem class]]); |
| 110 | 121 |
| 122 // The next section has one item of the type CollectionViewSwitchItem. |
| 123 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 124 item = GetCollectionViewItem(3, 0); |
| 125 EXPECT_TRUE([item isMemberOfClass:[CollectionViewSwitchItem class]]); |
| 126 |
| 111 // The footer section contains one item which is of the type | 127 // The footer section contains one item which is of the type |
| 112 // CollectionViewFooterItem. | 128 // CollectionViewFooterItem. |
| 113 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); | 129 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 114 item = GetCollectionViewItem(3, 0); | 130 item = GetCollectionViewItem(4, 0); |
| 115 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); | 131 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); |
| 116 } | 132 } |
| OLD | NEW |