Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 1 | // 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 Krcal | 324a5c1 | 2019-03-14 13:18:20 | [diff] [blame] | 8 | #include <map> |
Mikel Astiz | 81d02e2 | 2019-10-24 17:32:46 | [diff] [blame] | 9 | #include <string> |
Jan Krcal | 0b31440 | 2019-01-25 10:42:02 | [diff] [blame] | 10 | #include <utility> |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 11 | #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 | |
| 18 | namespace autofill { |
Jan Krcal | 3b23f1a | 2018-12-18 08:41:40 | [diff] [blame] | 19 | struct AutofillMetadata; |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 20 | class AutofillProfile; |
| 21 | class AutofillWebDataService; |
| 22 | class CreditCard; |
siyua | 0d9599a | 2019-12-16 20:43:57 | [diff] [blame] | 23 | struct CreditCardCloudTokenData; |
Melissa Zhang | ab83e84b | 2019-12-12 02:49:12 | [diff] [blame] | 24 | struct PaymentsCustomerData; |
siyua | 0d9599a | 2019-12-16 20:43:57 | [diff] [blame] | 25 | class PersonalDataManager; |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 26 | } // namespace autofill |
| 27 | |
| 28 | namespace sync_pb { |
| 29 | class SyncEntity; |
Jan Krcal | aaba404 | 2019-02-05 12:54:39 | [diff] [blame] | 30 | class ModelTypeState; |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | namespace wallet_helper { |
| 34 | |
| 35 | extern const char kDefaultCardID[]; |
| 36 | extern const char kDefaultAddressID[]; |
| 37 | extern const char kDefaultCustomerID[]; |
| 38 | extern const char kDefaultBillingAddressID[]; |
siyua | 0d9599a | 2019-12-16 20:43:57 | [diff] [blame] | 39 | extern const char kDefaultCreditCardCloudTokenDataID[]; |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 40 | |
| 41 | // Used to access the personal data manager within a particular sync profile. |
| 42 | autofill::PersonalDataManager* GetPersonalDataManager(int index) |
| 43 | WARN_UNUSED_RESULT; |
| 44 | |
| 45 | // Used to access the web data service within a particular sync profile. |
| 46 | scoped_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. |
| 51 | scoped_refptr<autofill::AutofillWebDataService> GetAccountWebDataService( |
| 52 | int index) WARN_UNUSED_RESULT; |
| 53 | |
| 54 | void SetServerCreditCards( |
| 55 | int profile, |
| 56 | const std::vector<autofill::CreditCard>& credit_cards); |
| 57 | |
| 58 | void SetServerProfiles(int profile, |
| 59 | const std::vector<autofill::AutofillProfile>& profiles); |
| 60 | |
| 61 | void SetPaymentsCustomerData( |
| 62 | int profile, |
| 63 | const autofill::PaymentsCustomerData& customer_data); |
| 64 | |
siyua | 0d9599a | 2019-12-16 20:43:57 | [diff] [blame] | 65 | void SetCreditCardCloudTokenData( |
| 66 | int profile, |
| 67 | const std::vector<autofill::CreditCardCloudTokenData>& cloud_token_data); |
| 68 | |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 69 | void UpdateServerCardMetadata(int profile, |
| 70 | const autofill::CreditCard& credit_card); |
| 71 | |
| 72 | void UpdateServerAddressMetadata( |
| 73 | int profile, |
| 74 | const autofill::AutofillProfile& server_address); |
| 75 | |
Jan Krcal | 324a5c1 | 2019-03-14 13:18:20 | [diff] [blame] | 76 | std::map<std::string, autofill::AutofillMetadata> GetServerCardsMetadata( |
| 77 | int profile); |
Jan Krcal | 3b23f1a | 2018-12-18 08:41:40 | [diff] [blame] | 78 | |
Jan Krcal | 324a5c1 | 2019-03-14 13:18:20 | [diff] [blame] | 79 | std::map<std::string, autofill::AutofillMetadata> GetServerAddressesMetadata( |
| 80 | int profile); |
Jan Krcal | 3b23f1a | 2018-12-18 08:41:40 | [diff] [blame] | 81 | |
Jan Krcal | aaba404 | 2019-02-05 12:54:39 | [diff] [blame] | 82 | sync_pb::ModelTypeState GetWalletDataModelTypeState(int profile); |
| 83 | |
Jan Krcal | 8bf4776 | 2018-12-12 15:22:20 | [diff] [blame] | 84 | void UnmaskServerCard(int profile, |
| 85 | const autofill::CreditCard& credit_card, |
| 86 | const base::string16& full_number); |
| 87 | |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 88 | sync_pb::SyncEntity CreateDefaultSyncWalletCard(); |
| 89 | |
| 90 | sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name, |
Jan Krcal | f16a2137 | 2018-11-26 14:10:14 | [diff] [blame] | 91 | const std::string& last_four, |
Sujie Zhu | 43548e9 | 2020-03-13 00:03:59 | [diff] [blame] | 92 | const std::string& billing_address_id, |
Anne Lim | 001a7b8 | 2020-09-16 17:52:23 | [diff] [blame] | 93 | const std::string& nickname = "", |
Anne Lim | 7839d61 | 2020-10-07 06:11:34 | [diff] [blame^] | 94 | int64_t instrument_id = 1); |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 95 | |
| 96 | sync_pb::SyncEntity CreateSyncPaymentsCustomerData( |
| 97 | const std::string& customer_id); |
| 98 | |
| 99 | sync_pb::SyncEntity CreateDefaultSyncPaymentsCustomerData(); |
| 100 | |
| 101 | autofill::CreditCard GetDefaultCreditCard(); |
| 102 | |
| 103 | autofill::CreditCard GetCreditCard(const std::string& name, |
| 104 | const std::string& last_four); |
| 105 | |
| 106 | sync_pb::SyncEntity CreateDefaultSyncWalletAddress(); |
| 107 | |
| 108 | sync_pb::SyncEntity CreateSyncWalletAddress(const std::string& name, |
| 109 | const std::string& company); |
| 110 | |
siyua | 0d9599a | 2019-12-16 20:43:57 | [diff] [blame] | 111 | sync_pb::SyncEntity CreateSyncCreditCardCloudTokenData( |
| 112 | const std::string& cloud_token_data_id); |
| 113 | sync_pb::SyncEntity CreateDefaultSyncCreditCardCloudTokenData(); |
| 114 | |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 115 | // TODO(sebsg): Instead add a function to create a card, and one to inject in |
| 116 | // the server. Then compare the cards directly. |
| 117 | void 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. |
| 121 | void ExpectDefaultProfileValues(const autofill::AutofillProfile& profile); |
| 122 | |
| 123 | // Load current data from the database of profile |profile|. |
| 124 | std::vector<autofill::AutofillProfile*> GetServerProfiles(int profile); |
Jan Krcal | f16a2137 | 2018-11-26 14:10:14 | [diff] [blame] | 125 | std::vector<autofill::AutofillProfile*> GetLocalProfiles(int profile); |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 126 | std::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 Krcal | 2275024 | 2019-04-17 14:25:12 | [diff] [blame] | 131 | // profiles and until server profiles got converted to local profiles. |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 132 | class 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 Astiz | 81d02e2 | 2019-10-24 17:32:46 | [diff] [blame] | 140 | bool IsExitConditionSatisfied(std::ostream* os) override; |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 141 | |
| 142 | // autofill::PersonalDataManager implementation. |
| 143 | void OnPersonalDataChanged() override; |
| 144 | |
| 145 | private: |
| 146 | const int profile_a_; |
| 147 | const int profile_b_; |
| 148 | }; |
| 149 | |
Jan Krcal | 2275024 | 2019-04-17 14:25:12 | [diff] [blame] | 150 | // Checker to block until autofill server profiles got converted to local |
| 151 | // profiles. |
| 152 | class 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 Astiz | 81d02e2 | 2019-10-24 17:32:46 | [diff] [blame] | 161 | bool IsExitConditionSatisfied(std::ostream* os) override; |
Jan Krcal | 2275024 | 2019-04-17 14:25:12 | [diff] [blame] | 162 | |
| 163 | // autofill::PersonalDataManager implementation. |
| 164 | void OnPersonalDataChanged() override; |
| 165 | |
| 166 | private: |
| 167 | const int profile_; |
| 168 | }; |
| 169 | |
Jan Krcal | 93dcec8 | 2019-01-15 14:41:25 | [diff] [blame] | 170 | // Checker to block until autofill wallet metadata sizes match on both profiles. |
| 171 | class 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 Astiz | 81d02e2 | 2019-10-24 17:32:46 | [diff] [blame] | 179 | bool IsExitConditionSatisfied(std::ostream* os) override; |
Jan Krcal | 93dcec8 | 2019-01-15 14:41:25 | [diff] [blame] | 180 | |
| 181 | // autofill::PersonalDataManager implementation. |
| 182 | void OnPersonalDataChanged() override; |
| 183 | |
| 184 | private: |
Jan Krcal | c935328 | 2019-04-11 13:03:49 | [diff] [blame] | 185 | bool IsExitConditionSatisfiedImpl(); |
| 186 | |
Jan Krcal | 93dcec8 | 2019-01-15 14:41:25 | [diff] [blame] | 187 | const int profile_a_; |
| 188 | const int profile_b_; |
Jan Krcal | d2546dc | 2019-04-23 12:35:57 | [diff] [blame] | 189 | bool checking_exit_condition_in_flight_ = false; |
Jan Krcal | 93dcec8 | 2019-01-15 14:41:25 | [diff] [blame] | 190 | }; |
| 191 | |
Jan Krcal | 46c534f | 2018-11-13 17:42:09 | [diff] [blame] | 192 | #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_ |