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

Unified Diff: ios/chrome/browser/ui/payments/payment_method_selection_coordinator_unittest.mm

Issue 2956453003: [Payment Request] Makes sure only complete credit cards can be selected (Closed)
Patch Set: Fixed unit test Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/payments/payment_method_selection_coordinator_unittest.mm
diff --git a/ios/chrome/browser/ui/payments/payment_method_selection_coordinator_unittest.mm b/ios/chrome/browser/ui/payments/payment_method_selection_coordinator_unittest.mm
index dec60fa12c25ea50ab71c0babdd65256ec8c6029..c0802c89d71ac721805bf4caecad2bb207bbf1d2 100644
--- a/ios/chrome/browser/ui/payments/payment_method_selection_coordinator_unittest.mm
+++ b/ios/chrome/browser/ui/payments/payment_method_selection_coordinator_unittest.mm
@@ -7,6 +7,7 @@
#include "base/mac/foundation_util.h"
#include "base/memory/ptr_util.h"
#include "base/test/ios/wait_util.h"
+#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
@@ -27,16 +28,23 @@ class PaymentRequestPaymentMethodSelectionCoordinatorTest
: public PlatformTest {
protected:
PaymentRequestPaymentMethodSelectionCoordinatorTest()
- : credit_card1_(autofill::test::GetCreditCard()),
+ : autofill_profile_(autofill::test::GetFullProfile()),
+ credit_card1_(autofill::test::GetCreditCard()),
credit_card2_(autofill::test::GetCreditCard2()) {
- // Add testing credit cards to autofill::TestPersonalDataManager.
+ // Add testing credit cards to autofill::TestPersonalDataManager. Make the
+ // less frequently used one incomplete.
+ credit_card1_.set_use_count(10U);
+ personal_data_manager_.AddTestingProfile(&autofill_profile_);
+ credit_card1_.set_billing_address_id(autofill_profile_.guid());
personal_data_manager_.AddTestingCreditCard(&credit_card1_);
+ credit_card2_.set_use_count(5U);
personal_data_manager_.AddTestingCreditCard(&credit_card2_);
payment_request_ = base::MakeUnique<PaymentRequest>(
payment_request_test_util::CreateTestWebPaymentRequest(),
&personal_data_manager_);
}
+ autofill::AutofillProfile autofill_profile_;
autofill::CreditCard credit_card1_;
autofill::CreditCard credit_card2_;
autofill::TestPersonalDataManager personal_data_manager_;
@@ -76,7 +84,7 @@ TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest, StartAndStop) {
// Tests that calling the view controller delegate method which notifies the
// coordinator about selection of a payment method invokes the corresponding
-// coordinator delegate method.
+// coordinator delegate method, only if the payment method is complete.
TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest,
DidSelectPaymentMethod) {
UIViewController* base_view_controller = [[UIViewController alloc] init];
@@ -92,9 +100,12 @@ TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest,
// Mock the coordinator delegate.
id delegate = [OCMockObject
mockForProtocol:@protocol(PaymentMethodSelectionCoordinatorDelegate)];
- autofill::CreditCard* credit_card = payment_request_->credit_cards()[1];
- [[delegate expect] paymentMethodSelectionCoordinator:coordinator
- didSelectPaymentMethod:credit_card];
+ [[delegate expect]
+ paymentMethodSelectionCoordinator:coordinator
+ didSelectPaymentMethod:payment_request_->credit_cards()[0]];
+ [[delegate reject]
+ paymentMethodSelectionCoordinator:coordinator
+ didSelectPaymentMethod:payment_request_->credit_cards()[1]];
[coordinator setDelegate:delegate];
EXPECT_EQ(1u, navigation_controller.viewControllers.count);
@@ -104,13 +115,16 @@ TEST_F(PaymentRequestPaymentMethodSelectionCoordinatorTest,
base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSecondsD(1.0));
EXPECT_EQ(2u, navigation_controller.viewControllers.count);
- // Call the controller delegate method.
+ // Call the controller delegate method for both selectable items.
PaymentRequestSelectorViewController* view_controller =
base::mac::ObjCCastStrict<PaymentRequestSelectorViewController>(
navigation_controller.visibleViewController);
[coordinator paymentRequestSelectorViewController:view_controller
+ didSelectItemAtIndex:0];
+ // Wait for the coordinator delegate to be notified.
+ base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));
+ [coordinator paymentRequestSelectorViewController:view_controller
didSelectItemAtIndex:1];
-
// Wait for the coordinator delegate to be notified.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(0.5));

Powered by Google App Engine
This is Rietveld 408576698