Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/browser_sync/browser/profile_sync_service_autofill_unittest.cc

Issue 2142123002: [Autofill] Run autofill-profile de-dupe after sync starts if sync is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better logging and fix mathp's comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/autofill/core/browser/webdata/autofill_webdata_service_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 27 matching lines...) Expand all
38 #include "components/autofill/core/browser/webdata/autofill_table.h" 38 #include "components/autofill/core/browser/webdata/autofill_table.h"
39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
40 #include "components/autofill/core/common/autofill_pref_names.h" 40 #include "components/autofill/core/common/autofill_pref_names.h"
41 #include "components/browser_sync/browser/abstract_profile_sync_service_test.h" 41 #include "components/browser_sync/browser/abstract_profile_sync_service_test.h"
42 #include "components/browser_sync/browser/profile_sync_service.h" 42 #include "components/browser_sync/browser/profile_sync_service.h"
43 #include "components/browser_sync/browser/test_profile_sync_service.h" 43 #include "components/browser_sync/browser/test_profile_sync_service.h"
44 #include "components/sync_driver/data_type_controller.h" 44 #include "components/sync_driver/data_type_controller.h"
45 #include "components/sync_driver/data_type_manager_impl.h" 45 #include "components/sync_driver/data_type_manager_impl.h"
46 #include "components/sync_driver/sync_api_component_factory_mock.h" 46 #include "components/sync_driver/sync_api_component_factory_mock.h"
47 #include "components/syncable_prefs/pref_service_syncable.h" 47 #include "components/syncable_prefs/pref_service_syncable.h"
48 #include "components/version_info/version_info.h"
48 #include "components/webdata/common/web_database.h" 49 #include "components/webdata/common/web_database.h"
49 #include "components/webdata_services/web_data_service_test_util.h" 50 #include "components/webdata_services/web_data_service_test_util.h"
50 #include "sync/internal_api/public/base/model_type.h" 51 #include "sync/internal_api/public/base/model_type.h"
51 #include "sync/internal_api/public/data_type_debug_info_listener.h" 52 #include "sync/internal_api/public/data_type_debug_info_listener.h"
52 #include "sync/internal_api/public/read_node.h" 53 #include "sync/internal_api/public/read_node.h"
53 #include "sync/internal_api/public/read_transaction.h" 54 #include "sync/internal_api/public/read_transaction.h"
54 #include "sync/internal_api/public/write_node.h" 55 #include "sync/internal_api/public/write_node.h"
55 #include "sync/internal_api/public/write_transaction.h" 56 #include "sync/internal_api/public/write_transaction.h"
56 #include "sync/protocol/autofill_specifics.pb.h" 57 #include "sync/protocol/autofill_specifics.pb.h"
57 #include "sync/syncable/mutable_entry.h" 58 #include "sync/syncable/mutable_entry.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 using testing::Not; 94 using testing::Not;
94 using testing::SetArgumentPointee; 95 using testing::SetArgumentPointee;
95 using testing::Return; 96 using testing::Return;
96 97
97 namespace { 98 namespace {
98 99
99 void RegisterAutofillPrefs(user_prefs::PrefRegistrySyncable* registry) { 100 void RegisterAutofillPrefs(user_prefs::PrefRegistrySyncable* registry) {
100 registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true); 101 registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true);
101 registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled, 102 registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled,
102 true); 103 true);
104 registry->RegisterIntegerPref(autofill::prefs::kAutofillLastVersionDeduped,
105 atoi(version_info::GetVersionNumber().c_str()));
103 } 106 }
104 107
105 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) { 108 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) {
106 cb.Run(); 109 cb.Run();
107 event->Signal(); 110 event->Signal();
108 } 111 }
109 112
110 AutofillEntry MakeAutofillEntry(const char* name, 113 AutofillEntry MakeAutofillEntry(const char* name,
111 const char* value, 114 const char* value,
112 int time_shift0, 115 int time_shift0,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 165
163 class WebDatabaseFake : public WebDatabase { 166 class WebDatabaseFake : public WebDatabase {
164 public: 167 public:
165 explicit WebDatabaseFake(AutofillTable* autofill_table) { 168 explicit WebDatabaseFake(AutofillTable* autofill_table) {
166 AddTable(autofill_table); 169 AddTable(autofill_table);
167 } 170 }
168 }; 171 };
169 172
170 class MockAutofillBackend : public autofill::AutofillWebDataBackend { 173 class MockAutofillBackend : public autofill::AutofillWebDataBackend {
171 public: 174 public:
172 MockAutofillBackend(WebDatabase* web_database, 175 MockAutofillBackend(
173 const base::Closure& on_changed, 176 WebDatabase* web_database,
174 const scoped_refptr<base::SequencedTaskRunner>& ui_thread) 177 const base::Closure& on_changed,
178 const base::Callback<void(syncer::ModelType)>& on_sync_started,
179 const scoped_refptr<base::SequencedTaskRunner>& ui_thread)
175 : web_database_(web_database), 180 : web_database_(web_database),
176 on_changed_(on_changed), 181 on_changed_(on_changed),
182 on_sync_started_(on_sync_started),
177 ui_thread_(ui_thread) {} 183 ui_thread_(ui_thread) {}
178 184
179 ~MockAutofillBackend() override {} 185 ~MockAutofillBackend() override {}
180 WebDatabase* GetDatabase() override { return web_database_; } 186 WebDatabase* GetDatabase() override { return web_database_; }
181 void AddObserver( 187 void AddObserver(
182 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} 188 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {}
183 void RemoveObserver( 189 void RemoveObserver(
184 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} 190 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {}
185 void RemoveExpiredFormElements() override {} 191 void RemoveExpiredFormElements() override {}
186 void NotifyOfMultipleAutofillChanges() override { 192 void NotifyOfMultipleAutofillChanges() override {
187 DCHECK(!ui_thread_->RunsTasksOnCurrentThread()); 193 DCHECK(!ui_thread_->RunsTasksOnCurrentThread());
188 ui_thread_->PostTask(FROM_HERE, on_changed_); 194 ui_thread_->PostTask(FROM_HERE, on_changed_);
189 } 195 }
196 void NotifyThatSyncHasStarted(syncer::ModelType model_type) override {
197 DCHECK(!ui_thread_->RunsTasksOnCurrentThread());
198 ui_thread_->PostTask(FROM_HERE, base::Bind(on_sync_started_, model_type));
199 }
190 200
191 private: 201 private:
192 WebDatabase* web_database_; 202 WebDatabase* web_database_;
193 base::Closure on_changed_; 203 base::Closure on_changed_;
204 base::Callback<void(syncer::ModelType)> on_sync_started_;
194 const scoped_refptr<base::SequencedTaskRunner> ui_thread_; 205 const scoped_refptr<base::SequencedTaskRunner> ui_thread_;
195 }; 206 };
196 207
197 class ProfileSyncServiceAutofillTest; 208 class ProfileSyncServiceAutofillTest;
198 209
199 template<class AutofillProfile> 210 template<class AutofillProfile>
200 syncer::ModelType GetModelType() { 211 syncer::ModelType GetModelType() {
201 return syncer::UNSPECIFIED; 212 return syncer::UNSPECIFIED;
202 } 213 }
203 214
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void SetDatabase(WebDatabase* web_database) { 267 void SetDatabase(WebDatabase* web_database) {
257 web_database_ = web_database; 268 web_database_ = web_database;
258 } 269 }
259 270
260 void StartSyncableService() { 271 void StartSyncableService() {
261 // The |autofill_profile_syncable_service_| must be constructed on the DB 272 // The |autofill_profile_syncable_service_| must be constructed on the DB
262 // thread. 273 // thread.
263 const base::Closure& on_changed_callback = base::Bind( 274 const base::Closure& on_changed_callback = base::Bind(
264 &WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread, 275 &WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread,
265 AsWeakPtr()); 276 AsWeakPtr());
277 const base::Callback<void(syncer::ModelType)> on_sync_started_callback =
278 base::Bind(&WebDataServiceFake::NotifySyncStartedOnUIThread,
279 AsWeakPtr());
266 280
267 db_thread_->PostTask( 281 db_thread_->PostTask(FROM_HERE,
268 FROM_HERE, base::Bind(&WebDataServiceFake::CreateSyncableService, 282 base::Bind(&WebDataServiceFake::CreateSyncableService,
269 base::Unretained(this), on_changed_callback)); 283 base::Unretained(this), on_changed_callback,
284 on_sync_started_callback));
270 syncable_service_created_or_destroyed_.Wait(); 285 syncable_service_created_or_destroyed_.Wait();
271 } 286 }
272 287
273 void ShutdownSyncableService() { 288 void ShutdownSyncableService() {
274 // The |autofill_profile_syncable_service_| must be destructed on the DB 289 // The |autofill_profile_syncable_service_| must be destructed on the DB
275 // thread. 290 // thread.
276 db_thread_->PostTask(FROM_HERE, 291 db_thread_->PostTask(FROM_HERE,
277 base::Bind(&WebDataServiceFake::DestroySyncableService, 292 base::Bind(&WebDataServiceFake::DestroySyncableService,
278 base::Unretained(this))); 293 base::Unretained(this)));
279 syncable_service_created_or_destroyed_.Wait(); 294 syncable_service_created_or_destroyed_.Wait();
(...skipping 25 matching lines...) Expand all
305 base::Unretained(autofill_profile_syncable_service_), 320 base::Unretained(autofill_profile_syncable_service_),
306 changes); 321 changes);
307 db_thread_->PostTask(FROM_HERE, 322 db_thread_->PostTask(FROM_HERE,
308 base::Bind(&RunAndSignal, notify_cb, &event)); 323 base::Bind(&RunAndSignal, notify_cb, &event));
309 event.Wait(); 324 event.Wait();
310 } 325 }
311 326
312 private: 327 private:
313 ~WebDataServiceFake() override {} 328 ~WebDataServiceFake() override {}
314 329
315 void CreateSyncableService(const base::Closure& on_changed_callback) { 330 void CreateSyncableService(
331 const base::Closure& on_changed_callback,
332 const base::Callback<void(syncer::ModelType)>& on_sync_started) {
316 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); 333 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread());
317 // These services are deleted in DestroySyncableService(). 334 // These services are deleted in DestroySyncableService().
318 backend_.reset(new MockAutofillBackend(GetDatabase(), on_changed_callback, 335 backend_.reset(new MockAutofillBackend(GetDatabase(), on_changed_callback,
319 ui_thread_.get())); 336 on_sync_started, ui_thread_.get()));
320 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( 337 AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
321 this, backend_.get()); 338 this, backend_.get());
322 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( 339 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
323 this, backend_.get(), "en-US"); 340 this, backend_.get(), "en-US");
324 341
325 autocomplete_syncable_service_ = 342 autocomplete_syncable_service_ =
326 AutocompleteSyncableService::FromWebDataService(this); 343 AutocompleteSyncableService::FromWebDataService(this);
327 autofill_profile_syncable_service_ = 344 autofill_profile_syncable_service_ =
328 AutofillProfileSyncableService::FromWebDataService(this); 345 AutofillProfileSyncableService::FromWebDataService(this);
329 346
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 std::vector<AutofillEntry> sync_entries; 1478 std::vector<AutofillEntry> sync_entries;
1462 std::vector<AutofillProfile> sync_profiles; 1479 std::vector<AutofillProfile> sync_profiles;
1463 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1480 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1464 EXPECT_EQ(3U, sync_entries.size()); 1481 EXPECT_EQ(3U, sync_entries.size());
1465 EXPECT_EQ(0U, sync_profiles.size()); 1482 EXPECT_EQ(0U, sync_profiles.size());
1466 for (size_t i = 0; i < sync_entries.size(); i++) { 1483 for (size_t i = 0; i < sync_entries.size(); i++) {
1467 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1484 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1468 << ", " << sync_entries[i].key().value(); 1485 << ", " << sync_entries[i].key().value();
1469 } 1486 }
1470 } 1487 }
OLDNEW
« no previous file with comments | « components/autofill/core/browser/webdata/autofill_webdata_service_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698