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
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/buildflag.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/data_manager/addresses/address_data_manager.h"
#include "components/autofill/core/browser/data_manager/addresses/address_data_manager_test_utils.h"
#include "components/autofill/core/browser/data_manager/personal_data_manager.h"
#include "components/autofill/core/browser/data_model/addresses/autofill_profile.h"
#include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
#include "components/autofill/core/browser/test_utils/test_autofill_clock.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
namespace payments {
namespace {
const base::Time kSomeDate = base::Time::FromSecondsSinceUnixEpoch(1484505871);
const base::Time kSomeLaterDate =
base::Time::FromSecondsSinceUnixEpoch(1497552271);
} // namespace
using PaymentRequestShippingAddressUseStatsTest = PaymentRequestBrowserTestBase;
// Tests that use stats for the shipping address used in a Payment Request are
// properly updated upon completion.
// Flaky. https://crbug.com/1495539.
IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressUseStatsTest,
DISABLED_RecordUse) {
std::string payment_method_name;
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);
NavigateTo("/payment_request_free_shipping_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Create two addresses, one with a higher frequency score so that it is
// selected as the default shipping address.
autofill::AutofillProfile shipping_address1 =
autofill::test::GetFullProfile();
AddAutofillProfile(shipping_address1);
autofill::AutofillProfile shipping_address2 =
autofill::test::GetFullProfile2();
shipping_address2.usage_history().set_use_count(3);
AddAutofillProfile(shipping_address2);
// Check that the initial use stats were set correctly.
const autofill::AutofillProfile* initial_shipping =
address_data_manager()->GetProfileByGUID(shipping_address2.guid());
EXPECT_EQ(3U, initial_shipping->usage_history().use_count());
EXPECT_EQ(kSomeDate, initial_shipping->usage_history().use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUIWithJs("buyWithMethods([{supportedMethods:'" +
payment_method_name + "'}]);");
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
autofill::AddressDataChangedWaiter(address_data_manager()).Wait();
// Check that the usage of the profile was recorded.
const autofill::AutofillProfile* updated_shipping =
address_data_manager()->GetProfileByGUID(shipping_address2.guid());
EXPECT_EQ(4U, updated_shipping->usage_history().use_count());
EXPECT_EQ(kSomeLaterDate, updated_shipping->usage_history().use_date());
}
using PaymentRequestContactAddressUseStatsTest = PaymentRequestBrowserTestBase;
// Tests that use stats for the contact address used in a Payment Request are
// properly updated upon completion.
// Flaky. https://crbug.com/1495539.
IN_PROC_BROWSER_TEST_F(PaymentRequestContactAddressUseStatsTest,
DISABLED_RecordUse) {
std::string payment_method_name;
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);
NavigateTo("/payment_request_name_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Create two addresses, one with a higher frequency score so that it is
// selected as the default contact address.
autofill::AutofillProfile contact_address1 = autofill::test::GetFullProfile();
AddAutofillProfile(contact_address1);
autofill::AutofillProfile contact_address2 =
autofill::test::GetFullProfile2();
contact_address2.usage_history().set_use_count(3);
AddAutofillProfile(contact_address2);
// Check that the initial use stats were set correctly.
const autofill::AutofillProfile* initial_contact =
address_data_manager()->GetProfileByGUID(contact_address2.guid());
EXPECT_EQ(3U, initial_contact->usage_history().use_count());
EXPECT_EQ(kSomeDate, initial_contact->usage_history().use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUIWithJs("buyWithMethods([{supportedMethods:'" +
payment_method_name + "'}]);");
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
autofill::AddressDataChangedWaiter(address_data_manager()).Wait();
// Check that the usage of the profile was recorded.
const autofill::AutofillProfile* updated_contact =
address_data_manager()->GetProfileByGUID(contact_address2.guid());
EXPECT_EQ(4U, updated_contact->usage_history().use_count());
EXPECT_EQ(kSomeLaterDate, updated_contact->usage_history().use_date());
}
using PaymentRequestSameShippingAndContactAddressUseStatsTest =
PaymentRequestBrowserTestBase;
// 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.
// Flaky. https://crbug.com/1495539.
IN_PROC_BROWSER_TEST_F(PaymentRequestSameShippingAndContactAddressUseStatsTest,
DISABLED_RecordUse) {
std::string payment_method_name;
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);
NavigateTo("/payment_request_contact_details_and_free_shipping_test.html");
autofill::TestAutofillClock test_clock;
test_clock.SetNow(kSomeDate);
// Create two addresses, one with a higher frequency score so that it is
// selected as the default shipping and contact address.
autofill::AutofillProfile multi_address1 = autofill::test::GetFullProfile();
AddAutofillProfile(multi_address1);
autofill::AutofillProfile multi_address2 = autofill::test::GetFullProfile2();
multi_address2.usage_history().set_use_count(3);
AddAutofillProfile(multi_address2);
// Check that the initial use stats were set correctly.
const autofill::AutofillProfile* initial_multi =
address_data_manager()->GetProfileByGUID(multi_address2.guid());
EXPECT_EQ(3U, initial_multi->usage_history().use_count());
EXPECT_EQ(kSomeDate, initial_multi->usage_history().use_date());
// Complete the Payment Request.
test_clock.SetNow(kSomeLaterDate);
InvokePaymentRequestUIWithJs("buyWithMethods([{supportedMethods:'" +
payment_method_name + "'}]);");
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
autofill::AddressDataChangedWaiter(address_data_manager()).Wait();
// Check that the usage of the profile was only recorded once.
const autofill::AutofillProfile* updated_multi =
address_data_manager()->GetProfileByGUID(multi_address2.guid());
EXPECT_EQ(4U, updated_multi->usage_history().use_count());
EXPECT_EQ(kSomeLaterDate, updated_multi->usage_history().use_date());
}
} // namespace payments
|