Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 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 | |
Alison Gale | 079e6e95 | 2024-04-16 22:00:30 | [diff] [blame] | 18 | // TODO(crbug.com/40720284): 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 | 1f7d64bd | 2022-11-21 14:41:33 | [diff] [blame] | 29 | std::string method_name; |
| 30 | InstallPaymentApp("a.com", "/abort_responder_app.js", &method_name); |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 31 | |
| 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 Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 40 | IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest, |
Rouslan Solomakhin | 80574b5 | 2020-06-04 21:59:15 | [diff] [blame] | 41 | CanAbortInvokedJitPaymentHandler) { |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 42 | 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 | |
| 54 | IN_PROC_BROWSER_TEST_F(AbortPaymentHandlerTest, |
| 55 | InstalledPaymentHandlerCanRefuseAbort) { |
Rouslan Solomakhin | 1f7d64bd | 2022-11-21 14:41:33 | [diff] [blame] | 56 | std::string method_name; |
| 57 | InstallPaymentApp("a.com", "/abort_responder_app.js", &method_name); |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 58 | |
| 59 | NavigateTo("b.com", "/payment_handler_aborter.html"); |
| 60 | EXPECT_EQ( |
Nate Chapin | de8ea27 | 2024-03-15 17:51:59 | [diff] [blame] | 61 | "Failed to execute 'abort' on 'PaymentRequest': Unable to abort the " |
| 62 | "payment", |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 63 | content::EvalJs(GetActiveWebContents(), |
| 64 | content::JsReplace("launchAndAbort($1, $2)", method_name, |
| 65 | /*abortResponse=*/false))); |
| 66 | } |
| 67 | |
| 68 | IN_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 Chapin | de8ea27 | 2024-03-15 17:51:59 | [diff] [blame] | 76 | "Failed to execute 'abort' on 'PaymentRequest': Unable to abort the " |
| 77 | "payment", |
Rouslan Solomakhin | 13947ae3 | 2020-05-22 15:34:29 | [diff] [blame] | 78 | content::EvalJs(GetActiveWebContents(), |
| 79 | content::JsReplace("launchAndAbort($1, $2)", method_name, |
| 80 | /*abortResponse=*/false))); |
| 81 | } |
| 82 | |
| 83 | } // namespace |
| 84 | } // namespace payments |