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

Side by Side Diff: ios/chrome/browser/ui/payments/payment_request_mediator_unittest.mm

Issue 2970013003: [Payment Request] Displays appropriate footer if first transaction completed (Closed)
Patch Set: Created 3 years, 5 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 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_mediator.h" 5 #import "ios/chrome/browser/ui/payments/payment_request_mediator.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/scoped_task_environment.h" 12 #include "base/test/scoped_task_environment.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/autofill_test_utils.h" 14 #include "components/autofill/core/browser/autofill_test_utils.h"
15 #include "components/autofill/core/browser/credit_card.h" 15 #include "components/autofill/core/browser/credit_card.h"
16 #include "components/autofill/core/browser/test_personal_data_manager.h" 16 #include "components/autofill/core/browser/test_personal_data_manager.h"
17 #include "components/payments/core/payment_prefs.h"
17 #include "components/payments/core/strings_util.h" 18 #include "components/payments/core/strings_util.h"
19 #include "components/prefs/pref_service.h"
18 #include "components/signin/core/browser/signin_manager.h" 20 #include "components/signin/core/browser/signin_manager.h"
19 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
20 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 22 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
21 #include "ios/chrome/browser/payments/payment_request_test_util.h" 23 #include "ios/chrome/browser/payments/payment_request_test_util.h"
22 #include "ios/chrome/browser/payments/payment_request_util.h" 24 #include "ios/chrome/browser/payments/payment_request_util.h"
23 #include "ios/chrome/browser/payments/test_payment_request.h" 25 #include "ios/chrome/browser/payments/test_payment_request.h"
24 #include "ios/chrome/browser/signin/fake_signin_manager_builder.h" 26 #include "ios/chrome/browser/signin/fake_signin_manager_builder.h"
25 #include "ios/chrome/browser/signin/signin_manager_factory.h" 27 #include "ios/chrome/browser/signin/signin_manager_factory.h"
26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 29 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
(...skipping 15 matching lines...) Expand all
43 using ::payment_request_util::GetEmailLabelFromAutofillProfile; 45 using ::payment_request_util::GetEmailLabelFromAutofillProfile;
44 using ::payment_request_util::GetNameLabelFromAutofillProfile; 46 using ::payment_request_util::GetNameLabelFromAutofillProfile;
45 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile; 47 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile;
46 using ::payment_request_util::GetShippingAddressLabelFromAutofillProfile; 48 using ::payment_request_util::GetShippingAddressLabelFromAutofillProfile;
47 } // namespace 49 } // namespace
48 50
49 class PaymentRequestMediatorTest : public PlatformTest { 51 class PaymentRequestMediatorTest : public PlatformTest {
50 protected: 52 protected:
51 PaymentRequestMediatorTest() 53 PaymentRequestMediatorTest()
52 : autofill_profile_(autofill::test::GetFullProfile()), 54 : autofill_profile_(autofill::test::GetFullProfile()),
53 credit_card_(autofill::test::GetCreditCard()) { 55 credit_card_(autofill::test::GetCreditCard()),
56 pref_service_(autofill::test::PrefServiceForTesting()) {
54 // Add testing profile and credit card to autofill::TestPersonalDataManager. 57 // Add testing profile and credit card to autofill::TestPersonalDataManager.
55 personal_data_manager_.AddTestingProfile(&autofill_profile_); 58 personal_data_manager_.AddTestingProfile(&autofill_profile_);
56 credit_card_.set_billing_address_id(autofill_profile_.guid()); 59 credit_card_.set_billing_address_id(autofill_profile_.guid());
57 personal_data_manager_.AddTestingCreditCard(&credit_card_); 60 personal_data_manager_.AddTestingCreditCard(&credit_card_);
58 61
59 payment_request_ = base::MakeUnique<TestPaymentRequest>(
60 payment_request_test_util::CreateTestWebPaymentRequest(),
61 &personal_data_manager_);
62
63 TestChromeBrowserState::Builder test_cbs_builder; 62 TestChromeBrowserState::Builder test_cbs_builder;
64 test_cbs_builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(), 63 test_cbs_builder.AddTestingFactory(ios::SigninManagerFactory::GetInstance(),
65 &ios::BuildFakeSigninManager); 64 &ios::BuildFakeSigninManager);
66 chrome_browser_state_ = test_cbs_builder.Build(); 65 chrome_browser_state_ = test_cbs_builder.Build();
66
67 payment_request_ = base::MakeUnique<TestPaymentRequest>(
68 payment_request_test_util::CreateTestWebPaymentRequest(),
69 chrome_browser_state_.get(), &personal_data_manager_);
70 payment_request_->SetPrefService(pref_service_.get());
71
67 mediator_ = [[PaymentRequestMediator alloc] 72 mediator_ = [[PaymentRequestMediator alloc]
68 initWithBrowserState:chrome_browser_state_.get() 73 initWithPaymentRequest:payment_request_.get()];
69 paymentRequest:payment_request_.get()];
70 } 74 }
71 75
72 PaymentRequestMediator* GetPaymentRequestMediator() { return mediator_; } 76 PaymentRequestMediator* GetPaymentRequestMediator() { return mediator_; }
73 77
74 base::test::ScopedTaskEnvironment scoped_task_evironment_; 78 base::test::ScopedTaskEnvironment scoped_task_evironment_;
75 79
76 autofill::AutofillProfile autofill_profile_; 80 autofill::AutofillProfile autofill_profile_;
77 autofill::CreditCard credit_card_; 81 autofill::CreditCard credit_card_;
82 std::unique_ptr<PrefService> pref_service_;
78 autofill::TestPersonalDataManager personal_data_manager_; 83 autofill::TestPersonalDataManager personal_data_manager_;
79 std::unique_ptr<TestPaymentRequest> payment_request_; 84 std::unique_ptr<TestPaymentRequest> payment_request_;
80 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 85 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
81 PaymentRequestMediator* mediator_; 86 PaymentRequestMediator* mediator_;
82 }; 87 };
83 88
84 // Tests whether payment can be completed when expected. 89 // Tests whether payment can be completed when expected.
85 TEST_F(PaymentRequestMediatorTest, TestCanPay) { 90 TEST_F(PaymentRequestMediatorTest, TestCanPay) {
86 EXPECT_TRUE(payment_request_->selected_credit_card()); 91 EXPECT_TRUE(payment_request_->selected_credit_card());
87 EXPECT_TRUE(payment_request_->selected_shipping_profile()); 92 EXPECT_TRUE(payment_request_->selected_shipping_profile());
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 base::mac::ObjCCastStrict<CollectionViewDetailItem>(item); 421 base::mac::ObjCCastStrict<CollectionViewDetailItem>(item);
417 EXPECT_TRUE([add_contact_info_item.detailText 422 EXPECT_TRUE([add_contact_info_item.detailText
418 isEqualToString:[l10n_util::GetNSString(IDS_ADD) 423 isEqualToString:[l10n_util::GetNSString(IDS_ADD)
419 uppercaseStringWithLocale:[NSLocale currentLocale]]]); 424 uppercaseStringWithLocale:[NSLocale currentLocale]]]);
420 EXPECT_EQ(MDCCollectionViewCellAccessoryNone, 425 EXPECT_EQ(MDCCollectionViewCellAccessoryNone,
421 add_contact_info_item.accessoryType); 426 add_contact_info_item.accessoryType);
422 } 427 }
423 428
424 // Tests that the Footer item is created as expected. 429 // Tests that the Footer item is created as expected.
425 TEST_F(PaymentRequestMediatorTest, TestFooterItem) { 430 TEST_F(PaymentRequestMediatorTest, TestFooterItem) {
431 // Make sure the first transaction has not completed yet.
432 pref_service_->SetBoolean(payments::kPaymentsFirstTransactionCompleted,
433 false);
434
426 // Make sure the user is signed out. 435 // Make sure the user is signed out.
427 SigninManager* signin_manager = ios::SigninManagerFactory::GetForBrowserState( 436 SigninManager* signin_manager = ios::SigninManagerFactory::GetForBrowserState(
428 chrome_browser_state_.get()); 437 chrome_browser_state_.get());
429 if (signin_manager->IsAuthenticated()) { 438 if (signin_manager->IsAuthenticated()) {
430 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST, 439 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST,
431 signin_metrics::SignoutDelete::IGNORE_METRIC); 440 signin_metrics::SignoutDelete::IGNORE_METRIC);
432 } 441 }
433 442
434 // Footer item should be of type CollectionViewFooterItem. 443 // Footer item should be of type CollectionViewFooterItem.
435 id item = [GetPaymentRequestMediator() footerItem]; 444 id item = [GetPaymentRequestMediator() footerItem];
436 ASSERT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]); 445 ASSERT_TRUE([item isMemberOfClass:[CollectionViewFooterItem class]]);
437 CollectionViewFooterItem* footer_item = 446 CollectionViewFooterItem* footer_item =
438 base::mac::ObjCCastStrict<CollectionViewFooterItem>(item); 447 base::mac::ObjCCastStrict<CollectionViewFooterItem>(item);
439 EXPECT_TRUE([footer_item.text 448 EXPECT_TRUE([footer_item.text
440 isEqualToString:l10n_util::GetNSString( 449 isEqualToString:l10n_util::GetNSString(
441 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_OUT)]); 450 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_OUT)]);
442 451
443 // Fake a signed in user. 452 // Fake a signed in user.
444 signin_manager->SetAuthenticatedAccountInfo("12345", "username@example.com"); 453 signin_manager->SetAuthenticatedAccountInfo("12345", "username@example.com");
445 454
446 item = [GetPaymentRequestMediator() footerItem]; 455 item = [GetPaymentRequestMediator() footerItem];
447 footer_item = base::mac::ObjCCastStrict<CollectionViewFooterItem>(item); 456 footer_item = base::mac::ObjCCastStrict<CollectionViewFooterItem>(item);
448 EXPECT_TRUE([footer_item.text 457 EXPECT_TRUE([footer_item.text
449 isEqualToString:l10n_util::GetNSStringF( 458 isEqualToString:l10n_util::GetNSStringF(
450 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN, 459 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN,
451 base::ASCIIToUTF16("username@example.com"))]); 460 base::ASCIIToUTF16("username@example.com"))]);
461
462 // Record that the first transaction completed.
463 pref_service_->SetBoolean(payments::kPaymentsFirstTransactionCompleted, true);
464
465 item = [GetPaymentRequestMediator() footerItem];
466 footer_item = base::mac::ObjCCastStrict<CollectionViewFooterItem>(item);
467 EXPECT_TRUE([footer_item.text
468 isEqualToString:l10n_util::GetNSString(
469 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS)]);
470
471 // Sign the user out.
472 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST,
473 signin_metrics::SignoutDelete::IGNORE_METRIC);
474
475 // The signed in state has no effect on the footer text if the first
476 // transaction has completed.
477 footer_item = base::mac::ObjCCastStrict<CollectionViewFooterItem>(item);
478 EXPECT_TRUE([footer_item.text
479 isEqualToString:l10n_util::GetNSString(
480 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS)]);
452 } 481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698