File: android_app_communication_test_support_chrome_os.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; 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 (144 lines) | stat: -rw-r--r-- 5,589 bytes parent folder | download | duplicates (8)
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
// 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 "components/payments/content/android_app_communication_test_support_chrome_os.h"

#include <utility>

#include "chromeos/components/payments/mojom/payment_app.mojom.h"
#include "chromeos/components/payments/mojom/payment_app_types.mojom.h"
#include "components/payments/core/method_strings.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace payments {

AndroidAppCommunicationTestSupportChromeOS::
    AndroidAppCommunicationTestSupportChromeOS() = default;
AndroidAppCommunicationTestSupportChromeOS::
    ~AndroidAppCommunicationTestSupportChromeOS() = default;

bool AndroidAppCommunicationTestSupportChromeOS::
    AreAndroidAppsSupportedOnThisPlatform() const {
  return true;
}

void AndroidAppCommunicationTestSupportChromeOS::
    ExpectNoListOfPaymentAppsQuery() {
  EXPECT_CALL(*instance(), IsPaymentImplemented(testing::_, testing::_))
      .Times(0);
}

void AndroidAppCommunicationTestSupportChromeOS::ExpectNoIsReadyToPayQuery() {
  EXPECT_CALL(*instance(), IsReadyToPay(testing::_, testing::_)).Times(0);
}

void AndroidAppCommunicationTestSupportChromeOS::ExpectNoPaymentAppInvoke() {
  EXPECT_CALL(*instance(), InvokePaymentApp(testing::_, testing::_)).Times(0);
}

void AndroidAppCommunicationTestSupportChromeOS::
    ExpectQueryListOfPaymentAppsAndRespond(
        std::vector<std::unique_ptr<AndroidAppDescription>> apps) {
  // Move |apps| into a member variable, so it's still alive by the time the
  // RespondToGetAppDescriptions() method is executed at some point in the
  // future.
  apps_ = std::move(apps);
  EXPECT_CALL(*instance(), IsPaymentImplemented(testing::_, testing::_))
      .WillOnce([&](const std::string& package_name,
                    IsPaymentImplementedCallback callback) {
        RespondToGetAppDescriptions(package_name, std::move(callback));
      });
}

void AndroidAppCommunicationTestSupportChromeOS::
    ExpectQueryIsReadyToPayAndRespond(bool is_ready_to_pay) {
  EXPECT_CALL(*instance(), IsReadyToPay(testing::_, testing::_))
      .WillOnce([is_ready_to_pay](
                    chromeos::payments::mojom::PaymentParametersPtr parameters,
                    IsReadyToPayCallback callback) {
        std::move(callback).Run(
            chromeos::payments::mojom::IsReadyToPayResult::NewResponse(
                is_ready_to_pay));
      });
}

void AndroidAppCommunicationTestSupportChromeOS::
    ExpectInvokePaymentAppAndRespond(
        bool is_activity_result_ok,
        const std::string& payment_method_identifier,
        const std::string& stringified_details) {
  EXPECT_CALL(*instance(), InvokePaymentApp(testing::_, testing::_))
      .WillOnce([is_activity_result_ok, stringified_details](
                    chromeos::payments::mojom::PaymentParametersPtr parameters,
                    InvokePaymentAppCallback callback) {
        // Chrome OS supports only kGooglePlayBilling payment method
        // identifier at this time, so the |payment_method_identifier|
        // parameter is ignored here.
        auto valid =
            chromeos::payments::mojom::InvokePaymentAppValidResult::New();
        valid->is_activity_result_ok = is_activity_result_ok;
        valid->stringified_details = stringified_details;
        std::move(callback).Run(
            chromeos::payments::mojom::InvokePaymentAppResult::NewValid(
                std::move(valid)));
      });
}

void AndroidAppCommunicationTestSupportChromeOS::
    ExpectInvokeAndAbortPaymentApp() {
  EXPECT_CALL(*instance(), InvokePaymentApp(testing::_, testing::_))
      .WillOnce(
          [this](chromeos::payments::mojom::PaymentParametersPtr parameters,
                 InvokePaymentAppCallback callback) {
            pending_invoke_callback_ = std::move(callback);
          });

  EXPECT_CALL(*instance(), AbortPaymentApp(testing::_, testing::_))
      .WillOnce([this](const std::string& request_token,
                       AbortPaymentAppCallback callback) {
        if (!pending_invoke_callback_.is_null()) {
          std::move(pending_invoke_callback_)
              .Run(chromeos::payments::mojom::InvokePaymentAppResult::NewError(
                  "Payment was aborted."));
        }
        std::move(callback).Run(true);
      });
}

void AndroidAppCommunicationTestSupportChromeOS::ExpectNoAbortPaymentApp() {
  EXPECT_CALL(*instance(), AbortPaymentApp(testing::_, testing::_)).Times(0);
}

void AndroidAppCommunicationTestSupportChromeOS::RespondToGetAppDescriptions(
    const std::string& package_name,
    IsPaymentImplementedCallback callback) {
  auto valid =
      chromeos::payments::mojom::IsPaymentImplementedValidResult::New();
  for (const auto& app : apps_) {
    if (app->package == package_name) {
      for (const auto& activity : app->activities) {
        // Chrome OS supports only kGooglePlayBilling method at this time.
        if (activity->default_payment_method == methods::kGooglePlayBilling) {
          valid->activity_names.push_back(activity->name);
        }
      }

      valid->service_names = app->service_names;

      // Chrome OS supports only one payment app in Android subsystem at this
      // time, i.e., the TWA that invoked Chrome.
      break;
    }
  }

  std::move(callback).Run(
      chromeos::payments::mojom::IsPaymentImplementedResult::NewValid(
          std::move(valid)));
}

MockPaymentAppInstance* AndroidAppCommunicationTestSupportChromeOS::instance() {
  return nullptr;
}

}  // namespace payments