blob: a6022930842c7dacfb5681ff0ab0b4d338d6dc22 [file] [log] [blame]
Rouslan Solomakhin13947ae32020-05-22 15:34:291// Copyright 2020 The Chromium Authors. All rights reserved.
2// 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
Collin Baker4b413cb2020-09-17 21:21:1618// TODO(crbug.com/1129578): 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 Solomakhin13947ae32020-05-22 15:34:2929 std::string method_name = https_server()->GetURL("a.com", "/").spec();
30 method_name = method_name.substr(0, method_name.length() - 1);
31 ASSERT_NE('/', method_name[method_name.length() - 1]);
32 NavigateTo("a.com", "/payment_handler_installer.html");
33 ASSERT_EQ("success", content::EvalJs(
34 GetActiveWebContents(),
35 content::JsReplace(
36 "install('abort_responder_app.js', [$1], false)",
37 method_name)));
38
39 NavigateTo("b.com", "/payment_handler_aborter.html");
40 EXPECT_EQ(
41 "Abort completed",
42 content::EvalJs(GetActiveWebContents(),
43 content::JsReplace("launchAndAbort($1, $2)", method_name,
44 /*abortResponse=*/true)));
45}
46
Rouslan Solomakhin13947ae32020-05-22 15:34:2947IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
Rouslan Solomakhin80574b52020-06-04 21:59:1548 CanAbortInvokedJitPaymentHandler) {
Rouslan Solomakhin13947ae32020-05-22 15:34:2949 std::string method_name =
50 https_server()->GetURL("a.com", "/abort_responder_app.json").spec();
51 ASSERT_NE('/', method_name[method_name.length() - 1]);
52
53 NavigateTo("b.com", "/payment_handler_aborter.html");
54 EXPECT_EQ(
55 "Abort completed",
56 content::EvalJs(GetActiveWebContents(),
57 content::JsReplace("launchAndAbort($1, $2)", method_name,
58 /*abortResponse=*/true)));
59}
60
61IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
62 InstalledPaymentHandlerCanRefuseAbort) {
63 std::string method_name = https_server()->GetURL("a.com", "/").spec();
64 method_name = method_name.substr(0, method_name.length() - 1);
65 ASSERT_NE('/', method_name[method_name.length() - 1]);
66 NavigateTo("a.com", "/payment_handler_installer.html");
67 ASSERT_EQ("success", content::EvalJs(
68 GetActiveWebContents(),
69 content::JsReplace(
70 "install('abort_responder_app.js', [$1], false)",
71 method_name)));
72
73 NavigateTo("b.com", "/payment_handler_aborter.html");
74 EXPECT_EQ(
75 "Unable to abort the payment",
76 content::EvalJs(GetActiveWebContents(),
77 content::JsReplace("launchAndAbort($1, $2)", method_name,
78 /*abortResponse=*/false)));
79}
80
81IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
82 JitPaymentHandlerCanRefuseAbort) {
83 std::string method_name =
84 https_server()->GetURL("a.com", "/abort_responder_app.json").spec();
85 ASSERT_NE('/', method_name[method_name.length() - 1]);
86
87 NavigateTo("b.com", "/payment_handler_aborter.html");
88 EXPECT_EQ(
89 "Unable to abort the payment",
90 content::EvalJs(GetActiveWebContents(),
91 content::JsReplace("launchAndAbort($1, $2)", method_name,
92 /*abortResponse=*/false)));
93}
94
95} // namespace
96} // namespace payments