1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
#include "chrome/test/base/ui_test_utils.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/personal_data_manager.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/test/browser_test_utils.h"
namespace payments {
namespace {
const base::Time kSomeDate = base::Time::FromDoubleT(1484505871);
const base::Time kSomeLaterDate = base::Time::FromDoubleT(1497552271);
} // namespace
class PaymentRequestAutofillInstrumentUseStatsTest
: public PaymentRequestBrowserTestBase {
protected:
PaymentRequestAutofillInstrumentUseStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestAutofillInstrumentUseStatsTest);
};
// Tests that use stats for the autofill payment instrument used in a Payment
// Request are properly updated upon completion.
IN_PROC_BROWSER_TEST_F(PaymentRequestAutofillInstrumentUseStatsTest,
RecordUse) {
NavigateTo("/payment_request_no_shipping_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Setup a credit card with an associated billing address.
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card); // Visa.
// Check that the initial use stats were set correctly.
autofill::CreditCard* initial_card =
GetDataManager()->GetCreditCardByGUID(card.guid());
EXPECT_EQ(1U, initial_card->use_count());
EXPECT_EQ(kSomeDate, initial_card->use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUI();
ResetEventWaiter(DialogEvent::DIALOG_CLOSED);
PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
// Check that the usage of the card was recorded.
autofill::CreditCard* updated_card =
GetDataManager()->GetCreditCardByGUID(card.guid());
EXPECT_EQ(2U, updated_card->use_count());
EXPECT_EQ(kSomeLaterDate, updated_card->use_date());
}
class PaymentRequestShippingAddressUseStatsTest
: public PaymentRequestBrowserTestBase {
protected:
PaymentRequestShippingAddressUseStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestShippingAddressUseStatsTest);
};
// Tests that use stats for the shipping address used in a Payment Request are
// properly updated upon completion.
IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressUseStatsTest, RecordUse) {
NavigateTo("/payment_request_free_shipping_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Create a billing address and a card that uses it.
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card); // Visa.
// Create a shipping address with a higher frecency score, so that it is
// selected as the default shipping address.
autofill::AutofillProfile shipping_address =
autofill::test::GetFullProfile2();
shipping_address.set_use_count(3);
AddAutofillProfile(shipping_address);
// Check that the initial use stats were set correctly.
autofill::AutofillProfile* initial_shipping =
GetDataManager()->GetProfileByGUID(shipping_address.guid());
EXPECT_EQ(3U, initial_shipping->use_count());
EXPECT_EQ(kSomeDate, initial_shipping->use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUI();
ResetEventWaiter(DialogEvent::DIALOG_CLOSED);
PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
// Check that the usage of the profile was recorded.
autofill::AutofillProfile* updated_shipping =
GetDataManager()->GetProfileByGUID(shipping_address.guid());
EXPECT_EQ(4U, updated_shipping->use_count());
EXPECT_EQ(kSomeLaterDate, updated_shipping->use_date());
}
class PaymentRequestContactAddressUseStatsTest
: public PaymentRequestBrowserTestBase {
protected:
PaymentRequestContactAddressUseStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PaymentRequestContactAddressUseStatsTest);
};
// Tests that use stats for the contact address used in a Payment Request are
// properly updated upon completion.
IN_PROC_BROWSER_TEST_F(PaymentRequestContactAddressUseStatsTest, RecordUse) {
NavigateTo("/payment_request_name_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Setup a credit card with an associated billing address.
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card); // Visa.
// Create a contact address with a higher frecency score, so that it is
// selected as the default contact address.
autofill::AutofillProfile contact_address = autofill::test::GetFullProfile2();
contact_address.set_use_count(3);
AddAutofillProfile(contact_address);
// Check that the initial use stats were set correctly.
autofill::AutofillProfile* initial_contact =
GetDataManager()->GetProfileByGUID(contact_address.guid());
EXPECT_EQ(3U, initial_contact->use_count());
EXPECT_EQ(kSomeDate, initial_contact->use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUI();
ResetEventWaiter(DialogEvent::DIALOG_CLOSED);
PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
// Check that the usage of the profile was recorded.
autofill::AutofillProfile* updated_contact =
GetDataManager()->GetProfileByGUID(contact_address.guid());
EXPECT_EQ(4U, updated_contact->use_count());
EXPECT_EQ(kSomeLaterDate, updated_contact->use_date());
}
class PaymentRequestSameShippingAndContactAddressUseStatsTest
: public PaymentRequestBrowserTestBase {
protected:
PaymentRequestSameShippingAndContactAddressUseStatsTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(
PaymentRequestSameShippingAndContactAddressUseStatsTest);
};
// Tests that use stats for an address that was used both as a shipping and
// contact address in a Payment Request are properly updated upon completion.
IN_PROC_BROWSER_TEST_F(PaymentRequestSameShippingAndContactAddressUseStatsTest,
RecordUse) {
NavigateTo("/payment_request_contact_details_and_free_shipping_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Setup a credit card with an associated billing address.
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card); // Visa.
// Create an address with a higher frecency score, so that it is selected as
// the default shipping and contact address.
autofill::AutofillProfile multi_address = autofill::test::GetFullProfile2();
multi_address.set_use_count(3);
AddAutofillProfile(multi_address);
// Check that the initial use stats were set correctly.
autofill::AutofillProfile* initial_multi =
GetDataManager()->GetProfileByGUID(multi_address.guid());
EXPECT_EQ(3U, initial_multi->use_count());
EXPECT_EQ(kSomeDate, initial_multi->use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUI();
ResetEventWaiter(DialogEvent::DIALOG_CLOSED);
PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
// Check that the usage of the profile was only recorded once.
autofill::AutofillProfile* updated_multi =
GetDataManager()->GetProfileByGUID(multi_address.guid());
EXPECT_EQ(4U, updated_multi->use_count());
EXPECT_EQ(kSomeLaterDate, updated_multi->use_date());
}
} // namespace payments
|