File: android_payment_app_factory_browsertest.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (178 lines) | stat: -rw-r--r-- 6,895 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/test/scoped_feature_list.h"
#include "chrome/test/payments/payment_app_install_util.h"
#include "chrome/test/payments/payment_request_platform_browsertest_base.h"
#include "components/payments/core/features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/ash/experiences/arc/overlay/arc_overlay_manager.h"
#endif

namespace payments {
namespace {

struct [[maybe_unused]] ScopedTestSupport {
#if BUILDFLAG(IS_CHROMEOS)
  // Invoking Play Billing on Chrome OS requires initializing the overlay
  // manager.
  ash::ArcOverlayManager overlay_manager;
#endif
};

class AndroidPaymentAppFactoryTest
    : public PaymentRequestPlatformBrowserTestBase {
 public:
  AndroidPaymentAppFactoryTest() {
    feature_list_.InitAndEnableFeature(features::kAppStoreBilling);
  }

  ~AndroidPaymentAppFactoryTest() override = default;

  // PaymentRequestTestObserver:
  void OnUIDisplayed() override {
    PaymentRequestPlatformBrowserTestBase::OnUIDisplayed();
    FAIL() << "Browser UI should never be displayed for Android payment apps "
              "invoked here.";
  }

 private:
  base::test::ScopedFeatureList feature_list_;
};

// Even if a service worker app for app store payment method is installed, it
// should be ignored.
IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest,
                       IgnoreInstalledPlayBillingServiceWorker) {
  GURL service_worker_javascript_file_url =
      https_server()->GetURL("a.com", "/alicepay.test/app1/app.js");
  ASSERT_TRUE(
      PaymentAppInstallUtil::InstallPaymentAppForPaymentMethodIdentifier(
          *GetActiveWebContents(),
          service_worker_javascript_file_url,
          /*payment_method_identifier=*/"https://play.google.com/billing",
          PaymentAppInstallUtil::IconInstall::kWithIcon));

  NavigateTo("b.com", "/can_make_payment_checker.html");
  ASSERT_EQ("false", content::EvalJs(
                         GetActiveWebContents(),
                         "canMakePayment('https://play.google.com/billing')"));
}

// When an app store payment method app is available in a trusted web activity,
// then ignore other payment apps, since this is considered to be a digital
// goods purchase.
IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest,
                       IgnoreOtherPaymentAppsInTwaWhenHaveAppStoreBilling) {
  ScopedTestSupport scoped_test_support;

  std::string method_name;
  InstallPaymentApp("a.com", "/payment_request_success_responder.js",
                    &method_name);

  // The "payment_request_success_responder.js" always replies with "{status:
  // success}", so the |response| here has to be distinct.
  std::string response = "App store payment method app response for test.";
  test_controller()->SetTwaPackageName("com.example.app");
  test_controller()->SetTwaPaymentApp("https://play.google.com/billing",
                                      "{\"status\": \"" + response + "\"}");

#if BUILDFLAG(IS_CHROMEOS)
  std::string expected_response = response;
#else
  std::string expected_response = "success";
#endif  // BUILDFLAG(IS_CHROMEOS)

  NavigateTo("b.com", "/payment_handler_status.html");
  ASSERT_EQ(expected_response,
            content::EvalJs(
                GetActiveWebContents(),
                content::JsReplace(
                    "getStatusList(['https://play.google.com/billing', $1])",
                    method_name)));
}

// https://play.google.com/billing payment method.
IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest, PlayBillingPaymentMethod) {
  ScopedTestSupport scoped_test_support;

  std::string response = "App store payment method app response for test.";
  test_controller()->SetTwaPackageName("com.example.app");
  test_controller()->SetTwaPaymentApp("https://play.google.com/billing",
                                      "{\"status\": \"" + response + "\"}");

#if BUILDFLAG(IS_CHROMEOS)
  std::string expected_response = response;
#else
  std::string expected_response =
      "NotSupportedError: The payment method "
      "\"https://play.google.com/billing\" is not supported.";
#endif  // BUILDFLAG(IS_CHROMEOS)

  NavigateTo("b.com", "/payment_handler_status.html");
  ASSERT_EQ(expected_response,
            content::EvalJs(GetActiveWebContents(),
                            "getStatus('https://play.google.com/billing')"));
}

// Passing a promise into PaymentRequest.show() should skip browser sheet with
// https://play.google.com/billing payment method.
IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest,
                       ShowPromiseShouldSkipBrowserPaymentSheet) {
  ScopedTestSupport scoped_test_support;

  std::string response = "App store payment method app response for test.";
  test_controller()->SetTwaPackageName("com.example.app");
  test_controller()->SetTwaPaymentApp("https://play.google.com/billing",
                                      "{\"status\": \"" + response + "\"}");

#if BUILDFLAG(IS_CHROMEOS)
  std::string expected_response = response;
#else
  std::string expected_response =
      "NotSupportedError: The payment method "
      "\"https://play.google.com/billing\" is not supported.";
#endif  // BUILDFLAG(IS_CHROMEOS)

  NavigateTo("b.com", "/payment_handler_status.html");
  ASSERT_EQ(expected_response,
            content::EvalJs(
                GetActiveWebContents(),
                "getStatusForMethodDataWithShowPromise([{supportedMethods:"
                "'https://play.google.com/billing'}])"));
}

// PaymentRequest.show(Promise.resolve({})) should skip browser sheet with
// https://play.google.com/billing payment method.
IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest,
                       EmptyShowPromiseShouldSkipBrowserPaymentSheet) {
  ScopedTestSupport scoped_test_support;

  std::string response = "App store payment method app response for test.";
  test_controller()->SetTwaPackageName("com.example.app");
  test_controller()->SetTwaPaymentApp("https://play.google.com/billing",
                                      "{\"status\": \"" + response + "\"}");

#if BUILDFLAG(IS_CHROMEOS)
  std::string expected_response = response;
#else
  std::string expected_response =
      "NotSupportedError: The payment method "
      "\"https://play.google.com/billing\" is not supported.";
#endif  // BUILDFLAG(IS_CHROMEOS)

  NavigateTo("b.com", "/payment_handler_status.html");
  ASSERT_EQ(expected_response,
            content::EvalJs(
                GetActiveWebContents(),
                "getStatusForMethodDataWithEmptyShowPromise([{supportedMethods:"
                "'https://play.google.com/billing'}])"));
}

}  // namespace
}  // namespace payments