Skip to content

Commit

Permalink
[Web Payment] Test-only installer for Service Worker Payment Handlers
Browse files Browse the repository at this point in the history
This patch changes the Web Payment common test scaffolding to install
payment handlers directly via a C++ utility method, instead of the old
method of using the JavaScript PaymentInstruments API that is slated to
be removed.

Bug: 1327265
Change-Id: I93754f69f014ccf18826160abde30db02f0f9119
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4038641
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1076216}
  • Loading branch information
rsolomakhin authored and Chromium LUCI CQ committed Nov 28, 2022
1 parent 429d21a commit 4cba515
Show file tree
Hide file tree
Showing 32 changed files with 323 additions and 201 deletions.
1 change: 1 addition & 0 deletions chrome/browser/payments/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ source_set("browser_tests") {

if (!is_android) {
sources += [
"capability_delegation_browsertest.cc",
"manifest_verifier_browsertest.cc",
"payment_manifest_parser_browsertest.cc",
"secure_payment_confirmation_authenticator_browsertest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ IN_PROC_BROWSER_TEST_F(CapabilityDelegationBrowserTest,
// Install a payment app that responds to the abortpayment event, which is
// used by this test to determine that the app was successfully run.
std::string payment_method;
InstallPaymentApp("a.com", "abort_responder_app.js", &payment_method);
InstallPaymentApp("a.com", "/abort_responder_app.js", &payment_method);

// Navigate the top frame.
GURL main_url(
Expand Down Expand Up @@ -122,7 +122,7 @@ IN_PROC_BROWSER_TEST_F(CapabilityDelegationBrowserTest,
// Install a payment app that responds to the abortpayment event, which is
// used by this test to determine that the app was successfully run.
std::string payment_method;
InstallPaymentApp("a.com", "abort_responder_app.js", &payment_method);
InstallPaymentApp("a.com", "/abort_responder_app.js", &payment_method);

// Navigate the top frame.
GURL main_url(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PaymentRequestCanMakePaymentQueryTest
IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
AppRespondsFalseToCanMakePaymentEvent) {
std::string method;
InstallPaymentApp("a.com", "can_make_payment_false_responder.js", &method);
InstallPaymentApp("a.com", "/can_make_payment_false_responder.js", &method);

NavigateTo("b.com", "/payment_request_can_make_payment_query_test.html");

Expand All @@ -51,7 +51,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
AppRespondsTrueToCanMakePaymentEvent) {
std::string method;
InstallPaymentApp("a.com", "can_make_payment_true_responder.js", &method);
InstallPaymentApp("a.com", "/can_make_payment_true_responder.js", &method);

NavigateTo("b.com", "/payment_request_can_make_payment_query_test.html");

Expand All @@ -66,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
IncognitoModeWithInstalledPaymentHandler) {
std::string method;
InstallPaymentApp("a.com", "can_make_payment_true_responder.js", &method);
InstallPaymentApp("a.com", "/can_make_payment_true_responder.js", &method);

NavigateTo("b.com", "/payment_request_can_make_payment_query_test.html");
test_controller()->SetOffTheRecord(true);
Expand Down Expand Up @@ -111,7 +111,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
test_controller()->SetCanMakePaymentEnabledPref(false);

std::string method;
InstallPaymentApp("a.com", "can_make_payment_true_responder.js", &method);
InstallPaymentApp("a.com", "/can_make_payment_true_responder.js", &method);

NavigateTo("b.com", "/payment_request_can_make_payment_query_test.html");

Expand All @@ -124,7 +124,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest,
// show().
IN_PROC_BROWSER_TEST_F(PaymentRequestCanMakePaymentQueryTest, InvalidSSL) {
std::string method;
InstallPaymentApp("a.com", "payment_request_success_responder.js", &method);
InstallPaymentApp("a.com", "/payment_request_success_responder.js", &method);

NavigateTo("b.com", "/payment_request_can_make_payment_query_test.html");
test_controller()->SetValidSsl(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class MAYBE_PaymentRequestContactInfoEditorTest
IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest, HappyPath) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_contact_details_test.html");
Expand Down Expand Up @@ -106,10 +106,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
EnterAcceleratorHappyPath) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_contact_details_test.html");
Expand Down Expand Up @@ -159,10 +159,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest, Validation) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_contact_details_test.html");
Expand Down Expand Up @@ -226,10 +226,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
ModifyExisting) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_contact_details_test.html");
Expand Down Expand Up @@ -286,10 +286,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
ModifyExistingSelectsIt) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_contact_details_test.html");
Expand Down Expand Up @@ -354,10 +354,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
HappyPathInIncognito) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

SetIncognito();
Expand Down Expand Up @@ -410,10 +410,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
RetryWithPayerErrors) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_retry_with_payer_errors.html");
Expand Down Expand Up @@ -462,10 +462,10 @@ IN_PROC_BROWSER_TEST_F(
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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_retry_with_payer_errors.html");
Expand Down Expand Up @@ -516,10 +516,10 @@ IN_PROC_BROWSER_TEST_F(MAYBE_PaymentRequestContactInfoEditorTest,
RetryWithPayerErrors_NoPaymentOptions) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_retry_with_no_payment_options.html");
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/payments/empty_update_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ using PaymentRequestEmptyUpdateTest = PaymentRequestBrowserTestBase;
IN_PROC_BROWSER_TEST_F(PaymentRequestEmptyUpdateTest, NoCrash) {
// Installs two apps to ensure that the payment request UI is shown.
std::string a_method_name;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_empty_update_test.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using PaymentRequestErrorMessageTest = PaymentRequestBrowserTestBase;
// Testing the use of the complete('fail') JS API and the error message.
IN_PROC_BROWSER_TEST_F(PaymentRequestErrorMessageTest, CompleteFail) {
std::string payment_method_name;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);

NavigateTo("/payment_request_fail_complete_test.html");
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/ui/views/payments/modifiers_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestModifiersTest,
// without an icon - this makes ServiceWorkerPaymentApp::CanPreselect false
// for it and so the other app should be selected.
std::string payment_method_name_1;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name_1);
std::string payment_method_name_2;
InstallPaymentAppWithoutIcon("b.com", "payment_request_success_responder.js",
InstallPaymentAppWithoutIcon("b.com", "/payment_request_success_responder.js",
&payment_method_name_2);

NavigateTo("/payment_request_with_modifiers_test.html");
Expand All @@ -70,10 +70,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestModifiersTest,
// The modifier without the total applies to the first method; to make sure
// that it is always selected we install the second method without an icon.
std::string payment_method_name_1;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name_1);
std::string payment_method_name_2;
InstallPaymentAppWithoutIcon("b.com", "payment_request_success_responder.js",
InstallPaymentAppWithoutIcon("b.com", "/payment_request_success_responder.js",
&payment_method_name_2);

NavigateTo("/payment_request_with_modifiers_test.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using PaymentRequestOrderSummaryViewControllerTest =
IN_PROC_BROWSER_TEST_F(PaymentRequestOrderSummaryViewControllerTest,
OrderSummaryReflectsShippingOption) {
std::string payment_method_name;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&payment_method_name);

NavigateTo("/payment_request_dynamic_shipping_test.html");
Expand Down
28 changes: 14 additions & 14 deletions chrome/browser/ui/views/payments/payment_request_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class PaymentRequestNoShippingTest : public PaymentRequestBrowserTestBase {
void OpenPaymentRequestDialog() {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_no_shipping_test.html");
Expand Down Expand Up @@ -108,10 +108,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest,

IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, InactiveBrowserWindow) {
std::string a_method_name;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_no_shipping_test.html");
Expand All @@ -128,10 +128,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, InactiveBrowserWindow) {

IN_PROC_BROWSER_TEST_F(PaymentRequestNoShippingTest, InvalidSSL) {
std::string a_method_name;
InstallPaymentApp("a.com", "payment_request_success_responder.js",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_no_shipping_test.html");
Expand All @@ -152,10 +152,10 @@ using PaymentRequestAbortTest = PaymentRequestBrowserTestBase;
IN_PROC_BROWSER_TEST_F(PaymentRequestAbortTest, OpenThenAbort) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_abort_test.html");
Expand Down Expand Up @@ -188,10 +188,10 @@ using PaymentRequestPaymentMethodIdentifierTest = PaymentRequestBrowserTestBase;
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest, Url_Valid) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_payment_method_identifier_test.html");
Expand Down Expand Up @@ -239,10 +239,10 @@ class PaymentsRequestVisualTest
IN_PROC_BROWSER_TEST_F(PaymentsRequestVisualTest, InvokeUi_NoShipping) {
// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name_);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name_);

NavigateTo("/payment_request_no_shipping_test.html");
Expand All @@ -261,10 +261,10 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestSettingsLinkTest, ClickSettingsLink) {

// 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",
InstallPaymentApp("a.com", "/payment_request_success_responder.js",
&a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "payment_request_success_responder.js",
InstallPaymentApp("b.com", "/payment_request_success_responder.js",
&b_method_name);

NavigateTo("/payment_request_no_shipping_test.html");
Expand Down

0 comments on commit 4cba515

Please sign in to comment.