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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.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" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" |
9 #include "chrome/browser/sync/test/integration/autofill_helper.h" | 11 #include "chrome/browser/sync/test/integration/autofill_helper.h" |
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 13 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
11 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 14 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
12 #include "chrome/browser/sync/test/integration/sync_test.h" | 15 #include "chrome/browser/sync/test/integration/sync_test.h" |
13 #include "components/autofill/core/browser/credit_card.h" | 16 #include "components/autofill/core/browser/credit_card.h" |
14 #include "components/autofill/core/browser/field_types.h" | 17 #include "components/autofill/core/browser/field_types.h" |
15 #include "components/autofill/core/browser/personal_data_manager.h" | 18 #include "components/autofill/core/browser/personal_data_manager.h" |
| 19 #include "content/public/browser/notification_service.h" |
16 #include "sync/internal_api/public/base/model_type.h" | 20 #include "sync/internal_api/public/base/model_type.h" |
17 #include "sync/test/fake_server/fake_server_entity.h" | 21 #include "sync/test/fake_server/fake_server_entity.h" |
18 #include "sync/test/fake_server/unique_client_entity.h" | 22 #include "sync/test/fake_server/unique_client_entity.h" |
19 | 23 |
20 using autofill_helper::GetPersonalDataManager; | 24 using autofill_helper::GetPersonalDataManager; |
21 using sync_integration_test_util::AwaitCommitActivityCompletion; | 25 using sync_integration_test_util::AwaitCommitActivityCompletion; |
22 | 26 |
23 namespace { | 27 namespace { |
24 | 28 |
25 // Setting the Preferences files contents to this string (before Profile is | 29 // Setting the Preferences files contents to this string (before Profile is |
26 // created) will bypass the Sync experiment logic for enabling this feature. | 30 // created) will bypass the Sync experiment logic for enabling this feature. |
27 const char kWalletSyncEnabledPreferencesContents[] = | 31 const char kWalletSyncEnabledPreferencesContents[] = |
28 "{\"autofill\": { \"wallet_import_sync_experiment_enabled\": true } }"; | 32 "{\"autofill\": { \"wallet_import_sync_experiment_enabled\": true } }"; |
29 | 33 |
| 34 const char kWalletSyncExperimentTag[] = "wallet_sync"; |
| 35 |
30 } // namespace | 36 } // namespace |
31 | 37 |
32 class SingleClientWalletSyncTest : public SyncTest { | 38 class SingleClientWalletSyncTest : public SyncTest { |
33 public: | 39 public: |
34 SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {} | 40 SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {} |
35 ~SingleClientWalletSyncTest() override {} | 41 ~SingleClientWalletSyncTest() override {} |
36 | 42 |
| 43 void TriggerSyncCycle() { |
| 44 // Note: we use the experiments type here as we want to be able to trigger a |
| 45 // sync cycle even when wallet is not enabled yet. |
| 46 const syncer::ModelTypeSet kExperimentsType(syncer::EXPERIMENTS); |
| 47 content::NotificationService::current()->Notify( |
| 48 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 49 content::Source<Profile>(GetProfile(0)), |
| 50 content::Details<const syncer::ModelTypeSet>(&kExperimentsType)); |
| 51 } |
| 52 |
37 private: | 53 private: |
38 DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSyncTest); | 54 DISALLOW_COPY_AND_ASSIGN(SingleClientWalletSyncTest); |
39 }; | 55 }; |
40 | 56 |
| 57 // Checker that will wait until an asynchronous Wallet datatype enable event |
| 58 // happens, or times out. |
| 59 class WalletEnabledChecker : public SingleClientStatusChangeChecker { |
| 60 public: |
| 61 WalletEnabledChecker() |
| 62 : SingleClientStatusChangeChecker( |
| 63 sync_datatype_helper::test()->GetSyncService(0)) {} |
| 64 ~WalletEnabledChecker() override {} |
| 65 |
| 66 // SingleClientStatusChangeChecker overrides. |
| 67 bool IsExitConditionSatisfied() override { |
| 68 return service()->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA); |
| 69 } |
| 70 std::string GetDebugMessage() const override { |
| 71 return "Waiting for wallet enable event."; |
| 72 } |
| 73 }; |
| 74 |
| 75 // Checker that will wait until an asynchronous Wallet datatype disable event |
| 76 // happens, or times out |
| 77 class WalletDisabledChecker : public SingleClientStatusChangeChecker { |
| 78 public: |
| 79 WalletDisabledChecker() |
| 80 : SingleClientStatusChangeChecker( |
| 81 sync_datatype_helper::test()->GetSyncService(0)) {} |
| 82 ~WalletDisabledChecker() override {} |
| 83 |
| 84 // SingleClientStatusChangeChecker overrides. |
| 85 bool IsExitConditionSatisfied() override { |
| 86 return !service()->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA); |
| 87 } |
| 88 std::string GetDebugMessage() const override { |
| 89 return "Waiting for wallet disable event."; |
| 90 } |
| 91 }; |
| 92 |
41 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, DisabledByDefault) { | 93 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, DisabledByDefault) { |
42 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 94 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
43 // The type should not be enabled without the experiment enabled. | 95 // The type should not be enabled without the experiment enabled. |
44 ASSERT_FALSE(GetClient(0)->IsTypePreferred(syncer::AUTOFILL_WALLET_DATA)); | 96 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes().Has( |
| 97 syncer::AUTOFILL_WALLET_DATA)); |
45 } | 98 } |
46 | 99 |
47 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, EnabledViaPreference) { | 100 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, EnabledViaPreference) { |
48 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | 101 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); |
49 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; | 102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
50 // The type should not be enabled without the experiment enabled. | 103 // The type should not be enabled without the experiment enabled. |
51 ASSERT_TRUE(GetClient(0)->IsTypePreferred(syncer::AUTOFILL_WALLET_DATA)); | 104 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( |
| 105 syncer::AUTOFILL_WALLET_DATA)); |
52 // TODO(pvalenzuela): Assert that the local root node for AUTOFILL_WALLET_DATA | 106 // TODO(pvalenzuela): Assert that the local root node for AUTOFILL_WALLET_DATA |
53 // exists. | 107 // exists. |
54 } | 108 } |
55 | 109 |
| 110 // Tests that an experiment received at sync startup time (during sign-in) |
| 111 // enables the wallet datatype. |
| 112 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, |
| 113 EnabledViaExperimentStartup) { |
| 114 sync_pb::EntitySpecifics experiment_entity; |
| 115 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 116 experiment_entity.mutable_experiments(); |
| 117 experiment_specifics->mutable_wallet_sync()->set_enabled(true); |
| 118 GetFakeServer()->InjectEntity( |
| 119 fake_server::UniqueClientEntity::CreateForInjection( |
| 120 syncer::EXPERIMENTS, |
| 121 kWalletSyncExperimentTag, |
| 122 experiment_entity)); |
| 123 |
| 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 125 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( |
| 126 syncer::AUTOFILL_WALLET_DATA)); |
| 127 } |
| 128 |
| 129 // Tests receiving an enable experiment at runtime, followed by a disabled |
| 130 // experiment, and verifies the datatype is enabled/disabled as necessary. |
| 131 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, |
| 132 EnabledDisabledViaExperiment) { |
| 133 ASSERT_TRUE(SetupSync()) << "SetupSync() failed"; |
| 134 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes(). |
| 135 Has(syncer::AUTOFILL_WALLET_DATA)); |
| 136 |
| 137 sync_pb::EntitySpecifics experiment_entity; |
| 138 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 139 experiment_entity.mutable_experiments(); |
| 140 |
| 141 // First enable the experiment. |
| 142 experiment_specifics->mutable_wallet_sync()->set_enabled(true); |
| 143 GetFakeServer()->InjectEntity( |
| 144 fake_server::UniqueClientEntity::CreateForInjection( |
| 145 syncer::EXPERIMENTS, kWalletSyncExperimentTag, experiment_entity)); |
| 146 TriggerSyncCycle(); |
| 147 |
| 148 WalletEnabledChecker enabled_checker; |
| 149 enabled_checker.Wait(); |
| 150 ASSERT_FALSE(enabled_checker.TimedOut()); |
| 151 ASSERT_TRUE(GetClient(0)->service()->GetActiveDataTypes().Has( |
| 152 syncer::AUTOFILL_WALLET_DATA)); |
| 153 |
| 154 // Then disable the experiment. |
| 155 experiment_specifics->mutable_wallet_sync()->set_enabled(false); |
| 156 GetFakeServer()->InjectEntity( |
| 157 fake_server::UniqueClientEntity::CreateForInjection( |
| 158 syncer::EXPERIMENTS, kWalletSyncExperimentTag, experiment_entity)); |
| 159 TriggerSyncCycle(); |
| 160 |
| 161 WalletDisabledChecker disable_checker; |
| 162 disable_checker.Wait(); |
| 163 ASSERT_FALSE(disable_checker.TimedOut()); |
| 164 ASSERT_FALSE(GetClient(0)->service()->GetActiveDataTypes(). |
| 165 Has(syncer::AUTOFILL_WALLET_DATA)); |
| 166 } |
| 167 |
56 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) { | 168 IN_PROC_BROWSER_TEST_F(SingleClientWalletSyncTest, Download) { |
57 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); | 169 SetPreexistingPreferencesFileContents(kWalletSyncEnabledPreferencesContents); |
58 | 170 |
59 std::string id = "wallet entity ID"; | 171 std::string id = "wallet entity ID"; |
60 int expiration_month = 8; | 172 int expiration_month = 8; |
61 int expiration_year = 2087; | 173 int expiration_year = 2087; |
62 std::string last_four_digits = "1234"; | 174 std::string last_four_digits = "1234"; |
63 std::string name_on_card = "Patrick Valenzuela"; | 175 std::string name_on_card = "Patrick Valenzuela"; |
64 | 176 |
65 sync_pb::EntitySpecifics specifics; | 177 sync_pb::EntitySpecifics specifics; |
(...skipping 28 matching lines...) Expand all Loading... |
94 autofill::CreditCard* card = cards[0]; | 206 autofill::CreditCard* card = cards[0]; |
95 ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type()); | 207 ASSERT_EQ(autofill::CreditCard::MASKED_SERVER_CARD, card->record_type()); |
96 ASSERT_EQ(id, card->server_id()); | 208 ASSERT_EQ(id, card->server_id()); |
97 ASSERT_EQ(base::UTF8ToUTF16(last_four_digits), card->LastFourDigits()); | 209 ASSERT_EQ(base::UTF8ToUTF16(last_four_digits), card->LastFourDigits()); |
98 ASSERT_EQ(autofill::kAmericanExpressCard, card->type()); | 210 ASSERT_EQ(autofill::kAmericanExpressCard, card->type()); |
99 ASSERT_EQ(expiration_month, card->expiration_month()); | 211 ASSERT_EQ(expiration_month, card->expiration_month()); |
100 ASSERT_EQ(expiration_year, card->expiration_year()); | 212 ASSERT_EQ(expiration_year, card->expiration_year()); |
101 ASSERT_EQ(base::UTF8ToUTF16(name_on_card), | 213 ASSERT_EQ(base::UTF8ToUTF16(name_on_card), |
102 card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME)); | 214 card->GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME)); |
103 } | 215 } |
OLD | NEW |