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

Side by Side Diff: components/payments/core/autofill_payment_instrument_unittest.cc

Issue 2851893002: [Payments] Record CanMakePayment metrics on Desktop. (Closed)
Patch Set: Windows Fix and Rebase Fix Created 3 years, 7 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/core/autofill_payment_instrument.h" 5 #include "components/payments/core/autofill_payment_instrument.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
(...skipping 29 matching lines...) Expand all
40 40
41 bool WasOnInstrumentDetailsErrorCalled() { 41 bool WasOnInstrumentDetailsErrorCalled() {
42 return on_instrument_details_error_called_; 42 return on_instrument_details_error_called_;
43 } 43 }
44 44
45 private: 45 private:
46 bool on_instrument_details_ready_called_ = false; 46 bool on_instrument_details_ready_called_ = false;
47 bool on_instrument_details_error_called_ = false; 47 bool on_instrument_details_error_called_ = false;
48 }; 48 };
49 49
50 class FakeAddressNormalizer : public AddressNormalizer {
51 public:
52 FakeAddressNormalizer() {}
53
54 void LoadRulesForRegion(const std::string& region_code) override {}
55
56 bool AreRulesLoadedForRegion(const std::string& region_code) override {
57 return true;
58 }
59
60 void StartAddressNormalization(
61 const autofill::AutofillProfile& profile,
62 const std::string& region_code,
63 int timeout_seconds,
64 AddressNormalizer::Delegate* requester) override {
65 profile_ = profile;
66 requester_ = requester;
67 }
68
69 void OnAddressValidationRulesLoaded(const std::string& region_code,
70 bool success) override {}
71
72 void CompleteAddressNormalization() {
73 requester_->OnAddressNormalized(profile_);
74 }
75
76 private:
77 autofill::AutofillProfile profile_;
78 AddressNormalizer::Delegate* requester_;
79 };
80
81 class FakePaymentRequestDelegate : public PaymentRequestDelegate {
82 public:
83 FakePaymentRequestDelegate()
84 : locale_("en-US"), last_committed_url_("https://shop.com") {}
85 void ShowDialog(PaymentRequest* request) override {}
86
87 void CloseDialog() override {}
88
89 void ShowErrorMessage() override {}
90
91 autofill::PersonalDataManager* GetPersonalDataManager() override {
92 return nullptr;
93 }
94
95 const std::string& GetApplicationLocale() const override { return locale_; }
96
97 bool IsIncognito() const override { return false; }
98
99 bool IsSslCertificateValid() override { return true; }
100
101 const GURL& GetLastCommittedURL() const override {
102 return last_committed_url_;
103 }
104
105 void DoFullCardRequest(
106 const autofill::CreditCard& credit_card,
107 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
108 result_delegate) override {
109 full_card_request_card_ = credit_card;
110 full_card_result_delegate_ = result_delegate;
111 }
112
113 AddressNormalizer* GetAddressNormalizer() override {
114 return &address_normalizer_;
115 }
116
117 FakeAddressNormalizer* GetTestAddressNormalizer() {
118 return &address_normalizer_;
119 }
120
121 void CompleteFullCardRequest() {
122 full_card_result_delegate_->OnFullCardRequestSucceeded(
123 full_card_request_card_, base::ASCIIToUTF16("123"));
124 }
125
126 autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; }
127
128 ukm::UkmService* GetUkmService() override { return nullptr; }
129
130 private:
131 std::string locale_;
132 const GURL last_committed_url_;
133 FakeAddressNormalizer address_normalizer_;
134
135 autofill::CreditCard full_card_request_card_;
136 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
137 full_card_result_delegate_;
138 DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
139 };
140
50 } // namespace 141 } // namespace
51 142
52 class AutofillPaymentInstrumentTest : public testing::Test { 143 class AutofillPaymentInstrumentTest : public testing::Test {
53 protected: 144 protected:
54 AutofillPaymentInstrumentTest() 145 AutofillPaymentInstrumentTest()
55 : address_(autofill::test::GetFullProfile()), 146 : address_(autofill::test::GetFullProfile()),
56 local_card_(autofill::test::GetCreditCard()), 147 local_card_(autofill::test::GetCreditCard()),
57 billing_profiles_({&address_}) { 148 billing_profiles_({&address_}) {
58 local_card_.set_billing_address_id(address_.guid()); 149 local_card_.set_billing_address_id(address_.guid());
59 } 150 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 delegate.CompleteFullCardRequest(); 331 delegate.CompleteFullCardRequest();
241 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 332 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
242 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 333 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
243 334
244 delegate.test_address_normalizer()->CompleteAddressNormalization(); 335 delegate.test_address_normalizer()->CompleteAddressNormalization();
245 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 336 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
246 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 337 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
247 } 338 }
248 339
249 } // namespace payments 340 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request.cc ('k') | components/payments/core/journey_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698