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/payments/shipping_address_selection_view_controller.
h" | 5 #import "ios/chrome/browser/payments/shipping_address_selection_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/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 #import "ios/chrome/browser/payments/cells/autofill_profile_item.h" |
12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | 13 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
13 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | |
14 #include "ios/chrome/browser/payments/payment_request.h" | 14 #include "ios/chrome/browser/payments/payment_request.h" |
15 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 15 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
16 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 16 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
17 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | 17 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
18 #include "ios/web/public/payments/payment_request.h" | 18 #include "ios/web/public/payments/payment_request.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
22 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
23 #endif | 23 #endif |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 ASSERT_EQ(1, NumberOfSections()); | 70 ASSERT_EQ(1, NumberOfSections()); |
71 // One item for each of shipping addresses plus 2 for the message and the add | 71 // One item for each of shipping addresses plus 2 for the message and the add |
72 // button. | 72 // button. |
73 ASSERT_EQ(4U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 73 ASSERT_EQ(4U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
74 | 74 |
75 // The first item should be of type TextAndMessageItem. | 75 // The first item should be of type TextAndMessageItem. |
76 id item = GetCollectionViewItem(0, 0); | 76 id item = GetCollectionViewItem(0, 0); |
77 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | 77 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
78 | 78 |
79 // The next two items should be of type ShippingAddressItem. The first one | 79 // The next two items should be of type AutofillProfileItem. The first one |
80 // should appear to be selected. | 80 // should appear to be selected. |
81 item = GetCollectionViewItem(0, 1); | 81 item = GetCollectionViewItem(0, 1); |
82 ASSERT_TRUE([item isMemberOfClass:[ShippingAddressItem class]]); | 82 ASSERT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
83 ShippingAddressItem* shipping_address_item = item; | 83 AutofillProfileItem* shipping_address_item = item; |
84 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, | 84 EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, |
85 shipping_address_item.accessoryType); | 85 shipping_address_item.accessoryType); |
86 | 86 |
87 item = GetCollectionViewItem(0, 2); | 87 item = GetCollectionViewItem(0, 2); |
88 EXPECT_TRUE([item isMemberOfClass:[ShippingAddressItem class]]); | 88 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
89 shipping_address_item = item; | 89 shipping_address_item = item; |
90 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, | 90 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, |
91 shipping_address_item.accessoryType); | 91 shipping_address_item.accessoryType); |
92 | 92 |
93 // The last item should also be of type TextAndMessageItem. | 93 // The last item should also be of type TextAndMessageItem. |
94 item = GetCollectionViewItem(0, 3); | 94 item = GetCollectionViewItem(0, 3); |
95 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | 95 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
96 | 96 |
97 // Test the error state. | 97 // Test the error state. |
98 [GetShippingAddressSelectionViewController() setErrorMessage:@"Lorem ipsum"]; | 98 [GetShippingAddressSelectionViewController() setErrorMessage:@"Lorem ipsum"]; |
99 [GetShippingAddressSelectionViewController() loadModel]; | 99 [GetShippingAddressSelectionViewController() loadModel]; |
100 ASSERT_EQ(1, NumberOfSections()); | 100 ASSERT_EQ(1, NumberOfSections()); |
101 // There should stil be 4 items in total. | 101 // There should stil be 4 items in total. |
102 ASSERT_EQ(4U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 102 ASSERT_EQ(4U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
103 | 103 |
104 // Test the pending state. | 104 // Test the pending state. |
105 [GetShippingAddressSelectionViewController() setPending:YES]; | 105 [GetShippingAddressSelectionViewController() setPending:YES]; |
106 [GetShippingAddressSelectionViewController() loadModel]; | 106 [GetShippingAddressSelectionViewController() loadModel]; |
107 | 107 |
108 ASSERT_EQ(1, NumberOfSections()); | 108 ASSERT_EQ(1, NumberOfSections()); |
109 // There should be only one item. | 109 // There should be only one item. |
110 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 110 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
111 | 111 |
112 // The item should be of type StatusItem. | 112 // The item should be of type StatusItem. |
113 item = GetCollectionViewItem(0, 0); | 113 item = GetCollectionViewItem(0, 0); |
114 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); | 114 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); |
115 } | 115 } |
OLD | NEW |