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

Unified Diff: components/payments/core/autofill_payment_instrument_unittest.cc

Issue 2851893002: [Payments] Record CanMakePayment metrics on Desktop. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/core/autofill_payment_instrument_unittest.cc
diff --git a/components/payments/core/autofill_payment_instrument_unittest.cc b/components/payments/core/autofill_payment_instrument_unittest.cc
index 6735be8965bd719434bf503f7138fd79574b5975..8720a44850512b228e4a89f27035317bcb8a8528 100644
--- a/components/payments/core/autofill_payment_instrument_unittest.cc
+++ b/components/payments/core/autofill_payment_instrument_unittest.cc
@@ -11,7 +11,7 @@
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/payments/core/address_normalizer.h"
-#include "components/payments/core/payment_request_delegate.h"
+#include "components/payments/core/test_payment_request_delegate.h"
#include "components/strings/grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
@@ -47,95 +47,6 @@ class FakePaymentInstrumentDelegate : public PaymentInstrument::Delegate {
bool on_instrument_details_error_called_ = false;
};
-class FakeAddressNormalizer : public AddressNormalizer {
- public:
- FakeAddressNormalizer() {}
-
- void LoadRulesForRegion(const std::string& region_code) override {}
-
- bool AreRulesLoadedForRegion(const std::string& region_code) override {
- return true;
- }
-
- void StartAddressNormalization(
- const autofill::AutofillProfile& profile,
- const std::string& region_code,
- int timeout_seconds,
- AddressNormalizer::Delegate* requester) override {
- profile_ = profile;
- requester_ = requester;
- }
-
- void OnAddressValidationRulesLoaded(const std::string& region_code,
- bool success) override {}
-
- void CompleteAddressNormalization() {
- requester_->OnAddressNormalized(profile_);
- }
-
- private:
- autofill::AutofillProfile profile_;
- AddressNormalizer::Delegate* requester_;
-};
-
-class FakePaymentRequestDelegate : public PaymentRequestDelegate {
- public:
- FakePaymentRequestDelegate()
- : locale_("en-US"), last_committed_url_("https://shop.com") {}
- void ShowDialog(PaymentRequest* request) override {}
-
- void CloseDialog() override {}
-
- void ShowErrorMessage() override {}
-
- autofill::PersonalDataManager* GetPersonalDataManager() override {
- return nullptr;
- }
-
- const std::string& GetApplicationLocale() const override { return locale_; }
-
- bool IsIncognito() const override { return false; }
-
- bool IsSslCertificateValid() override { return true; }
-
- const GURL& GetLastCommittedURL() const override {
- return last_committed_url_;
- }
-
- void DoFullCardRequest(
- const autofill::CreditCard& credit_card,
- base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
- result_delegate) override {
- full_card_request_card_ = credit_card;
- full_card_result_delegate_ = result_delegate;
- }
-
- AddressNormalizer* GetAddressNormalizer() override {
- return &address_normalizer_;
- }
-
- FakeAddressNormalizer* GetTestAddressNormalizer() {
- return &address_normalizer_;
- }
-
- void CompleteFullCardRequest() {
- full_card_result_delegate_->OnFullCardRequestSucceeded(
- full_card_request_card_, base::ASCIIToUTF16("123"));
- }
-
- autofill::RegionDataLoader* GetRegionDataLoader() override { return nullptr; }
-
- private:
- std::string locale_;
- const GURL last_committed_url_;
- FakeAddressNormalizer address_normalizer_;
-
- autofill::CreditCard full_card_request_card_;
- base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
- full_card_result_delegate_;
- DISALLOW_COPY_AND_ASSIGN(FakePaymentRequestDelegate);
-};
-
} // namespace
class AutofillPaymentInstrumentTest : public testing::Test {
@@ -283,7 +194,9 @@ TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_NoNumber) {
// the billing address has been normalized and the card has been unmasked.
TEST_F(AutofillPaymentInstrumentTest,
InvokePaymentApp_NormalizationBeforeUnmask) {
- FakePaymentRequestDelegate delegate;
+ TestPaymentRequestDelegate delegate(/*personal_data_manager=*/nullptr);
+ delegate.DelayFullCardRequestCompletion();
+ delegate.GetTestAddressNormalizer()->DelayNormalization();
autofill::CreditCard& card = local_credit_card();
card.SetNumber(base::ASCIIToUTF16(""));
@@ -309,7 +222,9 @@ TEST_F(AutofillPaymentInstrumentTest,
// the billing address has been normalized and the card has been unmasked.
TEST_F(AutofillPaymentInstrumentTest,
InvokePaymentApp_UnmaskBeforeNormalization) {
- FakePaymentRequestDelegate delegate;
+ TestPaymentRequestDelegate delegate(/*personal_data_manager=*/nullptr);
+ delegate.DelayFullCardRequestCompletion();
Mathieu 2017/05/02 20:56:47 is this part of another change?
sebsg 2017/05/02 22:15:08 Done.
+ delegate.GetTestAddressNormalizer()->DelayNormalization();
autofill::CreditCard& card = local_credit_card();
card.SetNumber(base::ASCIIToUTF16(""));

Powered by Google App Engine
This is Rietveld 408576698