OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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/prefs/pref_registry_simple.h" | 5 #include "base/prefs/pref_registry_simple.h" |
6 #include "base/prefs/testing_pref_service.h" | 6 #include "base/prefs/testing_pref_service.h" |
7 #include "components/autofill/core/browser/autofill_test_utils.h" | 7 #include "components/autofill/core/browser/autofill_test_utils.h" |
8 #include "components/autofill/core/browser/options_util.h" | 8 #include "components/autofill/core/browser/options_util.h" |
9 #include "components/autofill/core/browser/test_personal_data_manager.h" | 9 #include "components/autofill/core/browser/test_personal_data_manager.h" |
10 #include "components/autofill/core/common/autofill_pref_names.h" | 10 #include "components/autofill/core/common/autofill_pref_names.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 return type_set_; | 39 return type_set_; |
40 } | 40 } |
41 bool CanSyncStart() const override { return can_sync_start_; } | 41 bool CanSyncStart() const override { return can_sync_start_; } |
42 | 42 |
43 private: | 43 private: |
44 syncer::ModelTypeSet type_set_; | 44 syncer::ModelTypeSet type_set_; |
45 bool can_sync_start_; | 45 bool can_sync_start_; |
46 }; | 46 }; |
47 | 47 |
48 scoped_ptr<TestSyncService> CreateSyncService(bool has_autofill_profile, | 48 scoped_ptr<TestSyncService> CreateSyncService(bool has_autofill_profile, |
49 bool has_autofill_wallet_data, | |
50 bool is_enabled_and_logged_in) { | 49 bool is_enabled_and_logged_in) { |
51 syncer::ModelTypeSet type_set; | 50 syncer::ModelTypeSet type_set; |
52 if (has_autofill_profile) | 51 if (has_autofill_profile) |
53 type_set.Put(syncer::AUTOFILL_PROFILE); | 52 type_set.Put(syncer::AUTOFILL_PROFILE); |
54 if (has_autofill_wallet_data) | |
55 type_set.Put(syncer::AUTOFILL_WALLET_DATA); | |
56 return make_scoped_ptr( | 53 return make_scoped_ptr( |
57 new TestSyncService(type_set, is_enabled_and_logged_in)); | 54 new TestSyncService(type_set, is_enabled_and_logged_in)); |
58 } | 55 } |
59 | 56 |
60 scoped_ptr<TestingPrefServiceSimple> CreatePrefService( | 57 scoped_ptr<TestingPrefServiceSimple> CreatePrefService( |
61 bool autofill_enabled, | |
62 bool autofill_wallet_import_enabled, | 58 bool autofill_wallet_import_enabled, |
63 bool autofill_wallet_sync_experiment_enabled) { | 59 bool autofill_wallet_sync_experiment_enabled) { |
64 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); | 60 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); |
65 prefs->registry()->RegisterBooleanPref(prefs::kAutofillEnabled, | 61 prefs->registry()->RegisterBooleanPref(prefs::kAutofillEnabled, true); |
66 autofill_enabled); | |
67 prefs->registry()->RegisterBooleanPref(prefs::kAutofillWalletImportEnabled, | 62 prefs->registry()->RegisterBooleanPref(prefs::kAutofillWalletImportEnabled, |
68 autofill_wallet_import_enabled); | 63 autofill_wallet_import_enabled); |
69 prefs->registry()->RegisterBooleanPref( | 64 prefs->registry()->RegisterBooleanPref( |
70 prefs::kAutofillWalletSyncExperimentEnabled, | 65 prefs::kAutofillWalletSyncExperimentEnabled, |
71 autofill_wallet_sync_experiment_enabled); | 66 autofill_wallet_sync_experiment_enabled); |
72 | 67 |
73 return prefs; | 68 return prefs; |
74 } | 69 } |
75 | 70 |
76 scoped_ptr<TestPersonalDataManager> CreatePersonalDataManager( | 71 scoped_ptr<TestPersonalDataManager> CreatePersonalDataManager( |
77 PrefService* prefs, | 72 PrefService* prefs) { |
78 bool has_server_data) { | |
79 scoped_ptr<TestPersonalDataManager> pdm(new TestPersonalDataManager()); | 73 scoped_ptr<TestPersonalDataManager> pdm(new TestPersonalDataManager()); |
80 pdm->SetTestingPrefService(prefs); | 74 pdm->SetTestingPrefService(prefs); |
81 if (has_server_data) { | |
82 // This will cause pdm->HasServerData() to return true. | |
83 pdm->AddTestingServerCreditCard(test::GetVerifiedCreditCard()); | |
84 } | |
85 | |
86 return pdm; | 75 return pdm; |
87 } | 76 } |
88 | 77 |
89 } // namespace | 78 } // namespace |
90 | 79 |
91 // Verify that true is returned when all inputs are complete. | 80 // Verify that true is returned when all inputs are complete. |
92 TEST(WalletIntegrationAvailableTest, AllInputsComplete) { | 81 TEST(WalletIntegrationAvailableTest, AllInputsComplete) { |
93 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true, true); | 82 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); |
94 scoped_ptr<TestingPrefServiceSimple> prefs = | 83 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(true, true); |
95 CreatePrefService(true, true, true); | |
96 scoped_ptr<TestPersonalDataManager> pdm = | 84 scoped_ptr<TestPersonalDataManager> pdm = |
97 CreatePersonalDataManager(prefs.get(), true); | 85 CreatePersonalDataManager(prefs.get()); |
98 | 86 |
99 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | 87 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); |
| 88 } |
| 89 |
| 90 // Verify that true is returned even if wallet import is disabled. (Otherwise |
| 91 // the user will never be able to enable it). |
| 92 TEST(WalletIntegrationAvailableTest, WalletImportDisabled) { |
| 93 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); |
| 94 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(false, true); |
| 95 scoped_ptr<TestPersonalDataManager> pdm = |
| 96 CreatePersonalDataManager(prefs.get()); |
| 97 |
| 98 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); |
100 } | 99 } |
101 | 100 |
102 // Verify that false is returned when SyncService is missing or incomplete. | 101 // Verify that false is returned when SyncService is missing or incomplete. |
103 TEST(WalletIntegrationAvailableTest, MissingOrIncompleteSyncService) { | 102 TEST(WalletIntegrationAvailableTest, MissingOrIncompleteSyncService) { |
104 // Setup |prefs| and |pdm| to do their part to make | 103 // Setup |prefs| and |pdm| to do their part to make |
105 // WalletIntegrationAvailable() return true. | 104 // WalletIntegrationAvailable() return true. |
106 scoped_ptr<TestingPrefServiceSimple> prefs = | 105 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(true, true); |
107 CreatePrefService(true, true, true); | |
108 scoped_ptr<TestPersonalDataManager> pdm = | 106 scoped_ptr<TestPersonalDataManager> pdm = |
109 CreatePersonalDataManager(prefs.get(), true); | 107 CreatePersonalDataManager(prefs.get()); |
110 | 108 |
111 // Incomplete SyncService data should return false. | 109 // Incomplete SyncService data should return false. |
112 EXPECT_FALSE(WalletIntegrationAvailable(NULL, *prefs, *pdm)); | 110 EXPECT_FALSE(WalletIntegrationAvailable(NULL, *pdm)); |
113 | 111 |
114 scoped_ptr<TestSyncService> sync = CreateSyncService(false, false, false); | 112 scoped_ptr<TestSyncService> sync = CreateSyncService(false, false); |
115 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | 113 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); |
116 | 114 |
117 sync = CreateSyncService(false, false, true); | 115 sync = CreateSyncService(false, true); |
118 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | 116 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); |
119 | 117 |
120 sync = CreateSyncService(true, false, false); | 118 sync = CreateSyncService(true, false); |
121 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | 119 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); |
122 | 120 |
123 // Complete SyncService data should return true. | 121 // Complete SyncService data should return true. |
124 sync = CreateSyncService(true, true, true); | 122 sync = CreateSyncService(true, true); |
125 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | 123 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); |
126 } | 124 } |
127 | 125 |
128 // Verify that false is returned when | 126 // Verify that false is returned when |
129 // !prefs::kAutofillWalletSyncExperimentEnabled. | 127 // !prefs::kAutofillWalletSyncExperimentEnabled. |
130 TEST(WalletIntegrationAvailableTest, ExperimentalWalletIntegrationDisabled) { | 128 TEST(WalletIntegrationAvailableTest, ExperimentalWalletIntegrationDisabled) { |
131 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true, true); | 129 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); |
132 // Set kAutofillWalletSyncExperimentEnabled to false. | 130 // Set kAutofillWalletSyncExperimentEnabled to false. |
133 scoped_ptr<TestingPrefServiceSimple> prefs = | 131 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(true, false); |
134 CreatePrefService(true, true, false); | |
135 scoped_ptr<TestPersonalDataManager> pdm = | 132 scoped_ptr<TestPersonalDataManager> pdm = |
136 CreatePersonalDataManager(prefs.get(), true); | 133 CreatePersonalDataManager(prefs.get()); |
137 | 134 |
138 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | 135 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); |
139 } | |
140 | |
141 // Verify that false is returned if server data is missing. | |
142 TEST(WalletIntegrationAvailableTest, NoServerData) { | |
143 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true, true); | |
144 scoped_ptr<TestingPrefServiceSimple> prefs = | |
145 CreatePrefService(true, true, true); | |
146 // Set server data as missing. | |
147 scoped_ptr<TestPersonalDataManager> pdm = | |
148 CreatePersonalDataManager(prefs.get(), false); | |
149 | |
150 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | |
151 } | |
152 | |
153 // Verify that true is returned when !prefs::kAutofillWalletImportEnabled, | |
154 // even if server data is missing. | |
155 TEST(WalletIntegrationAvailableTest, WalletImportDisabled) { | |
156 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true, true); | |
157 // Set kAutofillWalletImportEnabled to false. | |
158 scoped_ptr<TestingPrefServiceSimple> prefs = | |
159 CreatePrefService(true, false, true); | |
160 // Set server data as missing. | |
161 scoped_ptr<TestPersonalDataManager> pdm = | |
162 CreatePersonalDataManager(prefs.get(), false); | |
163 | |
164 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | |
165 } | |
166 | |
167 // Verify that true is returned when data hasn't been synced yet, even if | |
168 // server data is missing. | |
169 TEST(WalletIntegrationAvailableTest, WalletDataNotSyncedYet) { | |
170 // Set wallet data as not synced yet. | |
171 scoped_ptr<TestSyncService> sync = CreateSyncService(true, false, true); | |
172 scoped_ptr<TestingPrefServiceSimple> prefs = | |
173 CreatePrefService(true, true, true); | |
174 // Set server data as missing. | |
175 scoped_ptr<TestPersonalDataManager> pdm = | |
176 CreatePersonalDataManager(prefs.get(), false); | |
177 | |
178 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *prefs, *pdm)); | |
179 } | 136 } |
180 | 137 |
181 } // namespace autofill | 138 } // namespace autofill |
OLD | NEW |