blob: 039a48a3a5098937ab82dc5f21dc3b84d9407b7d [file] [log] [blame]
Jan Krcal46c534f2018-11-13 17:42:091// Copyright 2018 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#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_
6#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_
7
Jan Krcal324a5c12019-03-14 13:18:208#include <map>
Mikel Astiz81d02e22019-10-24 17:32:469#include <string>
Jan Krcal0b314402019-01-25 10:42:0210#include <utility>
Jan Krcal46c534f2018-11-13 17:42:0911#include <vector>
12
13#include "base/test/scoped_feature_list.h"
14#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h"
15#include "components/autofill/core/browser/personal_data_manager_observer.h"
16#include "testing/gtest/include/gtest/gtest.h"
17
18namespace autofill {
Jan Krcal3b23f1a2018-12-18 08:41:4019struct AutofillMetadata;
Jan Krcal46c534f2018-11-13 17:42:0920class AutofillProfile;
21class AutofillWebDataService;
22class CreditCard;
siyua0d9599a2019-12-16 20:43:5723struct CreditCardCloudTokenData;
Melissa Zhangab83e84b2019-12-12 02:49:1224struct PaymentsCustomerData;
siyua0d9599a2019-12-16 20:43:5725class PersonalDataManager;
Jan Krcal46c534f2018-11-13 17:42:0926} // namespace autofill
27
28namespace sync_pb {
29class SyncEntity;
Jan Krcalaaba4042019-02-05 12:54:3930class ModelTypeState;
Jan Krcal46c534f2018-11-13 17:42:0931}
32
33namespace wallet_helper {
34
35extern const char kDefaultCardID[];
36extern const char kDefaultAddressID[];
37extern const char kDefaultCustomerID[];
38extern const char kDefaultBillingAddressID[];
siyua0d9599a2019-12-16 20:43:5739extern const char kDefaultCreditCardCloudTokenDataID[];
Jan Krcal46c534f2018-11-13 17:42:0940
41// Used to access the personal data manager within a particular sync profile.
42autofill::PersonalDataManager* GetPersonalDataManager(int index)
43 WARN_UNUSED_RESULT;
44
45// Used to access the web data service within a particular sync profile.
46scoped_refptr<autofill::AutofillWebDataService> GetProfileWebDataService(
47 int index) WARN_UNUSED_RESULT;
48
49// Used to access the account-scoped web data service within a particular sync
50// profile.
51scoped_refptr<autofill::AutofillWebDataService> GetAccountWebDataService(
52 int index) WARN_UNUSED_RESULT;
53
54void SetServerCreditCards(
55 int profile,
56 const std::vector<autofill::CreditCard>& credit_cards);
57
58void SetServerProfiles(int profile,
59 const std::vector<autofill::AutofillProfile>& profiles);
60
61void SetPaymentsCustomerData(
62 int profile,
63 const autofill::PaymentsCustomerData& customer_data);
64
siyua0d9599a2019-12-16 20:43:5765void SetCreditCardCloudTokenData(
66 int profile,
67 const std::vector<autofill::CreditCardCloudTokenData>& cloud_token_data);
68
Jan Krcal46c534f2018-11-13 17:42:0969void UpdateServerCardMetadata(int profile,
70 const autofill::CreditCard& credit_card);
71
72void UpdateServerAddressMetadata(
73 int profile,
74 const autofill::AutofillProfile& server_address);
75
Jan Krcal324a5c12019-03-14 13:18:2076std::map<std::string, autofill::AutofillMetadata> GetServerCardsMetadata(
77 int profile);
Jan Krcal3b23f1a2018-12-18 08:41:4078
Jan Krcal324a5c12019-03-14 13:18:2079std::map<std::string, autofill::AutofillMetadata> GetServerAddressesMetadata(
80 int profile);
Jan Krcal3b23f1a2018-12-18 08:41:4081
Jan Krcalaaba4042019-02-05 12:54:3982sync_pb::ModelTypeState GetWalletDataModelTypeState(int profile);
83
Jan Krcal8bf47762018-12-12 15:22:2084void UnmaskServerCard(int profile,
85 const autofill::CreditCard& credit_card,
86 const base::string16& full_number);
87
Jan Krcal46c534f2018-11-13 17:42:0988sync_pb::SyncEntity CreateDefaultSyncWalletCard();
89
90sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
Jan Krcalf16a21372018-11-26 14:10:1491 const std::string& last_four,
Sujie Zhu43548e92020-03-13 00:03:5992 const std::string& billing_address_id,
Anne Lim001a7b82020-09-16 17:52:2393 const std::string& nickname = "",
Anne Lim7839d612020-10-07 06:11:3494 int64_t instrument_id = 1);
Jan Krcal46c534f2018-11-13 17:42:0995
96sync_pb::SyncEntity CreateSyncPaymentsCustomerData(
97 const std::string& customer_id);
98
99sync_pb::SyncEntity CreateDefaultSyncPaymentsCustomerData();
100
101autofill::CreditCard GetDefaultCreditCard();
102
103autofill::CreditCard GetCreditCard(const std::string& name,
104 const std::string& last_four);
105
106sync_pb::SyncEntity CreateDefaultSyncWalletAddress();
107
108sync_pb::SyncEntity CreateSyncWalletAddress(const std::string& name,
109 const std::string& company);
110
siyua0d9599a2019-12-16 20:43:57111sync_pb::SyncEntity CreateSyncCreditCardCloudTokenData(
112 const std::string& cloud_token_data_id);
113sync_pb::SyncEntity CreateDefaultSyncCreditCardCloudTokenData();
114
Jan Krcal46c534f2018-11-13 17:42:09115// TODO(sebsg): Instead add a function to create a card, and one to inject in
116// the server. Then compare the cards directly.
117void ExpectDefaultCreditCardValues(const autofill::CreditCard& card);
118
119// TODO(sebsg): Instead add a function to create a profile, and one to inject in
120// the server. Then compare the profiles directly.
121void ExpectDefaultProfileValues(const autofill::AutofillProfile& profile);
122
123// Load current data from the database of profile |profile|.
124std::vector<autofill::AutofillProfile*> GetServerProfiles(int profile);
Jan Krcalf16a21372018-11-26 14:10:14125std::vector<autofill::AutofillProfile*> GetLocalProfiles(int profile);
Jan Krcal46c534f2018-11-13 17:42:09126std::vector<autofill::CreditCard*> GetServerCreditCards(int profile);
127
128} // namespace wallet_helper
129
130// Checker to block until autofill wallet & server profiles match on both
Jan Krcal22750242019-04-17 14:25:12131// profiles and until server profiles got converted to local profiles.
Jan Krcal46c534f2018-11-13 17:42:09132class AutofillWalletChecker : public StatusChangeChecker,
133 public autofill::PersonalDataManagerObserver {
134 public:
135 AutofillWalletChecker(int profile_a, int profile_b);
136 ~AutofillWalletChecker() override;
137
138 // StatusChangeChecker implementation.
139 bool Wait() override;
Mikel Astiz81d02e22019-10-24 17:32:46140 bool IsExitConditionSatisfied(std::ostream* os) override;
Jan Krcal46c534f2018-11-13 17:42:09141
142 // autofill::PersonalDataManager implementation.
143 void OnPersonalDataChanged() override;
144
145 private:
146 const int profile_a_;
147 const int profile_b_;
148};
149
Jan Krcal22750242019-04-17 14:25:12150// Checker to block until autofill server profiles got converted to local
151// profiles.
152class AutofillWalletConversionChecker
153 : public StatusChangeChecker,
154 public autofill::PersonalDataManagerObserver {
155 public:
156 explicit AutofillWalletConversionChecker(int profile);
157 ~AutofillWalletConversionChecker() override;
158
159 // StatusChangeChecker implementation.
160 bool Wait() override;
Mikel Astiz81d02e22019-10-24 17:32:46161 bool IsExitConditionSatisfied(std::ostream* os) override;
Jan Krcal22750242019-04-17 14:25:12162
163 // autofill::PersonalDataManager implementation.
164 void OnPersonalDataChanged() override;
165
166 private:
167 const int profile_;
168};
169
Jan Krcal93dcec82019-01-15 14:41:25170// Checker to block until autofill wallet metadata sizes match on both profiles.
171class AutofillWalletMetadataSizeChecker
172 : public StatusChangeChecker,
173 public autofill::PersonalDataManagerObserver {
174 public:
175 AutofillWalletMetadataSizeChecker(int profile_a, int profile_b);
176 ~AutofillWalletMetadataSizeChecker() override;
177
178 // StatusChangeChecker implementation.
Mikel Astiz81d02e22019-10-24 17:32:46179 bool IsExitConditionSatisfied(std::ostream* os) override;
Jan Krcal93dcec82019-01-15 14:41:25180
181 // autofill::PersonalDataManager implementation.
182 void OnPersonalDataChanged() override;
183
184 private:
Jan Krcalc9353282019-04-11 13:03:49185 bool IsExitConditionSatisfiedImpl();
186
Jan Krcal93dcec82019-01-15 14:41:25187 const int profile_a_;
188 const int profile_b_;
Jan Krcald2546dc2019-04-23 12:35:57189 bool checking_exit_condition_in_flight_ = false;
Jan Krcal93dcec82019-01-15 14:41:25190};
191
Jan Krcal46c534f2018-11-13 17:42:09192#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_