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
|
// 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 "base/test/scoped_feature_list.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_model/addresses/autofill_profile.h"
#include "components/autofill/core/browser/data_model/payments/credit_card.h"
#include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
namespace payments {
using PaymentRequestPaymentResponseShippingAddressTest =
PaymentRequestBrowserTestBase;
// Tests that the PaymentResponse contains all the required fields for a
// shipping address and shipping option.
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentResponseShippingAddressTest,
TestPaymentResponse) {
std::string payment_method_name;
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);
NavigateTo("/payment_request_free_shipping_test.html");
// Create two shipping 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(2000);
AddAutofillProfile(shipping_address2);
// Complete the Payment Request.
InvokePaymentRequestUIWithJs("buyWithMethods([{supportedMethods:'" +
payment_method_name + "'}]);");
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ASSERT_TRUE(WaitForObservedEvent());
// Test that the shipping address was sent to the merchant.
ExpectBodyContains(
{"\"country\": \"US\"", "\"123 Main Street\"", "\"Unit 1\"",
"\"region\": \"MI\"", "\"city\": \"Greensdale\"",
"\"dependentLocality\": \"\"", "\"postalCode\": \"48838\"",
"\"sortingCode\": \"\"", "\"organization\": \"ACME\"",
"\"recipient\": \"Jane A. Smith\"", "\"phone\": \"+13105557889\""});
// Test that the shipping option was sent to the merchant.
ExpectBodyContains({"\"shippingOption\": \"freeShippingOption\""});
}
using PaymentRequestPaymentResponseAllContactDetailsTest =
PaymentRequestBrowserTestBase;
// Tests that the PaymentResponse contains all the required fields for contact
// details when all three details are requested.
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentResponseAllContactDetailsTest,
TestPaymentResponse) {
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::AutofillProfile address = autofill::test::GetFullProfile();
AddAutofillProfile(address);
// Complete the Payment Request.
InvokePaymentRequestUIWithJs("buyWithMethods([{supportedMethods:'" +
payment_method_name + "'}]);");
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ASSERT_TRUE(WaitForObservedEvent());
// Test that the contact details were sent to the merchant.
ExpectBodyContains({"\"payerName\": \"John H. Doe\"",
"\"payerEmail\": \"johndoe@hades.com\"",
"\"payerPhone\": \"+16502111111\""});
}
// Tests that the PaymentResponse contains all the correct contact details
// when user changes the selected contact information after retry() called once.
IN_PROC_BROWSER_TEST_F(
PaymentRequestPaymentResponseAllContactDetailsTest,
RetryWithPayerErrors_HasSameValueButDifferentErrorsShown) {
// Installs two apps so that the Payment Request UI will be shown.
std::string a_method_name;
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);
NavigateTo("/payment_request_retry_with_payer_errors.html");
autofill::AutofillProfile contact = autofill::test::GetFullProfile();
contact.usage_history().set_use_count(1000);
AddAutofillProfile(contact);
autofill::AutofillProfile contact2 = autofill::test::GetFullProfile2();
AddAutofillProfile(contact2);
// Show a Payment Request.
InvokePaymentRequestUIWithJs(
content::JsReplace("buyWithMethods([{supportedMethods:$1}"
", {supportedMethods:$2}]);",
a_method_name, b_method_name));
// Click on pay.
EXPECT_TRUE(IsPayButtonEnabled());
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ASSERT_TRUE(
content::ExecJs(GetActiveWebContents(), "processShowResponse();"));
ExpectBodyContains({"\"payerName\": \"John H. Doe\"",
"\"payerEmail\": \"johndoe@hades.com\"",
"\"payerPhone\": \"+16502111111\""});
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::SPEC_DONE_UPDATING,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::BACK_TO_PAYMENT_SHEET_NAVIGATION});
ASSERT_TRUE(content::ExecJs(GetActiveWebContents(), "retry({});"));
// Select "contact2" profile
OpenContactInfoScreen();
views::View* list_view = dialog_view()->GetViewByID(
static_cast<int>(DialogViewID::CONTACT_INFO_SHEET_LIST_VIEW));
DCHECK(list_view);
ClickOnDialogViewAndWait(list_view->children()[1]);
ExpectBodyContains({"\"payerName\": \"Jane A. Smith\"",
"\"payerEmail\": \"jsmith@example.com\"",
"\"payerPhone\": \"+13105557889\""});
}
using PaymentRequestPaymentResponseOneContactDetailTest =
PaymentRequestBrowserTestBase;
// Tests that the PaymentResponse contains all the required fields for contact
// details when all ont detail is requested.
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentResponseOneContactDetailTest,
TestPaymentResponse) {
std::string payment_method_name;
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);
NavigateTo("/payment_request_email_and_free_shipping_test.html");
autofill::AutofillProfile address = autofill::test::GetFullProfile();
AddAutofillProfile(address);
// Complete the Payment Request.
InvokePaymentRequestUIWithJs("buyWithMethods([{supportedMethods:'" +
payment_method_name + "'}]);");
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ASSERT_TRUE(WaitForObservedEvent());
// Test that the contact details were sent to the merchant.
ExpectBodyContains({"\"payerName\": null",
"\"payerEmail\": \"johndoe@hades.com\"",
"\"payerPhone\": null"});
}
} // namespace payments
|