Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 1 | // 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 | |
| 13 | namespace payments { |
| 14 | namespace { |
| 15 | |
| 16 | class AbortPaymentHandlerTest : public PaymentRequestPlatformBrowserTestBase {}; |
| 17 | |
Collin Baker | 4b413cb | 2020-09-17 21:21:16 | [diff] [blame] | 18 | // TODO(crbug.com/1129578): fix flakiness and reenable |
Xiaohan Wang | 735e9892 | 2022-01-15 23:56:51 | [diff] [blame^] | 19 | #if BUILDFLAG(IS_MAC) |
Collin Baker | 4b413cb | 2020-09-17 21:21:16 | [diff] [blame] | 20 | #define MAYBE_CanAbortInvokedInstalledPaymentHandler \ |
| 21 | DISABLED_CanAbortInvokedInstalledPaymentHandler |
| 22 | #else |
| 23 | #define MAYBE_CanAbortInvokedInstalledPaymentHandler \ |
| 24 | CanAbortInvokedInstalledPaymentHandler |
| 25 | #endif |
| 26 | |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 27 | IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest, |
Collin Baker | 4b413cb | 2020-09-17 21:21:16 | [diff] [blame] | 28 | MAYBE_CanAbortInvokedInstalledPaymentHandler) { |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 29 | 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 Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 47 | IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest, |
Rouslan Solomakhin | 80574b5 | 2020-06-04 21:59:15 | [diff] [blame] | 48 | CanAbortInvokedJitPaymentHandler) { |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 49 | 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 | |
| 61 | IN_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 | |
| 81 | IN_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 |