| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/sync/test/integration/autofill_helper.h" | 10 #include "chrome/browser/sync/test/integration/autofill_helper.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "sync/internal_api/public/base/model_type.h" | 23 #include "sync/internal_api/public/base/model_type.h" |
| 24 #include "sync/test/fake_server/fake_server_entity.h" | 24 #include "sync/test/fake_server/fake_server_entity.h" |
| 25 #include "sync/test/fake_server/unique_client_entity.h" | 25 #include "sync/test/fake_server/unique_client_entity.h" |
| 26 | 26 |
| 27 using autofill_helper::GetPersonalDataManager; | 27 using autofill_helper::GetPersonalDataManager; |
| 28 using sync_integration_test_util::AwaitCommitActivityCompletion; | 28 using sync_integration_test_util::AwaitCommitActivityCompletion; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Setting the Preferences files contents to this string (before Profile is | |
| 33 // created) will bypass the Sync experiment logic for enabling this feature. | |
| 34 const char kWalletSyncEnabledPreferencesContents[] = | |
| 35 "{\"autofill\": { \"wallet_import_sync_experiment_enabled\": true } }"; | |
| 36 | |
| 37 const char kWalletSyncExperimentTag[] = "wallet_sync"; | |
| 38 | |
| 39 const char kDefaultCardID[] = "wallet entity ID"; | 32 const char kDefaultCardID[] = "wallet entity ID"; |
| 40 const int kDefaultCardExpMonth = 8; | 33 const int kDefaultCardExpMonth = 8; |
| 41 const int kDefaultCardExpYear = 2087; | 34 const int kDefaultCardExpYear = 2087; |
| 42 const char kDefaultCardLastFour[] = "1234"; | 35 const char kDefaultCardLastFour[] = "1234"; |
| 43 const char kDefaultCardName[] = "Patrick Valenzuela"; | 36 const char kDefaultCardName[] = "Patrick Valenzuela"; |
| 44 const sync_pb::WalletMaskedCreditCard_WalletCardType kDefaultCardType = | 37 const sync_pb::WalletMaskedCreditCard_WalletCardType kDefaultCardType = |
| 45 sync_pb::WalletMaskedCreditCard::AMEX; | 38 sync_pb::WalletMaskedCreditCard::AMEX; |
| 46 | 39 |
| 47 void AddDefaultCard(fake_server::FakeServer* server) { | 40 void AddDefaultCard(fake_server::FakeServer* server) { |
| 48 sync_pb::EntitySpecifics specifics; | 41 sync_pb::EntitySpecifics specifics; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 66 specifics)); | 59 specifics)); |
| 67 } | 60 } |
| 68 | 61 |
| 69 } // namespace | 62 } // namespace |
| 70 | 63 |
| 71 class SingleClientWalletSyncTest : public SyncTest { | 64 class SingleClientWalletSyncTest : public SyncTest { |
| 72 public: | 65 public: |
| 73 SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {} | 66 SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {} |
| 74 ~SingleClientWalletSyncTest() override {} | 67 ~SingleClientWalletSyncTest() override {} |
| 75 | 68 |
| 76 void TriggerSyncCycle() { | |
| 77 // Note: we use the experiments type here as we want to be able to trigger a | |
| 78 // sync cycle even when wallet is not enabled yet. | |
| 79 const syncer::ModelTypeSet kExperimentsType(syncer::EXPERIMENTS); | |
| 80 TriggerSyncForModelTypes(0, kExperimentsType); | |
| 81 } | |
| 82 | |
| 83 private: | 69 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSyncTest); | 70 DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSyncTest); |
| 85 }; | 71 }; |
| 86 | 72 |
| 87 // Checker that will wait until an asynchronous Wallet datatype enable event | 73 // Checker that will wait until an asynchronous Wallet datatype enable event |
| 88 // happens, or times out. | 74 // happens, or times out. |
| 89 class WalletEnabledChecker : public SingleClientStatusChangeChecker { | 75 class WalletEnabledChecker : public SingleClientStatusChangeChecker { |
| 90 public: | 76 public: |
| 91 WalletEnabledChecker() | 77 WalletEnabledChecker() |
| 92 : SingleClientStatusChangeChecker( | 78 : SingleClientStatusChangeChecker( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 113 | 99 |
| 114 // SingleClientStatusChangeChecker overrides. | 100 // SingleClientStatusChangeChecker overrides. |
| 115 bool IsExitConditionSatisfied() override { | 101 bool IsExitConditionSatisfied() override { |
| 116 return !service()->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA); | 102 return !service()->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA); |
| 117 } | 103 } |
| 118 std::string GetDebugMessage() const override { | 104 std::string GetDebugMessage() const override { |
| 119 return "Waiting for wallet disable event."; | 105 return "Waiting for wallet disable event."; |
| 120 } | 106 } |
| 121 }; | 107 }; |
| 122 | 108 |
| 123 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, DisabledByDefault) { | 109 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, EnabledByDefault) { |
| 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 110 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 125 // The type should not be enabled without the experiment enabled. | |
| 126 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 127 syncer::AUTOFILL_WALLET_DATA)); | |
| 128 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 129 syncer::AUTOFILL_WALLET_METADATA)); | |
| 130 } | |
| 131 | |
| 132 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, EnabledViaPreference) { | |
| 133 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | |
| 134 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | |
| 135 // The type should not be enabled without the experiment enabled. | |
| 136 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( | 111 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( |
| 137 syncer::AUTOFILL_WALLET_DATA)); | 112 syncer::AUTOFILL_WALLET_DATA)); |
| 138 // TODO(pvalenzuela): Assert that the local root node for AUTOFILL_WALLET_DATA | 113 // TODO(pvalenzuela): Assert that the local root node for AUTOFILL_WALLET_DATA |
| 139 // exists. | 114 // exists. |
| 140 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( | 115 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( |
| 141 syncer::AUTOFILL_WALLET_METADATA)); | 116 syncer::AUTOFILL_WALLET_METADATA)); |
| 142 } | 117 } |
| 143 | 118 |
| 144 // Tests that an experiment received at sync startup time (during sign-in) | |
| 145 // enables the wallet datatype. | |
| 146 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, | |
| 147 EnabledViaExperimentStartup) { | |
| 148 sync_pb::EntitySpecifics experiment_entity; | |
| 149 sync_pb::ExperimentsSpecifics* experiment_specifics = | |
| 150 experiment_entity.mutable_experiments(); | |
| 151 experiment_specifics->mutable_wallet_sync()->set_enabled(true); | |
| 152 GetFakeServer()->InjectEntity( | |
| 153 fake_server::UniqueClientEntity::CreateForInjection( | |
| 154 kWalletSyncExperimentTag, | |
| 155 experiment_entity)); | |
| 156 | |
| 157 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | |
| 158 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 159 syncer::AUTOFILL_WALLET_DATA)); | |
| 160 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 161 syncer::AUTOFILL_WALLET_METADATA)); | |
| 162 } | |
| 163 | |
| 164 // Tests receiving an enable experiment at runtime, followed by a disabled | |
| 165 // experiment, and verifies the datatype is enabled/disabled as necessary. | |
| 166 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, | |
| 167 EnabledDisabledViaExperiment) { | |
| 168 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | |
| 169 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes(). | |
| 170 Has(syncer::AUTOFILL_WALLET_DATA)); | |
| 171 | |
| 172 sync_pb::EntitySpecifics experiment_entity; | |
| 173 sync_pb::ExperimentsSpecifics* experiment_specifics = | |
| 174 experiment_entity.mutable_experiments(); | |
| 175 | |
| 176 // First enable the experiment. | |
| 177 experiment_specifics->mutable_wallet_sync()->set_enabled(true); | |
| 178 GetFakeServer()->InjectEntity( | |
| 179 fake_server::UniqueClientEntity::CreateForInjection( | |
| 180 kWalletSyncExperimentTag, experiment_entity)); | |
| 181 TriggerSyncCycle(); | |
| 182 | |
| 183 WalletEnabledChecker enabled_checker; | |
| 184 enabled_checker.Wait(); | |
| 185 ASSERT_FALSE(enabled_checker.TimedOut()); | |
| 186 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 187 syncer::AUTOFILL_WALLET_DATA)); | |
| 188 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 189 syncer::AUTOFILL_WALLET_METADATA)); | |
| 190 | |
| 191 // Then disable the experiment. | |
| 192 experiment_specifics->mutable_wallet_sync()->set_enabled(false); | |
| 193 GetFakeServer()->InjectEntity( | |
| 194 fake_server::UniqueClientEntity::CreateForInjection( | |
| 195 kWalletSyncExperimentTag, experiment_entity)); | |
| 196 TriggerSyncCycle(); | |
| 197 | |
| 198 WalletDisabledChecker disable_checker; | |
| 199 disable_checker.Wait(); | |
| 200 ASSERT_FALSE(disable_checker.TimedOut()); | |
| 201 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes(). | |
| 202 Has(syncer::AUTOFILL_WALLET_DATA)); | |
| 203 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().Has( | |
| 204 syncer::AUTOFILL_WALLET_METADATA)); | |
| 205 } | |
| 206 | |
| 207 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) { | 119 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) { |
| 208 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | |
| 209 AddDefaultCard(GetFakeServer()); | 120 AddDefaultCard(GetFakeServer()); |
| 210 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 121 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 211 | 122 |
| 212 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); | 123 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); |
| 213 ASSERT_TRUE(pdm != nullptr); | 124 ASSERT_TRUE(pdm != nullptr); |
| 214 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); | 125 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); |
| 215 ASSERT_EQ(1uL, cards.size()); | 126 ASSERT_EQ(1uL, cards.size()); |
| 216 | 127 |
| 217 autofill::CreditCard* card = cards[0]; | 128 autofill::CreditCard* card = cards[0]; |
| 218 ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type()); | 129 ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type()); |
| 219 ASSERT_EQ(kDefaultCardID, card->server_id()); | 130 ASSERT_EQ(kDefaultCardID, card->server_id()); |
| 220 ASSERT_EQ(base::UTF8ToUTF16(kDefaultCardLastFour), card->LastFourDigits()); | 131 ASSERT_EQ(base::UTF8ToUTF16(kDefaultCardLastFour), card->LastFourDigits()); |
| 221 ASSERT_EQ(autofill::kAmericanExpressCard, card->type()); | 132 ASSERT_EQ(autofill::kAmericanExpressCard, card->type()); |
| 222 ASSERT_EQ(kDefaultCardExpMonth, card->expiration_month()); | 133 ASSERT_EQ(kDefaultCardExpMonth, card->expiration_month()); |
| 223 ASSERT_EQ(kDefaultCardExpYear, card->expiration_year()); | 134 ASSERT_EQ(kDefaultCardExpYear, card->expiration_year()); |
| 224 ASSERT_EQ(base::UTF8ToUTF16(kDefaultCardName), | 135 ASSERT_EQ(base::UTF8ToUTF16(kDefaultCardName), |
| 225 card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME_FULL)); | 136 card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME_FULL)); |
| 226 } | 137 } |
| 227 | 138 |
| 228 // Wallet data should get cleared from the database when sync is disabled. | 139 // Wallet data should get cleared from the database when sync is disabled. |
| 229 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, ClearOnDisableSync) { | 140 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, ClearOnDisableSync) { |
| 230 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | |
| 231 AddDefaultCard(GetFakeServer()); | 141 AddDefaultCard(GetFakeServer()); |
| 232 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 142 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 233 | 143 |
| 234 // Make sure the card is in the DB. | 144 // Make sure the card is in the DB. |
| 235 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); | 145 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); |
| 236 ASSERT_TRUE(pdm != nullptr); | 146 ASSERT_TRUE(pdm != nullptr); |
| 237 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); | 147 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); |
| 238 ASSERT_EQ(1uL, cards.size()); | 148 ASSERT_EQ(1uL, cards.size()); |
| 239 | 149 |
| 240 // Turn off sync, the card should be gone. | 150 // Turn off sync, the card should be gone. |
| 241 ASSERT_TRUE(GetClient(0)->DisableSyncForAllDatatypes()); | 151 ASSERT_TRUE(GetClient(0)->DisableSyncForAllDatatypes()); |
| 242 cards = pdm->GetCreditCards(); | 152 cards = pdm->GetCreditCards(); |
| 243 ASSERT_EQ(0uL, cards.size()); | 153 ASSERT_EQ(0uL, cards.size()); |
| 244 } | 154 } |
| 245 | 155 |
| 246 // Wallet data should get cleared from the database when the wallet sync type | 156 // Wallet data should get cleared from the database when the wallet sync type |
| 247 // flag is disabled. | 157 // flag is disabled. |
| 248 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, ClearOnDisableWalletSync) { | 158 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, ClearOnDisableWalletSync) { |
| 249 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | |
| 250 AddDefaultCard(GetFakeServer()); | 159 AddDefaultCard(GetFakeServer()); |
| 251 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 160 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 252 | 161 |
| 253 // Make sure the card is in the DB. | 162 // Make sure the card is in the DB. |
| 254 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); | 163 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); |
| 255 ASSERT_TRUE(pdm != nullptr); | 164 ASSERT_TRUE(pdm != nullptr); |
| 256 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); | 165 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); |
| 257 ASSERT_EQ(1uL, cards.size()); | 166 ASSERT_EQ(1uL, cards.size()); |
| 258 | 167 |
| 259 // Turn off autofill sync, the card should be gone. | 168 // Turn off autofill sync, the card should be gone. |
| 260 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncer::AUTOFILL)); | 169 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncer::AUTOFILL)); |
| 261 cards = pdm->GetCreditCards(); | 170 cards = pdm->GetCreditCards(); |
| 262 ASSERT_EQ(0uL, cards.size()); | 171 ASSERT_EQ(0uL, cards.size()); |
| 263 } | 172 } |
| 264 | 173 |
| 265 // Wallet data should get cleared from the database when the wallet autofill | 174 // Wallet data should get cleared from the database when the wallet autofill |
| 266 // integration flag is disabled. | 175 // integration flag is disabled. |
| 267 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, | 176 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, |
| 268 ClearOnDisableWalletAutofill) { | 177 ClearOnDisableWalletAutofill) { |
| 269 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | |
| 270 AddDefaultCard(GetFakeServer()); | 178 AddDefaultCard(GetFakeServer()); |
| 271 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 179 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 272 | 180 |
| 273 // Make sure the card is in the DB. | 181 // Make sure the card is in the DB. |
| 274 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); | 182 autofill::PersonalDataManager* pdm = GetPersonalDataManager(0); |
| 275 ASSERT_TRUE(pdm != nullptr); | 183 ASSERT_TRUE(pdm != nullptr); |
| 276 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); | 184 std::vector<autofill::CreditCard*> cards = pdm->GetCreditCards(); |
| 277 ASSERT_EQ(1uL, cards.size()); | 185 ASSERT_EQ(1uL, cards.size()); |
| 278 | 186 |
| 279 // Turn off the wallet autofill pref, the card should be gone as a side | 187 // Turn off the wallet autofill pref, the card should be gone as a side |
| 280 // effect of the wallet data type controller noticing. | 188 // effect of the wallet data type controller noticing. |
| 281 GetProfile(0)->GetPrefs()->SetBoolean( | 189 GetProfile(0)->GetPrefs()->SetBoolean( |
| 282 autofill::prefs::kAutofillWalletImportEnabled, false); | 190 autofill::prefs::kAutofillWalletImportEnabled, false); |
| 283 cards = pdm->GetCreditCards(); | 191 cards = pdm->GetCreditCards(); |
| 284 ASSERT_EQ(0uL, cards.size()); | 192 ASSERT_EQ(0uL, cards.size()); |
| 285 } | 193 } |
| OLD | NEW |