Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: ios/chrome/browser/payments/payment_request_view_controller.mm

Issue 2588913002: EarlGrey tests for Payment Request (base CL) (Closed)
Patch Set: Moved the experimental flag back to the BVC Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/payment_request_view_controller.h" 5 #import "ios/chrome/browser/payments/payment_request_view_controller.h"
6 6
7 #import "base/ios/weak_nsobject.h" 7 #import "base/ios/weak_nsobject.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/mac/objc_property_releaser.h" 9 #include "base/mac/objc_property_releaser.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "components/autofill/core/browser/autofill_data_util.h" 12 #include "components/autofill/core/browser/autofill_data_util.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 13 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/credit_card.h" 14 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/field_types.h" 15 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/personal_data_manager.h" 16 #include "components/autofill/core/browser/personal_data_manager.h"
17 #include "components/strings/grit/components_strings.h"
17 #include "ios/chrome/browser/application_context.h" 18 #include "ios/chrome/browser/application_context.h"
18 #import "ios/chrome/browser/payments/cells/page_info_item.h" 19 #import "ios/chrome/browser/payments/cells/page_info_item.h"
19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 20 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
20 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" 21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
21 #import "ios/chrome/browser/payments/payment_request_utils.h" 22 #import "ios/chrome/browser/payments/payment_request_utils.h"
22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
25 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 26 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
26 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 27 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
27 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 28 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
28 #include "ios/chrome/browser/ui/rtl_geometry.h" 29 #include "ios/chrome/browser/ui/rtl_geometry.h"
29 #include "ios/chrome/grit/ios_strings.h" 30 #include "ios/chrome/grit/ios_strings.h"
30 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 31 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
31 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 32 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
32 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 33 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
33 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 34 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
36 37
38 using payment_request_utils::NameLabelFromAutofillProfile;
39 using payment_request_utils::AddressLabelFromAutofillProfile;
40 using payment_request_utils::PhoneNumberLabelFromAutofillProfile;
41
37 NSString* const kPaymentRequestCollectionViewId = 42 NSString* const kPaymentRequestCollectionViewId =
38 @"kPaymentRequestCollectionViewId"; 43 @"kPaymentRequestCollectionViewId";
39 44
40 namespace { 45 namespace {
41 46
42 const CGFloat kButtonEdgeInset = 9; 47 const CGFloat kButtonEdgeInset = 9;
43 const CGFloat kSeparatorEdgeInset = 14; 48 const CGFloat kSeparatorEdgeInset = 14;
44 49
45 typedef NS_ENUM(NSInteger, SectionIdentifier) { 50 typedef NS_ENUM(NSInteger, SectionIdentifier) {
46 SectionIdentifierSummary = kSectionIdentifierEnumZero, 51 SectionIdentifierSummary = kSectionIdentifierEnumZero,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 _cancelButton.reset([[UIBarButtonItem alloc] 109 _cancelButton.reset([[UIBarButtonItem alloc]
105 initWithTitle:l10n_util::GetNSString( 110 initWithTitle:l10n_util::GetNSString(
106 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) 111 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON)
107 style:UIBarButtonItemStylePlain 112 style:UIBarButtonItemStylePlain
108 target:nil 113 target:nil
109 action:@selector(onCancel)]); 114 action:@selector(onCancel)]);
110 [_cancelButton setTitleTextAttributes:@{ 115 [_cancelButton setTitleTextAttributes:@{
111 NSForegroundColorAttributeName : [UIColor lightGrayColor] 116 NSForegroundColorAttributeName : [UIColor lightGrayColor]
112 } 117 }
113 forState:UIControlStateDisabled]; 118 forState:UIControlStateDisabled];
119 [_cancelButton
120 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)];
114 [self navigationItem].leftBarButtonItem = _cancelButton; 121 [self navigationItem].leftBarButtonItem = _cancelButton;
115 122
116 // Set up right (pay) button. 123 // Set up right (pay) button.
117 _payButton.reset([[MDCFlatButton alloc] init]); 124 _payButton.reset([[MDCFlatButton alloc] init]);
118 [_payButton 125 [_payButton
119 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) 126 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON)
120 forState:UIControlStateNormal]; 127 forState:UIControlStateNormal];
121 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] 128 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]
122 forState:UIControlStateNormal]; 129 forState:UIControlStateNormal];
123 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; 130 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]];
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 NSIndexPath* indexPath = 348 NSIndexPath* indexPath =
342 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem 349 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem
343 inSectionWithIdentifier:SectionIdentifierShipping]; 350 inSectionWithIdentifier:SectionIdentifierShipping];
344 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 351 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
345 } 352 }
346 353
347 #pragma mark - Helper methods 354 #pragma mark - Helper methods
348 355
349 - (void)fillShippingAddressItem:(ShippingAddressItem*)item 356 - (void)fillShippingAddressItem:(ShippingAddressItem*)item
350 withAddress:(autofill::AutofillProfile*)address { 357 withAddress:(autofill::AutofillProfile*)address {
351 item.name = 358 item.name = NameLabelFromAutofillProfile(address);
352 base::SysUTF16ToNSString(address->GetRawInfo(autofill::NAME_FULL)); 359 item.address = AddressLabelFromAutofillProfile(address);
353 item.address = 360 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(address);
354 payment_request_utils::AddressLabelFromAutofillProfile(address);
355 item.phoneNumber = base::SysUTF16ToNSString(
356 address->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER));
357 } 361 }
358 362
359 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item 363 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item
360 withOption:(web::PaymentShippingOption*)option { 364 withOption:(web::PaymentShippingOption*)option {
361 item.text = base::SysUTF16ToNSString(option->label); 365 item.text = base::SysUTF16ToNSString(option->label);
362 NSString* currencyCode = base::SysUTF16ToNSString(option->amount.currency); 366 NSString* currencyCode = base::SysUTF16ToNSString(option->amount.currency);
363 NSDecimalNumber* value = [NSDecimalNumber 367 NSDecimalNumber* value = [NSDecimalNumber
364 decimalNumberWithString:SysUTF16ToNSString(option->amount.value)]; 368 decimalNumberWithString:SysUTF16ToNSString(option->amount.value)];
365 item.detailText = 369 item.detailText =
366 payment_request_utils::FormattedCurrencyString(value, currencyCode); 370 payment_request_utils::FormattedCurrencyString(value, currencyCode);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 459 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
456 if (type == ItemTypeSummaryTotal && 460 if (type == ItemTypeSummaryTotal &&
457 _paymentRequest.details.display_items.empty()) { 461 _paymentRequest.details.display_items.empty()) {
458 return YES; 462 return YES;
459 } else { 463 } else {
460 return NO; 464 return NO;
461 } 465 }
462 } 466 }
463 467
464 @end 468 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698