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

Side by Side Diff: components/payments/content/payment_request_state_unittest.cc

Issue 2779283002: [Web Payments] Implement the CVC Unmask dialog. (Closed)
Patch Set: BUILD Created 3 years, 8 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 #include "components/payments/content/payment_request_state.h" 5 #include "components/payments/content/payment_request_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/autofill/core/browser/autofill_test_utils.h" 12 #include "components/autofill/core/browser/autofill_test_utils.h"
13 #include "components/autofill/core/browser/credit_card.h" 13 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/test_personal_data_manager.h" 14 #include "components/autofill/core/browser/test_personal_data_manager.h"
15 #include "components/payments/content/payment_request.mojom.h" 15 #include "components/payments/content/payment_request.mojom.h"
16 #include "components/payments/content/payment_request_spec.h" 16 #include "components/payments/content/payment_request_spec.h"
17 #include "components/payments/core/payment_request_delegate.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace payments { 20 namespace payments {
20 21
22 class FakePaymentRequestDelegate : public PaymentRequestDelegate {
23 public:
24 FakePaymentRequestDelegate(
25 autofill::PersonalDataManager* personal_data_manager)
26 : personal_data_manager_(personal_data_manager), locale_("en-US") {}
27 void ShowDialog(PaymentRequest* request) override {}
28
29 void CloseDialog() override {}
30
31 void ShowErrorMessage() override {}
32
33 autofill::PersonalDataManager* GetPersonalDataManager() override {
34 return personal_data_manager_;
35 }
36
37 const std::string& GetApplicationLocale() const override { return locale_; }
38
39 bool IsIncognito() const override { return false; }
40
41 void DoFullCardRequest(
42 const autofill::CreditCard& credit_card,
43 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
44 result_delegate) override {
45 result_delegate->OnFullCardRequestSucceeded(credit_card,
46 base::ASCIIToUTF16("123"));
47 }
48
49 private:
50 autofill::PersonalDataManager* personal_data_manager_;
51 std::string locale_;
52 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
53 };
54
21 class PaymentRequestStateTest : public testing::Test, 55 class PaymentRequestStateTest : public testing::Test,
22 public PaymentRequestState::Observer, 56 public PaymentRequestState::Observer,
23 public PaymentRequestState::Delegate { 57 public PaymentRequestState::Delegate {
24 protected: 58 protected:
25 PaymentRequestStateTest() 59 PaymentRequestStateTest()
26 : num_on_selected_information_changed_called_(0), 60 : num_on_selected_information_changed_called_(0),
61 payment_request_delegate_(
62 new FakePaymentRequestDelegate(&test_personal_data_manager_)),
27 address_(autofill::test::GetFullProfile()), 63 address_(autofill::test::GetFullProfile()),
28 credit_card_visa_(autofill::test::GetCreditCard()), 64 credit_card_visa_(autofill::test::GetCreditCard()),
29 credit_card_amex_(autofill::test::GetCreditCard2()) { 65 credit_card_amex_(autofill::test::GetCreditCard2()) {
30 test_personal_data_manager_.AddTestingProfile(&address_); 66 test_personal_data_manager_.AddTestingProfile(&address_);
31 credit_card_visa_.set_billing_address_id(address_.guid()); 67 credit_card_visa_.set_billing_address_id(address_.guid());
32 credit_card_visa_.set_use_count(5u); 68 credit_card_visa_.set_use_count(5u);
33 test_personal_data_manager_.AddTestingCreditCard(&credit_card_visa_); 69 test_personal_data_manager_.AddTestingCreditCard(&credit_card_visa_);
34 credit_card_amex_.set_billing_address_id(address_.guid()); 70 credit_card_amex_.set_billing_address_id(address_.guid());
35 credit_card_amex_.set_use_count(1u); 71 credit_card_amex_.set_use_count(1u);
36 test_personal_data_manager_.AddTestingCreditCard(&credit_card_amex_); 72 test_personal_data_manager_.AddTestingCreditCard(&credit_card_amex_);
(...skipping 20 matching lines...) Expand all
57 93
58 void RecreateStateWithOptionsAndDetails( 94 void RecreateStateWithOptionsAndDetails(
59 mojom::PaymentOptionsPtr options, 95 mojom::PaymentOptionsPtr options,
60 mojom::PaymentDetailsPtr details, 96 mojom::PaymentDetailsPtr details,
61 std::vector<mojom::PaymentMethodDataPtr> method_data) { 97 std::vector<mojom::PaymentMethodDataPtr> method_data) {
62 // The spec will be based on the |options| and |details| passed in. 98 // The spec will be based on the |options| and |details| passed in.
63 spec_ = base::MakeUnique<PaymentRequestSpec>( 99 spec_ = base::MakeUnique<PaymentRequestSpec>(
64 std::move(options), std::move(details), std::move(method_data), nullptr, 100 std::move(options), std::move(details), std::move(method_data), nullptr,
65 "en-US"); 101 "en-US");
66 state_ = base::MakeUnique<PaymentRequestState>( 102 state_ = base::MakeUnique<PaymentRequestState>(
67 spec_.get(), this, "en-US", &test_personal_data_manager_); 103 spec_.get(), this, "en-US", &test_personal_data_manager_,
104 payment_request_delegate_.get());
68 state_->AddObserver(this); 105 state_->AddObserver(this);
69 } 106 }
70 107
71 // Convenience method to create a PaymentRequestState with default details 108 // Convenience method to create a PaymentRequestState with default details
72 // (one shipping option) and method data (only supports visa). 109 // (one shipping option) and method data (only supports visa).
73 void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) { 110 void RecreateStateWithOptions(mojom::PaymentOptionsPtr options) {
74 // Create dummy PaymentDetails with a single shipping option. 111 // Create dummy PaymentDetails with a single shipping option.
75 std::vector<mojom::PaymentShippingOptionPtr> shipping_options; 112 std::vector<mojom::PaymentShippingOptionPtr> shipping_options;
76 mojom::PaymentShippingOptionPtr option = 113 mojom::PaymentShippingOptionPtr option =
77 mojom::PaymentShippingOption::New(); 114 mojom::PaymentShippingOption::New();
(...skipping 22 matching lines...) Expand all
100 } 137 }
101 138
102 autofill::AutofillProfile* test_address() { return &address_; } 139 autofill::AutofillProfile* test_address() { return &address_; }
103 140
104 private: 141 private:
105 std::unique_ptr<PaymentRequestState> state_; 142 std::unique_ptr<PaymentRequestState> state_;
106 std::unique_ptr<PaymentRequestSpec> spec_; 143 std::unique_ptr<PaymentRequestSpec> spec_;
107 int num_on_selected_information_changed_called_; 144 int num_on_selected_information_changed_called_;
108 mojom::PaymentResponsePtr payment_response_; 145 mojom::PaymentResponsePtr payment_response_;
109 autofill::TestPersonalDataManager test_personal_data_manager_; 146 autofill::TestPersonalDataManager test_personal_data_manager_;
147 std::unique_ptr<FakePaymentRequestDelegate> payment_request_delegate_;
110 148
111 // Test data. 149 // Test data.
112 autofill::AutofillProfile address_; 150 autofill::AutofillProfile address_;
113 autofill::CreditCard credit_card_visa_; 151 autofill::CreditCard credit_card_visa_;
114 autofill::CreditCard credit_card_amex_; 152 autofill::CreditCard credit_card_amex_;
115 autofill::CreditCard credit_card_jcb_; 153 autofill::CreditCard credit_card_jcb_;
116 }; 154 };
117 155
118 TEST_F(PaymentRequestStateTest, CanMakePayment) { 156 TEST_F(PaymentRequestStateTest, CanMakePayment) {
119 // Default options. 157 // Default options.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 EXPECT_TRUE(state()->is_ready_to_pay()); 429 EXPECT_TRUE(state()->is_ready_to_pay());
392 state()->GeneratePaymentResponse(); 430 state()->GeneratePaymentResponse();
393 431
394 // Check that the name was set, but not the other values. 432 // Check that the name was set, but not the other values.
395 EXPECT_EQ("John H. Doe", response()->payer_name.value()); 433 EXPECT_EQ("John H. Doe", response()->payer_name.value());
396 EXPECT_FALSE(response()->payer_phone.has_value()); 434 EXPECT_FALSE(response()->payer_phone.has_value());
397 EXPECT_FALSE(response()->payer_email.has_value()); 435 EXPECT_FALSE(response()->payer_email.has_value());
398 } 436 }
399 437
400 } // namespace payments 438 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698