blob: 673e0361aede45e4faa016248850b677efe708d6 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Rouslan Solomakhin13947ae32020-05-22 15:34:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
7#include "build/build_config.h"
8#include "chrome/test/payments/payment_request_platform_browsertest_base.h"
9#include "content/public/test/browser_test.h"
10#include "content/public/test/browser_test_utils.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace payments {
14namespace {
15
16class AbortPaymentHandlerTest : public PaymentRequestPlatformBrowserTestBase {};
17
Alison Gale079e6e952024-04-16 22:00:3018// TODO(crbug.com/40720284): fix flakiness and reenable
Xiaohan Wang735e98922022-01-15 23:56:5119#if BUILDFLAG(IS_MAC)
Collin Baker4b413cb2020-09-17 21:21:1620#define MAYBE_CanAbortInvokedInstalledPaymentHandler \
21 DISABLED_CanAbortInvokedInstalledPaymentHandler
22#else
23#define MAYBE_CanAbortInvokedInstalledPaymentHandler \
24 CanAbortInvokedInstalledPaymentHandler
25#endif
26
Rouslan Solomakhin13947ae32020-05-22 15:34:2927IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
Collin Baker4b413cb2020-09-17 21:21:1628 MAYBE_CanAbortInvokedInstalledPaymentHandler) {
Rouslan Solomakhin1f7d64bd2022-11-21 14:41:3329 std::string method_name;
30 InstallPaymentApp("a.com", "/abort_responder_app.js", &method_name);
Rouslan Solomakhin13947ae32020-05-22 15:34:2931
32 NavigateTo("b.com", "/payment_handler_aborter.html");
33 EXPECT_EQ(
34 "Abort completed",
35 content::EvalJs(GetActiveWebContents(),
36 content::JsReplace("launchAndAbort($1, $2)", method_name,
37 /*abortResponse=*/true)));
38}
39
Rouslan Solomakhin13947ae32020-05-22 15:34:2940IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
Rouslan Solomakhin80574b52020-06-04 21:59:1541 CanAbortInvokedJitPaymentHandler) {
Rouslan Solomakhin13947ae32020-05-22 15:34:2942 std::string method_name =
43 https_server()->GetURL("a.com", "/abort_responder_app.json").spec();
44 ASSERT_NE('/', method_name[method_name.length() - 1]);
45
46 NavigateTo("b.com", "/payment_handler_aborter.html");
47 EXPECT_EQ(
48 "Abort completed",
49 content::EvalJs(GetActiveWebContents(),
50 content::JsReplace("launchAndAbort($1, $2)", method_name,
51 /*abortResponse=*/true)));
52}
53
54IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
55 InstalledPaymentHandlerCanRefuseAbort) {
Rouslan Solomakhin1f7d64bd2022-11-21 14:41:3356 std::string method_name;
57 InstallPaymentApp("a.com", "/abort_responder_app.js", &method_name);
Rouslan Solomakhin13947ae32020-05-22 15:34:2958
59 NavigateTo("b.com", "/payment_handler_aborter.html");
60 EXPECT_EQ(
Nate Chapinde8ea272024-03-15 17:51:5961 "Failed to execute 'abort' on 'PaymentRequest': Unable to abort the "
62 "payment",
Rouslan Solomakhin13947ae32020-05-22 15:34:2963 content::EvalJs(GetActiveWebContents(),
64 content::JsReplace("launchAndAbort($1, $2)", method_name,
65 /*abortResponse=*/false)));
66}
67
68IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
69 JitPaymentHandlerCanRefuseAbort) {
70 std::string method_name =
71 https_server()->GetURL("a.com", "/abort_responder_app.json").spec();
72 ASSERT_NE('/', method_name[method_name.length() - 1]);
73
74 NavigateTo("b.com", "/payment_handler_aborter.html");
75 EXPECT_EQ(
Nate Chapinde8ea272024-03-15 17:51:5976 "Failed to execute 'abort' on 'PaymentRequest': Unable to abort the "
77 "payment",
Rouslan Solomakhin13947ae32020-05-22 15:34:2978 content::EvalJs(GetActiveWebContents(),
79 content::JsReplace("launchAndAbort($1, $2)", method_name,
80 /*abortResponse=*/false)));
81}
82
83} // namespace
84} // namespace payments