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

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

Issue 2028193002: Migrate WaitableEvent to enum-based constructor in components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: rm comment explaining true/false Created 4 years, 6 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
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 class WebDataServiceFake : public AutofillWebDataService { 240 class WebDataServiceFake : public AutofillWebDataService {
241 public: 241 public:
242 WebDataServiceFake( 242 WebDataServiceFake(
243 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, 243 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
244 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) 244 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread)
245 : AutofillWebDataService(ui_thread, db_thread), 245 : AutofillWebDataService(ui_thread, db_thread),
246 web_database_(NULL), 246 web_database_(NULL),
247 autocomplete_syncable_service_(NULL), 247 autocomplete_syncable_service_(NULL),
248 autofill_profile_syncable_service_(NULL), 248 autofill_profile_syncable_service_(NULL),
249 syncable_service_created_or_destroyed_(false, false), 249 syncable_service_created_or_destroyed_(
250 base::WaitableEvent::ResetPolicy::AUTOMATIC,
251 base::WaitableEvent::InitialState::NOT_SIGNALED),
250 db_thread_(db_thread), 252 db_thread_(db_thread),
251 ui_thread_(ui_thread) {} 253 ui_thread_(ui_thread) {}
252 254
253 void SetDatabase(WebDatabase* web_database) { 255 void SetDatabase(WebDatabase* web_database) {
254 web_database_ = web_database; 256 web_database_ = web_database;
255 } 257 }
256 258
257 void StartSyncableService() { 259 void StartSyncableService() {
258 // The |autofill_profile_syncable_service_| must be constructed on the DB 260 // The |autofill_profile_syncable_service_| must be constructed on the DB
259 // thread. 261 // thread.
(...skipping 14 matching lines...) Expand all
274 base::Bind(&WebDataServiceFake::DestroySyncableService, 276 base::Bind(&WebDataServiceFake::DestroySyncableService,
275 base::Unretained(this))); 277 base::Unretained(this)));
276 syncable_service_created_or_destroyed_.Wait(); 278 syncable_service_created_or_destroyed_.Wait();
277 } 279 }
278 280
279 bool IsDatabaseLoaded() override { return true; } 281 bool IsDatabaseLoaded() override { return true; }
280 282
281 WebDatabase* GetDatabase() override { return web_database_; } 283 WebDatabase* GetDatabase() override { return web_database_; }
282 284
283 void OnAutofillEntriesChanged(const AutofillChangeList& changes) { 285 void OnAutofillEntriesChanged(const AutofillChangeList& changes) {
284 WaitableEvent event(true, false); 286 WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
287 base::WaitableEvent::InitialState::NOT_SIGNALED);
285 288
286 base::Closure notify_cb = 289 base::Closure notify_cb =
287 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged, 290 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged,
288 base::Unretained(autocomplete_syncable_service_), 291 base::Unretained(autocomplete_syncable_service_),
289 changes); 292 changes);
290 db_thread_->PostTask(FROM_HERE, 293 db_thread_->PostTask(FROM_HERE,
291 base::Bind(&RunAndSignal, notify_cb, &event)); 294 base::Bind(&RunAndSignal, notify_cb, &event));
292 event.Wait(); 295 event.Wait();
293 } 296 }
294 297
295 void OnAutofillProfileChanged(const AutofillProfileChange& changes) { 298 void OnAutofillProfileChanged(const AutofillProfileChange& changes) {
296 WaitableEvent event(true, false); 299 WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
300 base::WaitableEvent::InitialState::NOT_SIGNALED);
297 301
298 base::Closure notify_cb = 302 base::Closure notify_cb =
299 base::Bind(&AutocompleteSyncableService::AutofillProfileChanged, 303 base::Bind(&AutocompleteSyncableService::AutofillProfileChanged,
300 base::Unretained(autofill_profile_syncable_service_), 304 base::Unretained(autofill_profile_syncable_service_),
301 changes); 305 changes);
302 db_thread_->PostTask(FROM_HERE, 306 db_thread_->PostTask(FROM_HERE,
303 base::Bind(&RunAndSignal, notify_cb, &event)); 307 base::Bind(&RunAndSignal, notify_cb, &event));
304 event.Wait(); 308 event.Wait();
305 } 309 }
306 310
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { 707 class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> {
704 public: 708 public:
705 FakeServerUpdater(TestProfileSyncService* service, 709 FakeServerUpdater(TestProfileSyncService* service,
706 WaitableEvent* wait_for_start, 710 WaitableEvent* wait_for_start,
707 WaitableEvent* wait_for_syncapi, 711 WaitableEvent* wait_for_syncapi,
708 scoped_refptr<base::SequencedTaskRunner> db_thread) 712 scoped_refptr<base::SequencedTaskRunner> db_thread)
709 : entry_(MakeAutofillEntry("0", "0", 0)), 713 : entry_(MakeAutofillEntry("0", "0", 0)),
710 service_(service), 714 service_(service),
711 wait_for_start_(wait_for_start), 715 wait_for_start_(wait_for_start),
712 wait_for_syncapi_(wait_for_syncapi), 716 wait_for_syncapi_(wait_for_syncapi),
713 is_finished_(false, false), 717 is_finished_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
718 base::WaitableEvent::InitialState::NOT_SIGNALED),
714 db_thread_(db_thread) {} 719 db_thread_(db_thread) {}
715 720
716 void Update() { 721 void Update() {
717 // This gets called in a modelsafeworker thread. 722 // This gets called in a modelsafeworker thread.
718 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); 723 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread());
719 724
720 syncer::UserShare* user_share = service_->GetUserShare(); 725 syncer::UserShare* user_share = service_->GetUserShare();
721 syncer::syncable::Directory* directory = user_share->directory.get(); 726 syncer::syncable::Directory* directory = user_share->directory.get();
722 727
723 // Create autofill protobuf. 728 // Create autofill protobuf.
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 // On the other hand Autofill and Autocomplete are separated now, so 1414 // On the other hand Autofill and Autocomplete are separated now, so
1410 // GetAutofillProfiles() should not be called. 1415 // GetAutofillProfiles() should not be called.
1411 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)).Times(0); 1416 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)).Times(0);
1412 EXPECT_CALL(autofill_table(), UpdateAutofillEntries(_)) 1417 EXPECT_CALL(autofill_table(), UpdateAutofillEntries(_))
1413 .WillRepeatedly(Return(true)); 1418 .WillRepeatedly(Return(true));
1414 EXPECT_CALL(personal_data_manager(), Refresh()).Times(3); 1419 EXPECT_CALL(personal_data_manager(), Refresh()).Times(3);
1415 CreateRootHelper create_root(this, AUTOFILL); 1420 CreateRootHelper create_root(this, AUTOFILL);
1416 StartSyncService(create_root.callback(), false, AUTOFILL); 1421 StartSyncService(create_root.callback(), false, AUTOFILL);
1417 ASSERT_TRUE(create_root.success()); 1422 ASSERT_TRUE(create_root.success());
1418 1423
1419 // (true, false) means we have to reset after |Signal|, init to unsignaled. 1424 std::unique_ptr<WaitableEvent> wait_for_start(
1420 std::unique_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false)); 1425 new WaitableEvent(base::WaitableEvent::ResetPolicy::MANUAL,
1426 base::WaitableEvent::InitialState::NOT_SIGNALED));
1421 std::unique_ptr<WaitableEvent> wait_for_syncapi( 1427 std::unique_ptr<WaitableEvent> wait_for_syncapi(
1422 new WaitableEvent(true, false)); 1428 new WaitableEvent(base::WaitableEvent::ResetPolicy::MANUAL,
1429 base::WaitableEvent::InitialState::NOT_SIGNALED));
1423 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater( 1430 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater(
1424 sync_service(), wait_for_start.get(), wait_for_syncapi.get(), 1431 sync_service(), wait_for_start.get(), wait_for_syncapi.get(),
1425 data_type_thread()->task_runner())); 1432 data_type_thread()->task_runner()));
1426 1433
1427 // This server side update will stall waiting for CommitWaiter. 1434 // This server side update will stall waiting for CommitWaiter.
1428 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1)); 1435 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1));
1429 wait_for_start->Wait(); 1436 wait_for_start->Wait();
1430 1437
1431 AutofillEntry syncapi_entry(MakeAutofillEntry("syncapi", "entry", 2)); 1438 AutofillEntry syncapi_entry(MakeAutofillEntry("syncapi", "entry", 2));
1432 ASSERT_TRUE(AddAutofillSyncNode(syncapi_entry)); 1439 ASSERT_TRUE(AddAutofillSyncNode(syncapi_entry));
(...skipping 15 matching lines...) Expand all
1448 std::vector<AutofillEntry> sync_entries; 1455 std::vector<AutofillEntry> sync_entries;
1449 std::vector<AutofillProfile> sync_profiles; 1456 std::vector<AutofillProfile> sync_profiles;
1450 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1457 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1451 EXPECT_EQ(3U, sync_entries.size()); 1458 EXPECT_EQ(3U, sync_entries.size());
1452 EXPECT_EQ(0U, sync_profiles.size()); 1459 EXPECT_EQ(0U, sync_profiles.size());
1453 for (size_t i = 0; i < sync_entries.size(); i++) { 1460 for (size_t i = 0; i < sync_entries.size(); i++) {
1454 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1461 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1455 << ", " << sync_entries[i].key().value(); 1462 << ", " << sync_entries[i].key().value();
1456 } 1463 }
1457 } 1464 }
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_model.cc ('k') | components/font_service/public/cpp/font_service_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698