blob: 3338372c7343f398d61110025b0b29a083a3dc6c [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
18IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
19 CanAbortInvokedInstalledPaymentHandler) {
20 std::string method_name = https_server()->GetURL("a.com", "/").spec();
21 method_name = method_name.substr(0, method_name.length() - 1);
22 ASSERT_NE('/', method_name[method_name.length() - 1]);
23 NavigateTo("a.com", "/payment_handler_installer.html");
24 ASSERT_EQ("success", content::EvalJs(
25 GetActiveWebContents(),
26 content::JsReplace(
27 "install('abort_responder_app.js', [$1], false)",
28 method_name)));
29
30 NavigateTo("b.com", "/payment_handler_aborter.html");
31 EXPECT_EQ(
32 "Abort completed",
33 content::EvalJs(GetActiveWebContents(),
34 content::JsReplace("launchAndAbort($1, $2)", method_name,
35 /*abortResponse=*/true)));
36}
37
38// TODO(crbug.com/1083242): Andorid implementation of
39// ServiceWorkerPaymentApp.java is unable to abort payments for invoked
40// just-in-time installed payment handlers. When ServiceWorkerPaymentApp.java is
41// replaced with JniPaymentApp.java that owns an instance of the correctly
42// working service_worker_payment_app.cc, this test should be enabled on
43// Android.
44#if defined(OS_ANDROID)
45#define MAYBE_CanAbortInvokedJitPaymentHandler \
46 DISABLED_CanAbortInvokedJitPaymentHandler
47#else
48#define MAYBE_CanAbortInvokedJitPaymentHandler CanAbortInvokedJitPaymentHandler
49#endif // OS_ANDROID
50IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
51 MAYBE_CanAbortInvokedJitPaymentHandler) {
52 std::string method_name =
53 https_server()->GetURL("a.com", "/abort_responder_app.json").spec();
54 ASSERT_NE('/', method_name[method_name.length() - 1]);
55
56 NavigateTo("b.com", "/payment_handler_aborter.html");
57 EXPECT_EQ(
58 "Abort completed",
59 content::EvalJs(GetActiveWebContents(),
60 content::JsReplace("launchAndAbort($1, $2)", method_name,
61 /*abortResponse=*/true)));
62}
63
64IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
65 InstalledPaymentHandlerCanRefuseAbort) {
66 std::string method_name = https_server()->GetURL("a.com", "/").spec();
67 method_name = method_name.substr(0, method_name.length() - 1);
68 ASSERT_NE('/', method_name[method_name.length() - 1]);
69 NavigateTo("a.com", "/payment_handler_installer.html");
70 ASSERT_EQ("success", content::EvalJs(
71 GetActiveWebContents(),
72 content::JsReplace(
73 "install('abort_responder_app.js', [$1], false)",
74 method_name)));
75
76 NavigateTo("b.com", "/payment_handler_aborter.html");
77 EXPECT_EQ(
78 "Unable to abort the payment",
79 content::EvalJs(GetActiveWebContents(),
80 content::JsReplace("launchAndAbort($1, $2)", method_name,
81 /*abortResponse=*/false)));
82}
83
84IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest,
85 JitPaymentHandlerCanRefuseAbort) {
86 std::string method_name =
87 https_server()->GetURL("a.com", "/abort_responder_app.json").spec();
88 ASSERT_NE('/', method_name[method_name.length() - 1]);
89
90 NavigateTo("b.com", "/payment_handler_aborter.html");
91 EXPECT_EQ(
92 "Unable to abort the payment",
93 content::EvalJs(GetActiveWebContents(),
94 content::JsReplace("launchAndAbort($1, $2)", method_name,
95 /*abortResponse=*/false)));
96}
97
98} // namespace
99} // namespace payments