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 "chrome/test/payments/payment_request_platform_browsertest_base.h"
6 #include "content/public/test/browser_test.h"
7 
8 namespace payments {
9 
10 namespace {
11 
12 class PaymentHandlerUninstallTest
13     : public PaymentRequestPlatformBrowserTestBase {
14  protected:
15   PaymentHandlerUninstallTest() = default;
16   ~PaymentHandlerUninstallTest() override = default;
17 
SetUpOnMainThread()18   void SetUpOnMainThread() override {
19     PaymentRequestPlatformBrowserTestBase::SetUpOnMainThread();
20     NavigateTo("/payment_handler.html");
21   }
22 };
23 
IN_PROC_BROWSER_TEST_F(PaymentHandlerUninstallTest,URLBasedPaymentMethod)24 IN_PROC_BROWSER_TEST_F(PaymentHandlerUninstallTest, URLBasedPaymentMethod) {
25   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(), "install()"));
26 
27   // Launch the payment request and confirm checkout completion.
28   ResetEventWaiterForSingleEvent(TestEvent::kPaymentCompleted);
29   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(), "launch()"));
30   WaitForObservedEvent();
31 
32   // Uninstall the payment app and verify that a new request.show() gets
33   // rejected after the app uninstallation.
34   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(), "uninstall()"));
35   ResetEventWaiterForSingleEvent(TestEvent::kNotSupportedError);
36   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(),
37                                        "launchWithoutWaitForResponse()"));
38   WaitForObservedEvent();
39 }
40 
IN_PROC_BROWSER_TEST_F(PaymentHandlerUninstallTest,BasicCard)41 IN_PROC_BROWSER_TEST_F(PaymentHandlerUninstallTest, BasicCard) {
42   EXPECT_EQ("success",
43             content::EvalJs(GetActiveWebContents(), "install('basic-card')"));
44 
45   // Launch the payment request and validate that one app is available.
46   ResetEventWaiterForSingleEvent(TestEvent::kAppListReady);
47   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(),
48                                        "launchWithoutWaitForResponse()"));
49   WaitForObservedEvent();
50   EXPECT_EQ(1u, test_controller()->app_descriptions().size());
51 
52   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(), "abort()"));
53 
54   // Uninstall the payment app and verify that there is no payment app
55   // available. A new request.show() will not get rejected though since the user
56   // will still have the option to add a credit card.
57   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(), "uninstall()"));
58   ResetEventWaiterForSingleEvent(TestEvent::kAppListReady);
59   EXPECT_EQ("success", content::EvalJs(GetActiveWebContents(),
60                                        "launchWithoutWaitForResponse()"));
61   WaitForObservedEvent();
62   EXPECT_EQ(0u, test_controller()->app_descriptions().size());
63 }
64 
65 }  // namespace
66 
67 }  // namespace payments
68