| 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_view_controller.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_view_controller.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> |
| 8 |
| 7 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
| 11 #include "components/autofill/core/browser/autofill_test_utils.h" | 13 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 12 #include "components/autofill/core/browser/credit_card.h" | 14 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/autofill/core/browser/test_personal_data_manager.h" | 15 #include "components/autofill/core/browser/test_personal_data_manager.h" |
| 14 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 15 #include "ios/chrome/browser/payments/payment_request.h" | |
| 16 #include "ios/chrome/browser/payments/payment_request_test_util.h" | 17 #include "ios/chrome/browser/payments/payment_request_test_util.h" |
| 18 #include "ios/chrome/browser/payments/test_payment_request.h" |
| 17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 19 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
| 18 #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_footer_item
.h" |
| 19 #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
" |
| 20 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h" | 23 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h" |
| 21 #import "ios/chrome/browser/ui/payments/cells/page_info_item.h" | 24 #import "ios/chrome/browser/ui/payments/cells/page_info_item.h" |
| 22 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" | 25 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" |
| 23 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h" | 26 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h" |
| 24 #import "ios/chrome/browser/ui/payments/cells/price_item.h" | 27 #import "ios/chrome/browser/ui/payments/cells/price_item.h" |
| 28 #import "ios/chrome/browser/ui/payments/payment_request_view_controller_data_sou
rce.h" |
| 25 #include "ios/chrome/grit/ios_strings.h" | 29 #include "ios/chrome/grit/ios_strings.h" |
| 26 #include "ios/web/public/payments/payment_request.h" | 30 #include "ios/web/public/payments/payment_request.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 29 | 33 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) | 34 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." | 35 #error "This file requires ARC support." |
| 32 #endif | 36 #endif |
| 33 | 37 |
| 38 @interface TestPaymentRequestMediator |
| 39 : NSObject<PaymentRequestViewControllerDataSource> |
| 40 |
| 41 @end |
| 42 |
| 43 @implementation TestPaymentRequestMediator |
| 44 |
| 45 - (BOOL)canPay { |
| 46 return YES; |
| 47 } |
| 48 |
| 49 - (BOOL)canShip { |
| 50 return YES; |
| 51 } |
| 52 |
| 53 - (BOOL)hasPaymentItems { |
| 54 return YES; |
| 55 } |
| 56 |
| 57 - (BOOL)requestShipping { |
| 58 return YES; |
| 59 } |
| 60 |
| 61 - (BOOL)requestContactInfo { |
| 62 return YES; |
| 63 } |
| 64 |
| 65 - (CollectionViewItem*)paymentSummaryItem { |
| 66 return [[PriceItem alloc] init]; |
| 67 } |
| 68 |
| 69 - (CollectionViewItem*)shippingSectionHeaderItem { |
| 70 return [[PaymentsTextItem alloc] init]; |
| 71 } |
| 72 |
| 73 - (CollectionViewItem*)shippingAddressItem { |
| 74 return [[AutofillProfileItem alloc] init]; |
| 75 } |
| 76 |
| 77 - (CollectionViewItem*)shippingOptionItem { |
| 78 return [[PaymentsTextItem alloc] init]; |
| 79 } |
| 80 |
| 81 - (CollectionViewItem*)paymentMethodSectionHeaderItem { |
| 82 return [[PaymentsTextItem alloc] init]; |
| 83 } |
| 84 |
| 85 - (CollectionViewItem*)paymentMethodItem { |
| 86 return [[PaymentMethodItem alloc] init]; |
| 87 } |
| 88 |
| 89 - (CollectionViewItem*)contactInfoSectionHeaderItem { |
| 90 return [[PaymentsTextItem alloc] init]; |
| 91 } |
| 92 |
| 93 - (CollectionViewItem*)contactInfoItem { |
| 94 return [[AutofillProfileItem alloc] init]; |
| 95 } |
| 96 |
| 97 - (CollectionViewFooterItem*)footerItem { |
| 98 return [[CollectionViewFooterItem alloc] init]; |
| 99 } |
| 100 |
| 101 @end |
| 102 |
| 103 @interface TestPaymentRequestMediatorNoShipping : TestPaymentRequestMediator |
| 104 |
| 105 @end |
| 106 |
| 107 @implementation TestPaymentRequestMediatorNoShipping |
| 108 |
| 109 - (BOOL)requestShipping { |
| 110 return NO; |
| 111 } |
| 112 |
| 113 @end |
| 114 |
| 115 @interface TestPaymentRequestMediatorNoContactInfo : TestPaymentRequestMediator |
| 116 |
| 117 @end |
| 118 |
| 119 @implementation TestPaymentRequestMediatorNoContactInfo |
| 120 |
| 121 - (BOOL)requestContactInfo { |
| 122 return NO; |
| 123 } |
| 124 |
| 125 @end |
| 126 |
| 127 @interface TestPaymentRequestMediatorCantShip : TestPaymentRequestMediator |
| 128 |
| 129 @end |
| 130 |
| 131 @implementation TestPaymentRequestMediatorCantShip |
| 132 |
| 133 - (BOOL)canShip { |
| 134 return NO; |
| 135 } |
| 136 |
| 137 @end |
| 138 |
| 34 class PaymentRequestViewControllerTest : public CollectionViewControllerTest { | 139 class PaymentRequestViewControllerTest : public CollectionViewControllerTest { |
| 35 protected: | 140 protected: |
| 36 PaymentRequestViewControllerTest() | 141 PaymentRequestViewControllerTest() |
| 37 : autofill_profile_(autofill::test::GetFullProfile()), | 142 : autofill_profile_(autofill::test::GetFullProfile()), |
| 38 credit_card_(autofill::test::GetCreditCard()) { | 143 credit_card_(autofill::test::GetCreditCard()) { |
| 39 // Add testing profile and credit card to autofill::TestPersonalDataManager. | 144 // Add testing profile and credit card to autofill::TestPersonalDataManager. |
| 40 personal_data_manager_.AddTestingProfile(&autofill_profile_); | 145 personal_data_manager_.AddTestingProfile(&autofill_profile_); |
| 41 personal_data_manager_.AddTestingCreditCard(&credit_card_); | 146 personal_data_manager_.AddTestingCreditCard(&credit_card_); |
| 147 |
| 148 payment_request_ = base::MakeUnique<TestPaymentRequest>( |
| 149 payment_request_test_util::CreateTestWebPaymentRequest(), |
| 150 &personal_data_manager_); |
| 151 |
| 152 mediator_ = [[TestPaymentRequestMediator alloc] init]; |
| 42 } | 153 } |
| 43 | 154 |
| 44 CollectionViewController* InstantiateController() override { | 155 CollectionViewController* InstantiateController() override { |
| 45 payment_request_ = base::MakeUnique<PaymentRequest>( | 156 PaymentRequestViewController* viewController = |
| 46 payment_request_test_util::CreateTestWebPaymentRequest(), | 157 [[PaymentRequestViewController alloc] init]; |
| 47 &personal_data_manager_); | 158 [viewController setDataSource:mediator_]; |
| 48 | 159 return viewController; |
| 49 return [[PaymentRequestViewController alloc] | |
| 50 initWithPaymentRequest:payment_request_.get()]; | |
| 51 } | 160 } |
| 52 | 161 |
| 53 PaymentRequestViewController* GetPaymentRequestViewController() { | 162 PaymentRequestViewController* GetPaymentRequestViewController() { |
| 54 return base::mac::ObjCCastStrict<PaymentRequestViewController>( | 163 return base::mac::ObjCCastStrict<PaymentRequestViewController>( |
| 55 controller()); | 164 controller()); |
| 56 } | 165 } |
| 57 | 166 |
| 58 autofill::AutofillProfile autofill_profile_; | 167 autofill::AutofillProfile autofill_profile_; |
| 59 autofill::CreditCard credit_card_; | 168 autofill::CreditCard credit_card_; |
| 60 autofill::TestPersonalDataManager personal_data_manager_; | 169 autofill::TestPersonalDataManager personal_data_manager_; |
| 61 std::unique_ptr<PaymentRequest> payment_request_; | 170 std::unique_ptr<TestPaymentRequest> payment_request_; |
| 171 TestPaymentRequestMediator* mediator_; |
| 62 }; | 172 }; |
| 63 | 173 |
| 64 // Tests that the correct items are displayed after loading the model. | 174 // Tests that the correct items are displayed after loading the model. |
| 65 TEST_F(PaymentRequestViewControllerTest, TestModel) { | 175 TEST_F(PaymentRequestViewControllerTest, TestModel) { |
| 66 CreateController(); | 176 CreateController(); |
| 67 CheckController(); | 177 CheckController(); |
| 68 CheckTitleWithId(IDS_PAYMENTS_TITLE); | 178 CheckTitleWithId(IDS_PAYMENTS_TITLE); |
| 69 | 179 |
| 70 [GetPaymentRequestViewController() loadModel]; | 180 [GetPaymentRequestViewController() loadModel]; |
| 71 | 181 |
| 72 // There should be five sections in total. Summary, Shipping, Payment, | 182 // There should be five sections in total. Summary, Shipping, Payment Method, |
| 73 // Contact info and a footer. | 183 // Contact Info and the Footer. |
| 74 ASSERT_EQ(5, NumberOfSections()); | 184 ASSERT_EQ(5, NumberOfSections()); |
| 75 | 185 |
| 76 // The only item in the Summary section should be of type PriceItem. | 186 // The only item in the Summary section should be of type PriceItem. |
| 77 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 187 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 78 id item = GetCollectionViewItem(0, 0); | 188 id item = GetCollectionViewItem(0, 0); |
| 79 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); | 189 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); |
| 80 PriceItem* price_item = item; | |
| 81 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | |
| 82 price_item.accessoryType); | |
| 83 | 190 |
| 84 // There should be two items in the Shipping section. | 191 // There should be two items in the Shipping section. |
| 85 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); | 192 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 86 | 193 |
| 87 // The first one should be of type AutofillProfileItem. | 194 // The first one should be of type AutofillProfileItem. |
| 88 item = GetCollectionViewItem(1, 0); | 195 item = GetCollectionViewItem(1, 0); |
| 89 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); | 196 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 90 AutofillProfileItem* shipping_address_item = item; | |
| 91 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | |
| 92 shipping_address_item.accessoryType); | |
| 93 | 197 |
| 94 // The next item should be of type PaymentsTextItem. | 198 // The next item should be of type PaymentsTextItem. |
| 95 item = GetCollectionViewItem(1, 1); | 199 item = GetCollectionViewItem(1, 1); |
| 96 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); | 200 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
| 97 PaymentsTextItem* shipping_option_item = item; | |
| 98 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | |
| 99 shipping_option_item.accessoryType); | |
| 100 | 201 |
| 101 // The only item in the Payment section should be of type PaymentMethodItem. | 202 // The only item in the Payment Method section should be of type |
| 203 // PaymentMethodItem. |
| 102 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); | 204 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); |
| 103 item = GetCollectionViewItem(2, 0); | 205 item = GetCollectionViewItem(2, 0); |
| 104 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); | 206 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); |
| 105 | 207 |
| 106 // The only item in the Contact info section should be of type | 208 // The only item in the Contact Info section should be of type |
| 107 // AutofillProfileItem. | 209 // AutofillProfileItem. |
| 108 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); | 210 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 109 item = GetCollectionViewItem(3, 0); | 211 item = GetCollectionViewItem(3, 0); |
| 110 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); | 212 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 213 |
| 214 // The only item in the Footer section should be of type |
| 215 // CollectionViewFooterItem. |
| 216 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(4))); |
| 217 item = GetCollectionViewItem(4, 0); |
| 218 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); |
| 219 } |
| 220 |
| 221 // Tests that the correct items are displayed after loading the model, when no |
| 222 // shipping information is requested. |
| 223 TEST_F(PaymentRequestViewControllerTest, TestModelNoShipping) { |
| 224 mediator_ = [[TestPaymentRequestMediatorNoShipping alloc] init]; |
| 225 |
| 226 CreateController(); |
| 227 CheckController(); |
| 228 |
| 229 // There should be four sections in total now. |
| 230 ASSERT_EQ(4, NumberOfSections()); |
| 231 |
| 232 // The second section is the Payment Method section isntead of the Shipping |
| 233 // section. |
| 234 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 235 CollectionViewItem* item = GetCollectionViewItem(1, 0); |
| 236 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); |
| 237 } |
| 238 |
| 239 // Tests that the correct items are displayed after loading the model, when no |
| 240 // contact information is requested. |
| 241 TEST_F(PaymentRequestViewControllerTest, TestModelNoContactInfo) { |
| 242 mediator_ = [[TestPaymentRequestMediatorNoContactInfo alloc] init]; |
| 243 |
| 244 CreateController(); |
| 245 CheckController(); |
| 246 |
| 247 // There should be four sections in total now. |
| 248 ASSERT_EQ(4, NumberOfSections()); |
| 249 |
| 250 // The fourth section is the Footer section instead of the Contact Info |
| 251 // section. |
| 252 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 253 CollectionViewItem* item = GetCollectionViewItem(3, 0); |
| 254 EXPECT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); |
| 111 } | 255 } |
| 112 | 256 |
| 113 // Tests that the correct items are displayed after loading the model, when | 257 // Tests that the correct items are displayed after loading the model, when |
| 114 // there are no display items. | 258 // shipping can't be made. |
| 115 TEST_F(PaymentRequestViewControllerTest, TestModelNoDisplayItem) { | 259 TEST_F(PaymentRequestViewControllerTest, TestModelCantShip) { |
| 260 mediator_ = [[TestPaymentRequestMediatorCantShip alloc] init]; |
| 261 |
| 116 CreateController(); | 262 CreateController(); |
| 117 CheckController(); | 263 CheckController(); |
| 118 | 264 |
| 119 payment_request_->UpdatePaymentDetails(web::PaymentDetails()); | 265 // There should only be one item in the Shipping section and it should be of |
| 120 [GetPaymentRequestViewController() loadModel]; | 266 // type AutofillProfileItem. |
| 267 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 268 id item = GetCollectionViewItem(1, 0); |
| 269 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 270 } |
| 121 | 271 |
| 122 // The only item in the Summary section should stil be of type PriceItem, but | 272 // Tests that the correct items are displayed after updating the Shipping |
| 123 // without an accessory view. | 273 // section. |
| 124 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 274 TEST_F(PaymentRequestViewControllerTest, TestUpdateShippingSection) { |
| 125 id item = GetCollectionViewItem(0, 0); | 275 CreateController(); |
| 126 EXPECT_TRUE([item isMemberOfClass:[PriceItem class]]); | 276 CheckController(); |
| 127 PriceItem* price_item = item; | 277 |
| 128 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, price_item.accessoryType); | 278 [GetPaymentRequestViewController() updateShippingSection]; |
| 279 |
| 280 // There should be two items in the Shipping section. |
| 281 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); |
| 282 |
| 283 // The first one should be of type AutofillProfileItem. |
| 284 id item = GetCollectionViewItem(1, 0); |
| 285 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 286 |
| 287 // The next item should be of type PaymentsTextItem. |
| 288 item = GetCollectionViewItem(1, 1); |
| 289 EXPECT_TRUE([item isMemberOfClass:[PaymentsTextItem class]]); |
| 290 } |
| 291 |
| 292 // Tests that the correct items are displayed after updating the Payment Method |
| 293 // section. |
| 294 TEST_F(PaymentRequestViewControllerTest, TestUpdatePaymentMethodSection) { |
| 295 CreateController(); |
| 296 CheckController(); |
| 297 |
| 298 [GetPaymentRequestViewController() updatePaymentMethodSection]; |
| 299 |
| 300 // The only item in the Payment Method section should be of type |
| 301 // PaymentMethodItem. |
| 302 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); |
| 303 id item = GetCollectionViewItem(2, 0); |
| 304 EXPECT_TRUE([item isMemberOfClass:[PaymentMethodItem class]]); |
| 305 } |
| 306 |
| 307 // Tests that the correct items are displayed after updating the Contact Info |
| 308 // section. |
| 309 TEST_F(PaymentRequestViewControllerTest, TestUpdateContactInfoSection) { |
| 310 CreateController(); |
| 311 CheckController(); |
| 312 |
| 313 [GetPaymentRequestViewController() updatePaymentMethodSection]; |
| 314 |
| 315 // The only item in the Contact Info section should be of type |
| 316 // AutofillProfileItem. |
| 317 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(3))); |
| 318 id item = GetCollectionViewItem(3, 0); |
| 319 EXPECT_TRUE([item isMemberOfClass:[AutofillProfileItem class]]); |
| 129 } | 320 } |
| 130 | 321 |
| 131 // Tests that the correct items are displayed after loading the model, when | 322 // Tests that the correct items are displayed after loading the model, when |
| 132 // there is no selected shipping addresse. | |
| 133 TEST_F(PaymentRequestViewControllerTest, TestModelNoSelectedShippingAddress) { | |
| 134 CreateController(); | |
| 135 CheckController(); | |
| 136 | |
| 137 payment_request_->set_selected_shipping_profile(nullptr); | |
| 138 [GetPaymentRequestViewController() loadModel]; | |
| 139 | |
| 140 // There should still be two items in the Shipping section. | |
| 141 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); | |
| 142 | |
| 143 // The first one should be of type CollectionViewDetailItem. | |
| 144 id item = GetCollectionViewItem(1, 0); | |
| 145 EXPECT_TRUE([item isMemberOfClass:[CollectionViewDetailItem class]]); | |
| 146 CollectionViewDetailItem* detail_item = item; | |
| 147 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, detail_item.accessoryType); | |
| 148 } | |
| 149 | |
| 150 // Tests that the correct items are displayed after loading the model, when | |
| 151 // there is no selected shipping option. | |
| 152 TEST_F(PaymentRequestViewControllerTest, TestModelNoSelectedShippingOption) { | |
| 153 CreateController(); | |
| 154 CheckController(); | |
| 155 | |
| 156 // Resetting the payment details should reset the selected shipping option. | |
| 157 payment_request_->UpdatePaymentDetails(web::PaymentDetails()); | |
| 158 [GetPaymentRequestViewController() loadModel]; | |
| 159 | |
| 160 // There should still be two items in the Shipping section. | |
| 161 ASSERT_EQ(2U, static_cast<unsigned int>(NumberOfItemsInSection(1))); | |
| 162 | |
| 163 // The second one should be of type CollectionViewDetailItem. | |
| 164 id item = GetCollectionViewItem(1, 1); | |
| 165 EXPECT_TRUE([item isMemberOfClass:[CollectionViewDetailItem class]]); | |
| 166 CollectionViewDetailItem* detail_item = item; | |
| 167 EXPECT_EQ(MDCCollectionViewCellAccessoryDisclosureIndicator, | |
| 168 detail_item.accessoryType); | |
| 169 } | |
| 170 | |
| 171 // Tests that the correct items are displayed after loading the model, when | |
| 172 // there is no selected payment method. | |
| 173 TEST_F(PaymentRequestViewControllerTest, TestModelNoSelectedPaymentMethod) { | |
| 174 CreateController(); | |
| 175 CheckController(); | |
| 176 | |
| 177 payment_request_->set_selected_credit_card(nullptr); | |
| 178 [GetPaymentRequestViewController() loadModel]; | |
| 179 | |
| 180 // The only item in the Payment section should be of type | |
| 181 // CollectionViewDetailItem. | |
| 182 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(2))); | |
| 183 id item = GetCollectionViewItem(2, 0); | |
| 184 EXPECT_TRUE([item isMemberOfClass:[CollectionViewDetailItem class]]); | |
| 185 CollectionViewDetailItem* detail_item = item; | |
| 186 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, detail_item.accessoryType); | |
| 187 } | |
| 188 | |
| 189 // Tests that the correct items are displayed after loading the model, when | |
| 190 // the view is in pending state. | 323 // the view is in pending state. |
| 191 TEST_F(PaymentRequestViewControllerTest, TestModelPendingState) { | 324 TEST_F(PaymentRequestViewControllerTest, TestModelPendingState) { |
| 192 CreateController(); | 325 CreateController(); |
| 193 CheckController(); | 326 CheckController(); |
| 194 | 327 |
| 195 [GetPaymentRequestViewController() setPending:YES]; | 328 [GetPaymentRequestViewController() setPending:YES]; |
| 196 [GetPaymentRequestViewController() loadModel]; | 329 [GetPaymentRequestViewController() loadModel]; |
| 197 | 330 |
| 198 ASSERT_EQ(1, NumberOfSections()); | 331 ASSERT_EQ(1, NumberOfSections()); |
| 199 // There should be only one item. | 332 // There should be only one item. |
| 200 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); | 333 ASSERT_EQ(1U, static_cast<unsigned int>(NumberOfItemsInSection(0))); |
| 201 | 334 |
| 202 // The item should be of type StatusItem. | 335 // The item should be of type StatusItem. |
| 203 id item = GetCollectionViewItem(0, 0); | 336 id item = GetCollectionViewItem(0, 0); |
| 204 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); | 337 EXPECT_TRUE([item isMemberOfClass:[StatusItem class]]); |
| 205 } | 338 } |
| 206 | |
| 207 TEST_F(PaymentRequestViewControllerTest, TestSignedInStringFormatting) { | |
| 208 const std::string unformattedString = l10n_util::GetStringUTF8( | |
| 209 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN); | |
| 210 const std::string formattedString = l10n_util::GetStringFUTF8( | |
| 211 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN, | |
| 212 base::ASCIIToUTF16("example@gmail.com")); | |
| 213 | |
| 214 EXPECT_NE(unformattedString, formattedString); | |
| 215 } | |
| OLD | NEW |