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 "base/strings/utf_string_conversions.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 "components/autofill/core/browser/data_model/addresses/autofill_profile.h"
#include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments {
using PaymentRequestNoUpdateWithTest = PaymentRequestBrowserTestBase;
// A merchant that does not listen to shipping address update events will not
// cause timeouts in UI.
IN_PROC_BROWSER_TEST_F(PaymentRequestNoUpdateWithTest, BuyWithoutListeners) {
// 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_no_update_with_test.html");
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
AddAutofillProfile(autofill::test::GetFullProfile2());
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card);
InvokePaymentRequestUIWithJs(
content::JsReplace("buyWithoutListenersWithMethods([{supportedMethods:$1}"
", {supportedMethods:$2}]);",
a_method_name, b_method_name));
OpenShippingAddressSectionScreen();
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::SPEC_DONE_UPDATING,
DialogEvent::BACK_NAVIGATION});
ClickOnChildInListViewAndWait(
/* child_index=*/1, /*total_num_children=*/2,
DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW,
/*wait_for_animation=*/false);
// Wait for the animation here explicitly, otherwise
// ClickOnChildInListViewAndWait tries to install an AnimationDelegate before
// the animation is kicked off (since that's triggered off of the spec being
// updated) and this hits a DCHECK.
WaitForAnimation();
// Click on pay.
EXPECT_TRUE(IsPayButtonEnabled());
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ExpectBodyContains({"freeShipping"});
}
// A merchant that listens to shipping address update events, but does not call
// updateWith() on the event, will not cause timeouts in UI.
IN_PROC_BROWSER_TEST_F(PaymentRequestNoUpdateWithTest,
BuyWithoutCallingUpdateWith) {
// 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_no_update_with_test.html");
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
AddAutofillProfile(autofill::test::GetFullProfile2());
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card);
InvokePaymentRequestUIWithJs(
content::JsReplace("buyWithoutCallingUpdateWithWithMethods([{"
"supportedMethods:$1}, {supportedMethods:$2}]);",
a_method_name, b_method_name));
OpenShippingAddressSectionScreen();
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::SPEC_DONE_UPDATING,
DialogEvent::BACK_NAVIGATION});
ClickOnChildInListViewAndWait(
/* child_index=*/1, /*total_num_children=*/2,
DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW,
/*wait_for_animation=*/false);
// Wait for the animation here explicitly, otherwise
// ClickOnChildInListViewAndWait tries to install an AnimationDelegate before
// the animation is kicked off (since that's triggered off of the spec being
// updated) and this hits a DCHECK.
WaitForAnimation();
// Click on pay.
EXPECT_TRUE(IsPayButtonEnabled());
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ExpectBodyContains({"freeShipping"});
}
// A merchant that invokes updateWith() directly without using a promise will
// not cause timeouts in UI.
IN_PROC_BROWSER_TEST_F(PaymentRequestNoUpdateWithTest, BuyWithoutPromises) {
// 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_no_update_with_test.html");
autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
AddAutofillProfile(billing_address);
AddAutofillProfile(autofill::test::GetFullProfile2());
autofill::CreditCard card = autofill::test::GetCreditCard();
card.set_billing_address_id(billing_address.guid());
AddCreditCard(card);
InvokePaymentRequestUIWithJs(
content::JsReplace("buyWithoutPromisesWithMethods([{supportedMethods:$1},"
" {supportedMethods:$2}]);",
a_method_name, b_method_name));
OpenOrderSummaryScreen();
EXPECT_EQ(u"$5.00",
GetLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL));
ClickOnBackArrow();
OpenShippingAddressSectionScreen();
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::SPEC_DONE_UPDATING,
DialogEvent::BACK_NAVIGATION});
ClickOnChildInListViewAndWait(
/* child_index=*/1, /*total_num_children=*/2,
DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW,
/*wait_for_animation=*/false);
// Wait for the animation here explicitly, otherwise
// ClickOnChildInListViewAndWait tries to install an AnimationDelegate before
// the animation is kicked off (since that's triggered off of the spec being
// updated) and this hits a DCHECK.
WaitForAnimation();
OpenOrderSummaryScreen();
EXPECT_EQ(u"$10.00",
GetLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL));
ClickOnBackArrow();
// Click on pay.
EXPECT_TRUE(IsPayButtonEnabled());
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ExpectBodyContains({"updatedShipping"});
}
} // namespace payments
|