File: wallet_helper.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (204 lines) | stat: -rw-r--r-- 7,306 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_

#include <map>
#include <string>
#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h"
#include "components/autofill/core/browser/data_manager/payments/payments_data_manager.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace autofill {
class AutofillWebDataService;
class CreditCard;
struct CreditCardCloudTokenData;
struct PaymentsCustomerData;
struct PaymentsMetadata;
class PaymentsDataManager;
class PersonalDataManager;
struct ServerCvc;
}  // namespace autofill

namespace sync_pb {
class DataTypeState;
class SyncEntity;
}  // namespace sync_pb

namespace wallet_helper {

inline constexpr char kDefaultCardID[] = "wallet card ID";
inline constexpr char kDefaultCustomerID[] = "deadbeef";
inline constexpr char kDefaultBillingAddressID[] = "billing address entity ID";
inline constexpr char kDefaultCreditCardCloudTokenDataID[] =
    "cloud token data ID";

// Used to access the `PaymentsDataManager` for a particular sync profile.
[[nodiscard]] autofill::PaymentsDataManager* GetPaymentsDataManager(int index);

// Used to access the `PersonalDataManager` for a particular sync profile.
// Prefer using `GetPaymentsDataManager` instead - Wallet should not need to
// know address-related information.
[[nodiscard]] autofill::PersonalDataManager* GetPersonalDataManager(int index);

// Used to access the web data service within a particular sync profile.
[[nodiscard]] scoped_refptr<autofill::AutofillWebDataService>
GetProfileWebDataService(int index);

// Used to access the account-scoped web data service within a particular sync
// profile.
[[nodiscard]] scoped_refptr<autofill::AutofillWebDataService>
GetAccountWebDataService(int index);

void SetServerCreditCards(
    int profile,
    const std::vector<autofill::CreditCard>& credit_cards);

void SetPaymentsCustomerData(
    int profile,
    const autofill::PaymentsCustomerData& customer_data);

void SetCreditCardCloudTokenData(
    int profile,
    const std::vector<autofill::CreditCardCloudTokenData>& cloud_token_data);

void SetServerCardCredentialData(int profile,
                                 const autofill::CreditCard& credit_card);

void RemoveServerCardCredentialData(int profile,
                                    const autofill::CreditCard& credit_card);

void UpdateServerCardCredentialData(int profile,
                                    const autofill::CreditCard& credit_card);

void UpdateServerCardMetadata(int profile,
                              const autofill::CreditCard& credit_card);

std::vector<autofill::PaymentsMetadata> GetServerCardsMetadata(int profile);

// Function supports AUTOFILL_WALLET_DATA and AUTOFILL_WALLET_OFFER.
sync_pb::DataTypeState GetWalletDataTypeState(syncer::DataType type,
                                              int profile);

sync_pb::SyncEntity CreateDefaultSyncWalletCard();

sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
                                         const std::string& last_four,
                                         const std::string& billing_address_id,
                                         const std::string& nickname = "",
                                         int64_t instrument_id = 1);

sync_pb::SyncEntity CreateSyncPaymentsCustomerData(
    const std::string& customer_id);

sync_pb::SyncEntity CreateDefaultSyncPaymentsCustomerData();

autofill::CreditCard GetDefaultCreditCard();

autofill::CreditCard GetCreditCard(const std::string& name,
                                   const std::string& last_four);

sync_pb::SyncEntity CreateSyncCreditCardCloudTokenData(
    const std::string& cloud_token_data_id);
sync_pb::SyncEntity CreateDefaultSyncCreditCardCloudTokenData();

sync_pb::SyncEntity CreateDefaultSyncWalletCredential();

sync_pb::SyncEntity CreateSyncWalletCredential(
    const autofill::ServerCvc& server_cvc);

// TODO(sebsg): Instead add a function to create a card, and one to inject in
// the server. Then compare the cards directly.
void ExpectDefaultCreditCardValues(const autofill::CreditCard& card);

void ExpectDefaultWalletCredentialValues(const autofill::CreditCard& card);

// Load current data from the database of profile |profile|.
std::vector<const autofill::CreditCard*> GetServerCreditCards(int profile);

}  // namespace wallet_helper

// Checker to block until autofill wallet data matches on both profiles.
class AutofillWalletChecker : public StatusChangeChecker,
                              public autofill::PaymentsDataManager::Observer {
 public:
  AutofillWalletChecker(int profile_a, int profile_b);
  ~AutofillWalletChecker() override;

  // StatusChangeChecker implementation.
  bool IsExitConditionSatisfied(std::ostream* os) override;

  // autofill::PaymentsDataManager::Observer implementation.
  void OnPaymentsDataChanged() override;

 private:
  // StatusChangeChecker overrides.
  void WillStartWaiting() override;

  const int profile_a_;
  const int profile_b_;
};

// Checker to block until autofill wallet metadata sizes match on both profiles.
class AutofillWalletMetadataSizeChecker
    : public StatusChangeChecker,
      public autofill::PaymentsDataManager::Observer {
 public:
  AutofillWalletMetadataSizeChecker(int profile_a, int profile_b);
  ~AutofillWalletMetadataSizeChecker() override;

  // StatusChangeChecker implementation.
  bool IsExitConditionSatisfied(std::ostream* os) override;

  // autofill::PaymentsDataManager::Observer implementation.
  void OnPaymentsDataChanged() override;

 private:
  bool IsExitConditionSatisfiedImpl();

  const int profile_a_;
  const int profile_b_;
  bool checking_exit_condition_in_flight_ = false;
};

// Checker to block until a new progress marker with correct timestamp is
// received.
class FullUpdateTypeProgressMarkerChecker : public StatusChangeChecker,
                                            public syncer::SyncServiceObserver {
 public:
  FullUpdateTypeProgressMarkerChecker(
      base::Time min_required_progress_marker_timestamp,
      syncer::SyncService* service,
      syncer::DataType data_type);
  ~FullUpdateTypeProgressMarkerChecker() override;

  FullUpdateTypeProgressMarkerChecker(
      const FullUpdateTypeProgressMarkerChecker&) = delete;
  FullUpdateTypeProgressMarkerChecker& operator=(
      const FullUpdateTypeProgressMarkerChecker&) = delete;

  // StatusChangeChecker:
  bool IsExitConditionSatisfied(std::ostream* os) override;

  // syncer::SyncServiceObserver:
  void OnSyncCycleCompleted(syncer::SyncService* sync) override;

 private:
  const base::Time min_required_progress_marker_timestamp_;
  const raw_ptr<const syncer::SyncService> service_;
  const syncer::DataType data_type_;

  base::ScopedObservation<syncer::SyncService, syncer::SyncServiceObserver>
      scoped_observation_{this};
};

#endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_