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

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 using base::Time; 62 using base::Time;
63 using base::TimeDelta; 63 using base::TimeDelta;
64 using base::WaitableEvent; 64 using base::WaitableEvent;
65 using browser_sync::AutofillDataTypeController; 65 using browser_sync::AutofillDataTypeController;
66 using browser_sync::AutofillProfileDataTypeController; 66 using browser_sync::AutofillProfileDataTypeController;
67 using browser_sync::DataTypeController; 67 using browser_sync::DataTypeController;
68 using browser_sync::GenericChangeProcessor; 68 using browser_sync::GenericChangeProcessor;
69 using browser_sync::SharedChangeProcessor; 69 using browser_sync::SharedChangeProcessor;
70 using content::BrowserThread; 70 using content::BrowserThread;
71 using syncer::syncable::AUTOFILL; 71 using syncer::AUTOFILL;
72 using syncer::BaseNode;
72 using syncer::syncable::BASE_VERSION; 73 using syncer::syncable::BASE_VERSION;
73 using syncer::syncable::CREATE; 74 using syncer::syncable::CREATE;
74 using syncer::syncable::GET_BY_SERVER_TAG; 75 using syncer::syncable::GET_BY_SERVER_TAG;
75 using syncer::syncable::MutableEntry; 76 using syncer::syncable::MutableEntry;
76 using syncer::syncable::SERVER_SPECIFICS; 77 using syncer::syncable::SERVER_SPECIFICS;
77 using syncer::syncable::SPECIFICS; 78 using syncer::syncable::SPECIFICS;
78 using syncer::syncable::UNITTEST; 79 using syncer::syncable::UNITTEST;
79 using syncer::syncable::WriterTag; 80 using syncer::syncable::WriterTag;
80 using syncer::syncable::WriteTransaction; 81 using syncer::syncable::WriteTransaction;
81 using syncer::BaseNode;
82 using testing::_; 82 using testing::_;
83 using testing::DoAll; 83 using testing::DoAll;
84 using testing::ElementsAre; 84 using testing::ElementsAre;
85 using testing::SetArgumentPointee; 85 using testing::SetArgumentPointee;
86 using testing::Return; 86 using testing::Return;
87 87
88 namespace syncable { 88 namespace syncable {
89 class Id; 89 class Id;
90 } 90 }
91 91
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return autofill_table_; 128 return autofill_table_;
129 } 129 }
130 130
131 private: 131 private:
132 AutofillTable* autofill_table_; 132 AutofillTable* autofill_table_;
133 }; 133 };
134 134
135 class ProfileSyncServiceAutofillTest; 135 class ProfileSyncServiceAutofillTest;
136 136
137 template<class AutofillProfile> 137 template<class AutofillProfile>
138 syncable::ModelType GetModelType() { 138 syncer::ModelType GetModelType() {
139 return syncable::UNSPECIFIED; 139 return syncer::UNSPECIFIED;
140 } 140 }
141 141
142 template<> 142 template<>
143 syncable::ModelType GetModelType<AutofillEntry>() { 143 syncer::ModelType GetModelType<AutofillEntry>() {
144 return syncable::AUTOFILL; 144 return syncer::AUTOFILL;
145 } 145 }
146 146
147 template<> 147 template<>
148 syncable::ModelType GetModelType<AutofillProfile>() { 148 syncer::ModelType GetModelType<AutofillProfile>() {
149 return syncable::AUTOFILL_PROFILE; 149 return syncer::AUTOFILL_PROFILE;
150 } 150 }
151 151
152 class WebDataServiceFake : public WebDataService { 152 class WebDataServiceFake : public WebDataService {
153 public: 153 public:
154 WebDataServiceFake() 154 WebDataServiceFake()
155 : web_database_(NULL), 155 : web_database_(NULL),
156 syncable_service_created_or_destroyed_(false, false) { 156 syncable_service_created_or_destroyed_(false, false) {
157 } 157 }
158 158
159 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { 159 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 296 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
297 ProfileSyncService* service, 297 ProfileSyncService* service,
298 WebDataService* wds, 298 WebDataService* wds,
299 DataTypeController* dtc) OVERRIDE { 299 DataTypeController* dtc) OVERRIDE {
300 EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)). 300 EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)).
301 WillOnce(MakeGenericChangeProcessor()); 301 WillOnce(MakeGenericChangeProcessor());
302 EXPECT_CALL(*factory, CreateSharedChangeProcessor()). 302 EXPECT_CALL(*factory, CreateSharedChangeProcessor()).
303 WillOnce(MakeSharedChangeProcessor()); 303 WillOnce(MakeSharedChangeProcessor());
304 EXPECT_CALL(*factory, GetSyncableServiceForType(syncable::AUTOFILL)). 304 EXPECT_CALL(*factory, GetSyncableServiceForType(syncer::AUTOFILL)).
305 WillOnce(MakeAutocompleteSyncComponents(wds)); 305 WillOnce(MakeAutocompleteSyncComponents(wds));
306 } 306 }
307 }; 307 };
308 308
309 class AutofillProfileFactory : public AbstractAutofillFactory { 309 class AutofillProfileFactory : public AbstractAutofillFactory {
310 public: 310 public:
311 virtual browser_sync::DataTypeController* CreateDataTypeController( 311 virtual browser_sync::DataTypeController* CreateDataTypeController(
312 ProfileSyncComponentsFactory* factory, 312 ProfileSyncComponentsFactory* factory,
313 ProfileMock* profile, 313 ProfileMock* profile,
314 ProfileSyncService* service) OVERRIDE { 314 ProfileSyncService* service) OVERRIDE {
315 return new AutofillProfileDataTypeController(factory, profile, service); 315 return new AutofillProfileDataTypeController(factory, profile, service);
316 } 316 }
317 317
318 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, 318 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory,
319 ProfileSyncService* service, 319 ProfileSyncService* service,
320 WebDataService* wds, 320 WebDataService* wds,
321 DataTypeController* dtc) OVERRIDE { 321 DataTypeController* dtc) OVERRIDE {
322 EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)). 322 EXPECT_CALL(*factory, CreateGenericChangeProcessor(_,_,_)).
323 WillOnce(MakeGenericChangeProcessor()); 323 WillOnce(MakeGenericChangeProcessor());
324 EXPECT_CALL(*factory, CreateSharedChangeProcessor()). 324 EXPECT_CALL(*factory, CreateSharedChangeProcessor()).
325 WillOnce(MakeSharedChangeProcessor()); 325 WillOnce(MakeSharedChangeProcessor());
326 EXPECT_CALL(*factory, 326 EXPECT_CALL(*factory,
327 GetSyncableServiceForType(syncable::AUTOFILL_PROFILE)). 327 GetSyncableServiceForType(syncer::AUTOFILL_PROFILE)).
328 WillOnce(MakeAutofillProfileSyncComponents(wds)); 328 WillOnce(MakeAutofillProfileSyncComponents(wds));
329 } 329 }
330 }; 330 };
331 331
332 class PersonalDataManagerMock: public PersonalDataManager { 332 class PersonalDataManagerMock: public PersonalDataManager {
333 public: 333 public:
334 static ProfileKeyedService* Build(Profile* profile) { 334 static ProfileKeyedService* Build(Profile* profile) {
335 return new PersonalDataManagerMock; 335 return new PersonalDataManagerMock;
336 } 336 }
337 337
338 MOCK_CONST_METHOD0(IsDataLoaded, bool()); 338 MOCK_CONST_METHOD0(IsDataLoaded, bool());
339 MOCK_METHOD0(LoadProfiles, void()); 339 MOCK_METHOD0(LoadProfiles, void());
340 MOCK_METHOD0(LoadCreditCards, void()); 340 MOCK_METHOD0(LoadCreditCards, void());
341 MOCK_METHOD0(Refresh, void()); 341 MOCK_METHOD0(Refresh, void());
342 }; 342 };
343 template <class T> class AddAutofillHelper; 343 template <class T> class AddAutofillHelper;
344 344
345 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { 345 class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
346 protected: 346 protected:
347 ProfileSyncServiceAutofillTest() { 347 ProfileSyncServiceAutofillTest() {
348 } 348 }
349 virtual ~ProfileSyncServiceAutofillTest() { 349 virtual ~ProfileSyncServiceAutofillTest() {
350 } 350 }
351 351
352 AutofillProfileFactory profile_factory_; 352 AutofillProfileFactory profile_factory_;
353 AutofillEntryFactory entry_factory_; 353 AutofillEntryFactory entry_factory_;
354 354
355 AbstractAutofillFactory* GetFactory(syncable::ModelType type) { 355 AbstractAutofillFactory* GetFactory(syncer::ModelType type) {
356 if (type == syncable::AUTOFILL) { 356 if (type == syncer::AUTOFILL) {
357 return &entry_factory_; 357 return &entry_factory_;
358 } else if (type == syncable::AUTOFILL_PROFILE) { 358 } else if (type == syncer::AUTOFILL_PROFILE) {
359 return &profile_factory_; 359 return &profile_factory_;
360 } else { 360 } else {
361 NOTREACHED(); 361 NOTREACHED();
362 return NULL; 362 return NULL;
363 } 363 }
364 } 364 }
365 365
366 virtual void SetUp() OVERRIDE { 366 virtual void SetUp() OVERRIDE {
367 AbstractProfileSyncServiceTest::SetUp(); 367 AbstractProfileSyncServiceTest::SetUp();
368 profile_.reset(new ProfileMock()); 368 profile_.reset(new ProfileMock());
(...skipping 28 matching lines...) Expand all
397 web_data_service_->ShutdownSyncableService(); 397 web_data_service_->ShutdownSyncableService();
398 profile_->ResetRequestContext(); 398 profile_->ResetRequestContext();
399 // To prevent a leak, fully release TestURLRequestContext to ensure its 399 // To prevent a leak, fully release TestURLRequestContext to ensure its
400 // destruction on the IO message loop. 400 // destruction on the IO message loop.
401 profile_.reset(); 401 profile_.reset();
402 AbstractProfileSyncServiceTest::TearDown(); 402 AbstractProfileSyncServiceTest::TearDown();
403 } 403 }
404 404
405 void StartSyncService(const base::Closure& callback, 405 void StartSyncService(const base::Closure& callback,
406 bool will_fail_association, 406 bool will_fail_association,
407 syncable::ModelType type) { 407 syncer::ModelType type) {
408 AbstractAutofillFactory* factory = GetFactory(type); 408 AbstractAutofillFactory* factory = GetFactory(type);
409 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); 409 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get());
410 signin->SetAuthenticatedUsername("test_user"); 410 signin->SetAuthenticatedUsername("test_user");
411 ProfileSyncComponentsFactoryMock* components_factory = 411 ProfileSyncComponentsFactoryMock* components_factory =
412 new ProfileSyncComponentsFactoryMock(); 412 new ProfileSyncComponentsFactoryMock();
413 service_.reset( 413 service_.reset(
414 new TestProfileSyncService(components_factory, 414 new TestProfileSyncService(components_factory,
415 profile_.get(), 415 profile_.get(),
416 signin, 416 signin,
417 ProfileSyncService::AUTO_START, 417 ProfileSyncService::AUTO_START,
(...skipping 20 matching lines...) Expand all
438 438
439 service_->RegisterDataTypeController(data_type_controller); 439 service_->RegisterDataTypeController(data_type_controller);
440 service_->Initialize(); 440 service_->Initialize();
441 MessageLoop::current()->Run(); 441 MessageLoop::current()->Run();
442 } 442 }
443 443
444 bool AddAutofillSyncNode(const AutofillEntry& entry) { 444 bool AddAutofillSyncNode(const AutofillEntry& entry) {
445 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); 445 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare());
446 syncer::ReadNode autofill_root(&trans); 446 syncer::ReadNode autofill_root(&trans);
447 if (autofill_root.InitByTagLookup( 447 if (autofill_root.InitByTagLookup(
448 syncable::ModelTypeToRootTag(syncable::AUTOFILL)) != 448 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) !=
449 BaseNode::INIT_OK) { 449 BaseNode::INIT_OK) {
450 return false; 450 return false;
451 } 451 }
452 452
453 syncer::WriteNode node(&trans); 453 syncer::WriteNode node(&trans);
454 std::string tag = AutocompleteSyncableService::KeyToTag( 454 std::string tag = AutocompleteSyncableService::KeyToTag(
455 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); 455 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value()));
456 syncer::WriteNode::InitUniqueByCreationResult result = 456 syncer::WriteNode::InitUniqueByCreationResult result =
457 node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag); 457 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag);
458 if (result != syncer::WriteNode::INIT_SUCCESS) 458 if (result != syncer::WriteNode::INIT_SUCCESS)
459 return false; 459 return false;
460 460
461 sync_pb::EntitySpecifics specifics; 461 sync_pb::EntitySpecifics specifics;
462 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); 462 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics);
463 sync_pb::AutofillSpecifics* autofill_specifics = 463 sync_pb::AutofillSpecifics* autofill_specifics =
464 specifics.mutable_autofill(); 464 specifics.mutable_autofill();
465 node.SetAutofillSpecifics(*autofill_specifics); 465 node.SetAutofillSpecifics(*autofill_specifics);
466 return true; 466 return true;
467 } 467 }
468 468
469 bool AddAutofillSyncNode(const AutofillProfile& profile) { 469 bool AddAutofillSyncNode(const AutofillProfile& profile) {
470 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); 470 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare());
471 syncer::ReadNode autofill_root(&trans); 471 syncer::ReadNode autofill_root(&trans);
472 if (autofill_root.InitByTagLookup(kAutofillProfileTag) != 472 if (autofill_root.InitByTagLookup(kAutofillProfileTag) !=
473 BaseNode::INIT_OK) { 473 BaseNode::INIT_OK) {
474 return false; 474 return false;
475 } 475 }
476 syncer::WriteNode node(&trans); 476 syncer::WriteNode node(&trans);
477 std::string tag = profile.guid(); 477 std::string tag = profile.guid();
478 syncer::WriteNode::InitUniqueByCreationResult result = 478 syncer::WriteNode::InitUniqueByCreationResult result =
479 node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, 479 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE,
480 autofill_root, tag); 480 autofill_root, tag);
481 if (result != syncer::WriteNode::INIT_SUCCESS) 481 if (result != syncer::WriteNode::INIT_SUCCESS)
482 return false; 482 return false;
483 483
484 sync_pb::EntitySpecifics specifics; 484 sync_pb::EntitySpecifics specifics;
485 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); 485 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics);
486 sync_pb::AutofillProfileSpecifics* profile_specifics = 486 sync_pb::AutofillProfileSpecifics* profile_specifics =
487 specifics.mutable_autofill_profile(); 487 specifics.mutable_autofill_profile();
488 node.SetAutofillProfileSpecifics(*profile_specifics); 488 node.SetAutofillProfileSpecifics(*profile_specifics);
489 return true; 489 return true;
490 } 490 }
491 491
492 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, 492 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries,
493 std::vector<AutofillProfile>* profiles) { 493 std::vector<AutofillProfile>* profiles) {
494 syncer::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); 494 syncer::ReadTransaction trans(FROM_HERE, service_->GetUserShare());
495 syncer::ReadNode autofill_root(&trans); 495 syncer::ReadNode autofill_root(&trans);
496 if (autofill_root.InitByTagLookup( 496 if (autofill_root.InitByTagLookup(
497 syncable::ModelTypeToRootTag(syncable::AUTOFILL)) != 497 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) !=
498 BaseNode::INIT_OK) { 498 BaseNode::INIT_OK) {
499 return false; 499 return false;
500 } 500 }
501 501
502 int64 child_id = autofill_root.GetFirstChildId(); 502 int64 child_id = autofill_root.GetFirstChildId();
503 while (child_id != syncer::kInvalidId) { 503 while (child_id != syncer::kInvalidId) {
504 syncer::ReadNode child_node(&trans); 504 syncer::ReadNode child_node(&trans);
505 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) 505 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK)
506 return false; 506 return false;
507 507
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 class WriteTransactionTest: public WriteTransaction { 631 class WriteTransactionTest: public WriteTransaction {
632 public: 632 public:
633 WriteTransactionTest(const tracked_objects::Location& from_here, 633 WriteTransactionTest(const tracked_objects::Location& from_here,
634 WriterTag writer, 634 WriterTag writer,
635 syncer::syncable::Directory* directory, 635 syncer::syncable::Directory* directory,
636 scoped_ptr<WaitableEvent>* wait_for_syncapi) 636 scoped_ptr<WaitableEvent>* wait_for_syncapi)
637 : WriteTransaction(from_here, writer, directory), 637 : WriteTransaction(from_here, writer, directory),
638 wait_for_syncapi_(wait_for_syncapi) { } 638 wait_for_syncapi_(wait_for_syncapi) { }
639 639
640 virtual void NotifyTransactionComplete( 640 virtual void NotifyTransactionComplete(
641 syncable::ModelTypeSet types) OVERRIDE { 641 syncer::ModelTypeSet types) OVERRIDE {
642 // This is where we differ. Force a thread change here, giving another 642 // This is where we differ. Force a thread change here, giving another
643 // thread a chance to create a WriteTransaction 643 // thread a chance to create a WriteTransaction
644 (*wait_for_syncapi_)->Wait(); 644 (*wait_for_syncapi_)->Wait();
645 645
646 WriteTransaction::NotifyTransactionComplete(types); 646 WriteTransaction::NotifyTransactionComplete(types);
647 } 647 }
648 648
649 private: 649 private:
650 scoped_ptr<WaitableEvent>* wait_for_syncapi_; 650 scoped_ptr<WaitableEvent>* wait_for_syncapi_;
651 }; 651 };
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 // Tell main thread we've started 689 // Tell main thread we've started
690 (*wait_for_start_)->Signal(); 690 (*wait_for_start_)->Signal();
691 691
692 // Create write transaction. 692 // Create write transaction.
693 WriteTransactionTest trans(FROM_HERE, UNITTEST, directory, 693 WriteTransactionTest trans(FROM_HERE, UNITTEST, directory,
694 wait_for_syncapi_); 694 wait_for_syncapi_);
695 695
696 // Create actual entry based on autofill protobuf information. 696 // Create actual entry based on autofill protobuf information.
697 // Simulates effects of UpdateLocalDataFromServerData 697 // Simulates effects of UpdateLocalDataFromServerData
698 MutableEntry parent(&trans, GET_BY_SERVER_TAG, 698 MutableEntry parent(&trans, GET_BY_SERVER_TAG,
699 syncable::ModelTypeToRootTag(syncable::AUTOFILL)); 699 syncer::ModelTypeToRootTag(syncer::AUTOFILL));
700 MutableEntry item(&trans, CREATE, parent.Get(syncer::syncable::ID), tag); 700 MutableEntry item(&trans, CREATE, parent.Get(syncer::syncable::ID), tag);
701 ASSERT_TRUE(item.good()); 701 ASSERT_TRUE(item.good());
702 item.Put(SPECIFICS, entity_specifics); 702 item.Put(SPECIFICS, entity_specifics);
703 item.Put(SERVER_SPECIFICS, entity_specifics); 703 item.Put(SERVER_SPECIFICS, entity_specifics);
704 item.Put(BASE_VERSION, 1); 704 item.Put(BASE_VERSION, 1);
705 syncer::syncable::Id server_item_id = 705 syncer::syncable::Id server_item_id =
706 service_->id_factory()->NewServerId(); 706 service_->id_factory()->NewServerId();
707 item.Put(syncer::syncable::ID, server_item_id); 707 item.Put(syncer::syncable::ID, server_item_id);
708 syncer::syncable::Id new_predecessor; 708 syncer::syncable::Id new_predecessor;
709 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); 709 ASSERT_TRUE(item.PutPredecessor(new_predecessor));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 769 }
770 770
771 }; 771 };
772 772
773 // TODO(skrul): Test abort startup. 773 // TODO(skrul): Test abort startup.
774 // TODO(skrul): Test processing of cloud changes. 774 // TODO(skrul): Test processing of cloud changes.
775 // TODO(tim): Add autofill data type controller test, and a case to cover 775 // TODO(tim): Add autofill data type controller test, and a case to cover
776 // waiting for the PersonalDataManager. 776 // waiting for the PersonalDataManager.
777 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { 777 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) {
778 // Don't create the root autofill node so startup fails. 778 // Don't create the root autofill node so startup fails.
779 StartSyncService(base::Closure(), true, syncable::AUTOFILL); 779 StartSyncService(base::Closure(), true, syncer::AUTOFILL);
780 EXPECT_TRUE(service_->HasUnrecoverableError()); 780 EXPECT_TRUE(service_->HasUnrecoverableError());
781 } 781 }
782 782
783 TEST_F(ProfileSyncServiceAutofillTest, EmptyNativeEmptySync) { 783 TEST_F(ProfileSyncServiceAutofillTest, EmptyNativeEmptySync) {
784 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); 784 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true));
785 SetIdleChangeProcessorExpectations(); 785 SetIdleChangeProcessorExpectations();
786 CreateRootHelper create_root(this, syncable::AUTOFILL); 786 CreateRootHelper create_root(this, syncer::AUTOFILL);
787 EXPECT_CALL(*personal_data_manager_, Refresh()); 787 EXPECT_CALL(*personal_data_manager_, Refresh());
788 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 788 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
789 EXPECT_TRUE(create_root.success()); 789 EXPECT_TRUE(create_root.success());
790 std::vector<AutofillEntry> sync_entries; 790 std::vector<AutofillEntry> sync_entries;
791 std::vector<AutofillProfile> sync_profiles; 791 std::vector<AutofillProfile> sync_profiles;
792 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 792 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
793 EXPECT_EQ(0U, sync_entries.size()); 793 EXPECT_EQ(0U, sync_entries.size());
794 EXPECT_EQ(0U, sync_profiles.size()); 794 EXPECT_EQ(0U, sync_profiles.size());
795 } 795 }
796 796
797 TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) { 797 TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) {
798 std::vector<AutofillEntry> entries; 798 std::vector<AutofillEntry> entries;
799 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); 799 entries.push_back(MakeAutofillEntry("foo", "bar", 1));
800 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 800 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
801 WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); 801 WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true)));
802 SetIdleChangeProcessorExpectations(); 802 SetIdleChangeProcessorExpectations();
803 CreateRootHelper create_root(this, syncable::AUTOFILL); 803 CreateRootHelper create_root(this, syncer::AUTOFILL);
804 EXPECT_CALL(*personal_data_manager_, Refresh()); 804 EXPECT_CALL(*personal_data_manager_, Refresh());
805 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 805 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
806 ASSERT_TRUE(create_root.success()); 806 ASSERT_TRUE(create_root.success());
807 std::vector<AutofillEntry> sync_entries; 807 std::vector<AutofillEntry> sync_entries;
808 std::vector<AutofillProfile> sync_profiles; 808 std::vector<AutofillProfile> sync_profiles;
809 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 809 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
810 ASSERT_EQ(1U, entries.size()); 810 ASSERT_EQ(1U, entries.size());
811 EXPECT_TRUE(entries[0] == sync_entries[0]); 811 EXPECT_TRUE(entries[0] == sync_entries[0]);
812 EXPECT_EQ(0U, sync_profiles.size()); 812 EXPECT_EQ(0U, sync_profiles.size());
813 } 813 }
814 814
815 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { 815 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) {
816 std::vector<AutofillProfile*> profiles; 816 std::vector<AutofillProfile*> profiles;
817 std::vector<AutofillProfile> expected_profiles; 817 std::vector<AutofillProfile> expected_profiles;
818 // Owned by GetAutofillProfiles caller. 818 // Owned by GetAutofillProfiles caller.
819 AutofillProfile* profile0 = new AutofillProfile; 819 AutofillProfile* profile0 = new AutofillProfile;
820 autofill_test::SetProfileInfoWithGuid(profile0, 820 autofill_test::SetProfileInfoWithGuid(profile0,
821 "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", 821 "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing",
822 "Mitchell", "Morrison", 822 "Mitchell", "Morrison",
823 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 823 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
824 "91601", "US", "12345678910"); 824 "91601", "US", "12345678910");
825 profiles.push_back(profile0); 825 profiles.push_back(profile0);
826 expected_profiles.push_back(*profile0); 826 expected_profiles.push_back(*profile0);
827 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). 827 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).
828 WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); 828 WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true)));
829 EXPECT_CALL(*personal_data_manager_, Refresh()); 829 EXPECT_CALL(*personal_data_manager_, Refresh());
830 SetIdleChangeProcessorExpectations(); 830 SetIdleChangeProcessorExpectations();
831 CreateRootHelper create_root(this, syncable::AUTOFILL_PROFILE); 831 CreateRootHelper create_root(this, syncer::AUTOFILL_PROFILE);
832 StartSyncService(create_root.callback(), false, syncable::AUTOFILL_PROFILE); 832 StartSyncService(create_root.callback(), false, syncer::AUTOFILL_PROFILE);
833 ASSERT_TRUE(create_root.success()); 833 ASSERT_TRUE(create_root.success());
834 std::vector<AutofillProfile> sync_profiles; 834 std::vector<AutofillProfile> sync_profiles;
835 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(&sync_profiles)); 835 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(&sync_profiles));
836 EXPECT_EQ(1U, sync_profiles.size()); 836 EXPECT_EQ(1U, sync_profiles.size());
837 EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0])); 837 EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0]));
838 } 838 }
839 839
840 TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) { 840 TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) {
841 // There is buggy autofill code that allows duplicate name/value 841 // There is buggy autofill code that allows duplicate name/value
842 // pairs to exist in the database with separate pair_ids. 842 // pairs to exist in the database with separate pair_ids.
843 std::vector<AutofillEntry> entries; 843 std::vector<AutofillEntry> entries;
844 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); 844 entries.push_back(MakeAutofillEntry("foo", "bar", 1));
845 entries.push_back(MakeAutofillEntry("dup", "", 2)); 845 entries.push_back(MakeAutofillEntry("dup", "", 2));
846 entries.push_back(MakeAutofillEntry("dup", "", 3)); 846 entries.push_back(MakeAutofillEntry("dup", "", 3));
847 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 847 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
848 WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); 848 WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true)));
849 SetIdleChangeProcessorExpectations(); 849 SetIdleChangeProcessorExpectations();
850 CreateRootHelper create_root(this, syncable::AUTOFILL); 850 CreateRootHelper create_root(this, syncer::AUTOFILL);
851 EXPECT_CALL(*personal_data_manager_, Refresh()); 851 EXPECT_CALL(*personal_data_manager_, Refresh());
852 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 852 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
853 ASSERT_TRUE(create_root.success()); 853 ASSERT_TRUE(create_root.success());
854 std::vector<AutofillEntry> sync_entries; 854 std::vector<AutofillEntry> sync_entries;
855 std::vector<AutofillProfile> sync_profiles; 855 std::vector<AutofillProfile> sync_profiles;
856 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 856 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
857 EXPECT_EQ(2U, sync_entries.size()); 857 EXPECT_EQ(2U, sync_entries.size());
858 } 858 }
859 859
860 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { 860 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) {
861 AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1)); 861 AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1));
862 AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2)); 862 AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2));
863 863
864 std::vector<AutofillEntry> native_entries; 864 std::vector<AutofillEntry> native_entries;
865 native_entries.push_back(native_entry); 865 native_entries.push_back(native_entry);
866 866
867 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 867 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
868 WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); 868 WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true)));
869 869
870 std::vector<AutofillEntry> sync_entries; 870 std::vector<AutofillEntry> sync_entries;
871 sync_entries.push_back(sync_entry); 871 sync_entries.push_back(sync_entry);
872 872
873 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); 873 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries);
874 874
875 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(ElementsAre(sync_entry))). 875 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(ElementsAre(sync_entry))).
876 WillOnce(Return(true)); 876 WillOnce(Return(true));
877 877
878 EXPECT_CALL(*personal_data_manager_, Refresh()); 878 EXPECT_CALL(*personal_data_manager_, Refresh());
879 StartSyncService(add_autofill.callback(), false, syncable::AUTOFILL); 879 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL);
880 ASSERT_TRUE(add_autofill.success()); 880 ASSERT_TRUE(add_autofill.success());
881 881
882 std::set<AutofillEntry> expected_entries; 882 std::set<AutofillEntry> expected_entries;
883 expected_entries.insert(native_entry); 883 expected_entries.insert(native_entry);
884 expected_entries.insert(sync_entry); 884 expected_entries.insert(sync_entry);
885 885
886 std::vector<AutofillEntry> new_sync_entries; 886 std::vector<AutofillEntry> new_sync_entries;
887 std::vector<AutofillProfile> new_sync_profiles; 887 std::vector<AutofillProfile> new_sync_profiles;
888 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 888 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
889 &new_sync_profiles)); 889 &new_sync_profiles));
(...skipping 13 matching lines...) Expand all
903 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 903 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
904 WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); 904 WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true)));
905 905
906 std::vector<AutofillEntry> sync_entries; 906 std::vector<AutofillEntry> sync_entries;
907 sync_entries.push_back(sync_entry); 907 sync_entries.push_back(sync_entry);
908 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); 908 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries);
909 909
910 EXPECT_CALL(autofill_table_, 910 EXPECT_CALL(autofill_table_,
911 UpdateAutofillEntries(ElementsAre(merged_entry))).WillOnce(Return(true)); 911 UpdateAutofillEntries(ElementsAre(merged_entry))).WillOnce(Return(true));
912 EXPECT_CALL(*personal_data_manager_, Refresh()); 912 EXPECT_CALL(*personal_data_manager_, Refresh());
913 StartSyncService(add_autofill.callback(), false, syncable::AUTOFILL); 913 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL);
914 ASSERT_TRUE(add_autofill.success()); 914 ASSERT_TRUE(add_autofill.success());
915 915
916 std::vector<AutofillEntry> new_sync_entries; 916 std::vector<AutofillEntry> new_sync_entries;
917 std::vector<AutofillProfile> new_sync_profiles; 917 std::vector<AutofillProfile> new_sync_profiles;
918 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 918 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
919 &new_sync_profiles)); 919 &new_sync_profiles));
920 ASSERT_EQ(1U, new_sync_entries.size()); 920 ASSERT_EQ(1U, new_sync_entries.size());
921 EXPECT_TRUE(merged_entry == new_sync_entries[0]); 921 EXPECT_TRUE(merged_entry == new_sync_entries[0]);
922 } 922 }
923 923
(...skipping 17 matching lines...) Expand all
941 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 941 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
942 942
943 std::vector<AutofillProfile> sync_profiles; 943 std::vector<AutofillProfile> sync_profiles;
944 sync_profiles.push_back(sync_profile); 944 sync_profiles.push_back(sync_profile);
945 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 945 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
946 946
947 EXPECT_CALL(autofill_table_, 947 EXPECT_CALL(autofill_table_,
948 UpdateAutofillProfileMulti(MatchProfiles(sync_profile))). 948 UpdateAutofillProfileMulti(MatchProfiles(sync_profile))).
949 WillOnce(Return(true)); 949 WillOnce(Return(true));
950 EXPECT_CALL(*personal_data_manager_, Refresh()); 950 EXPECT_CALL(*personal_data_manager_, Refresh());
951 StartSyncService(add_autofill.callback(), false, syncable::AUTOFILL_PROFILE); 951 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE);
952 ASSERT_TRUE(add_autofill.success()); 952 ASSERT_TRUE(add_autofill.success());
953 953
954 std::vector<AutofillProfile> new_sync_profiles; 954 std::vector<AutofillProfile> new_sync_profiles;
955 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 955 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
956 &new_sync_profiles)); 956 &new_sync_profiles));
957 ASSERT_EQ(1U, new_sync_profiles.size()); 957 ASSERT_EQ(1U, new_sync_profiles.size());
958 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); 958 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0]));
959 } 959 }
960 960
961 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfileCombine) { 961 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfileCombine) {
(...skipping 22 matching lines...) Expand all
984 AddAutofillProfile(MatchProfiles(expected_profile))). 984 AddAutofillProfile(MatchProfiles(expected_profile))).
985 WillOnce(Return(true)); 985 WillOnce(Return(true));
986 EXPECT_CALL(autofill_table_, 986 EXPECT_CALL(autofill_table_,
987 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")). 987 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")).
988 WillOnce(Return(true)); 988 WillOnce(Return(true));
989 std::vector<AutofillProfile> sync_profiles; 989 std::vector<AutofillProfile> sync_profiles;
990 sync_profiles.push_back(sync_profile); 990 sync_profiles.push_back(sync_profile);
991 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 991 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
992 992
993 EXPECT_CALL(*personal_data_manager_, Refresh()); 993 EXPECT_CALL(*personal_data_manager_, Refresh());
994 StartSyncService(add_autofill.callback(), false, syncable::AUTOFILL_PROFILE); 994 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE);
995 ASSERT_TRUE(add_autofill.success()); 995 ASSERT_TRUE(add_autofill.success());
996 996
997 std::vector<AutofillProfile> new_sync_profiles; 997 std::vector<AutofillProfile> new_sync_profiles;
998 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 998 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
999 &new_sync_profiles)); 999 &new_sync_profiles));
1000 ASSERT_EQ(1U, new_sync_profiles.size()); 1000 ASSERT_EQ(1U, new_sync_profiles.size());
1001 // Check that key fields are the same. 1001 // Check that key fields are the same.
1002 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile)); 1002 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile));
1003 // Check that multivalued fields of the synced back data include original 1003 // Check that multivalued fields of the synced back data include original
1004 // data. 1004 // data.
(...skipping 27 matching lines...) Expand all
1032 1032
1033 std::vector<AutofillProfile> sync_profiles; 1033 std::vector<AutofillProfile> sync_profiles;
1034 sync_profiles.push_back(sync_profile); 1034 sync_profiles.push_back(sync_profile);
1035 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1035 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1036 1036
1037 EXPECT_CALL(autofill_table_, AddAutofillProfile(_)). 1037 EXPECT_CALL(autofill_table_, AddAutofillProfile(_)).
1038 WillOnce(Return(true)); 1038 WillOnce(Return(true));
1039 EXPECT_CALL(autofill_table_, RemoveAutofillProfile(native_guid)). 1039 EXPECT_CALL(autofill_table_, RemoveAutofillProfile(native_guid)).
1040 WillOnce(Return(true)); 1040 WillOnce(Return(true));
1041 EXPECT_CALL(*personal_data_manager_, Refresh()); 1041 EXPECT_CALL(*personal_data_manager_, Refresh());
1042 StartSyncService(add_autofill.callback(), false, syncable::AUTOFILL_PROFILE); 1042 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE);
1043 ASSERT_TRUE(add_autofill.success()); 1043 ASSERT_TRUE(add_autofill.success());
1044 1044
1045 std::vector<AutofillProfile> new_sync_profiles; 1045 std::vector<AutofillProfile> new_sync_profiles;
1046 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1046 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
1047 &new_sync_profiles)); 1047 &new_sync_profiles));
1048 ASSERT_EQ(1U, new_sync_profiles.size()); 1048 ASSERT_EQ(1U, new_sync_profiles.size());
1049 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); 1049 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0]));
1050 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); 1050 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid());
1051 } 1051 }
1052 1052
1053 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { 1053 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) {
1054 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); 1054 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true));
1055 EXPECT_CALL(*personal_data_manager_, Refresh()); 1055 EXPECT_CALL(*personal_data_manager_, Refresh());
1056 SetIdleChangeProcessorExpectations(); 1056 SetIdleChangeProcessorExpectations();
1057 CreateRootHelper create_root(this, syncable::AUTOFILL); 1057 CreateRootHelper create_root(this, syncer::AUTOFILL);
1058 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 1058 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
1059 ASSERT_TRUE(create_root.success()); 1059 ASSERT_TRUE(create_root.success());
1060 1060
1061 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1)); 1061 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1));
1062 std::vector<base::Time> timestamps(added_entry.timestamps()); 1062 std::vector<base::Time> timestamps(added_entry.timestamps());
1063 1063
1064 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)). 1064 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).
1065 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true))); 1065 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true)));
1066 1066
1067 AutofillChangeList changes; 1067 AutofillChangeList changes;
1068 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); 1068 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key()));
1069 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1069 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
1070 db_thread_.DeprecatedGetThreadObject())); 1070 db_thread_.DeprecatedGetThreadObject()));
1071 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 1071 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1072 content::Source<WebDataService>(web_data_service_.get()), 1072 content::Source<WebDataService>(web_data_service_.get()),
1073 content::Details<AutofillChangeList>(&changes)); 1073 content::Details<AutofillChangeList>(&changes));
1074 1074
1075 std::vector<AutofillEntry> new_sync_entries; 1075 std::vector<AutofillEntry> new_sync_entries;
1076 std::vector<AutofillProfile> new_sync_profiles; 1076 std::vector<AutofillProfile> new_sync_profiles;
1077 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 1077 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
1078 &new_sync_profiles)); 1078 &new_sync_profiles));
1079 ASSERT_EQ(1U, new_sync_entries.size()); 1079 ASSERT_EQ(1U, new_sync_entries.size());
1080 EXPECT_TRUE(added_entry == new_sync_entries[0]); 1080 EXPECT_TRUE(added_entry == new_sync_entries[0]);
1081 } 1081 }
1082 1082
1083 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { 1083 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) {
1084 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); 1084 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true));
1085 EXPECT_CALL(*personal_data_manager_, Refresh()); 1085 EXPECT_CALL(*personal_data_manager_, Refresh());
1086 SetIdleChangeProcessorExpectations(); 1086 SetIdleChangeProcessorExpectations();
1087 CreateRootHelper create_root(this, syncable::AUTOFILL_PROFILE); 1087 CreateRootHelper create_root(this, syncer::AUTOFILL_PROFILE);
1088 StartSyncService(create_root.callback(), false, syncable::AUTOFILL_PROFILE); 1088 StartSyncService(create_root.callback(), false, syncer::AUTOFILL_PROFILE);
1089 ASSERT_TRUE(create_root.success()); 1089 ASSERT_TRUE(create_root.success());
1090 1090
1091 AutofillProfile added_profile; 1091 AutofillProfile added_profile;
1092 autofill_test::SetProfileInfoWithGuid(&added_profile, 1092 autofill_test::SetProfileInfoWithGuid(&added_profile,
1093 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz", 1093 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz",
1094 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", 1094 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
1095 "32801", "US", "19482937549"); 1095 "32801", "US", "19482937549");
1096 1096
1097 AutofillProfileChange change(AutofillProfileChange::ADD, 1097 AutofillProfileChange change(AutofillProfileChange::ADD,
1098 added_profile.guid(), &added_profile); 1098 added_profile.guid(), &added_profile);
(...skipping 11 matching lines...) Expand all
1110 } 1110 }
1111 1111
1112 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { 1112 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) {
1113 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 1113 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
1114 std::vector<AutofillEntry> original_entries; 1114 std::vector<AutofillEntry> original_entries;
1115 original_entries.push_back(original_entry); 1115 original_entries.push_back(original_entry);
1116 1116
1117 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 1117 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
1118 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 1118 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true)));
1119 EXPECT_CALL(*personal_data_manager_, Refresh()); 1119 EXPECT_CALL(*personal_data_manager_, Refresh());
1120 CreateRootHelper create_root(this, syncable::AUTOFILL); 1120 CreateRootHelper create_root(this, syncer::AUTOFILL);
1121 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 1121 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
1122 ASSERT_TRUE(create_root.success()); 1122 ASSERT_TRUE(create_root.success());
1123 1123
1124 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); 1124 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2));
1125 std::vector<base::Time> timestamps(updated_entry.timestamps()); 1125 std::vector<base::Time> timestamps(updated_entry.timestamps());
1126 1126
1127 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)). 1127 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).
1128 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true))); 1128 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true)));
1129 1129
1130 AutofillChangeList changes; 1130 AutofillChangeList changes;
1131 changes.push_back(AutofillChange(AutofillChange::UPDATE, 1131 changes.push_back(AutofillChange(AutofillChange::UPDATE,
(...skipping 14 matching lines...) Expand all
1146 1146
1147 1147
1148 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { 1148 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) {
1149 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 1149 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
1150 std::vector<AutofillEntry> original_entries; 1150 std::vector<AutofillEntry> original_entries;
1151 original_entries.push_back(original_entry); 1151 original_entries.push_back(original_entry);
1152 1152
1153 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 1153 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
1154 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 1154 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true)));
1155 EXPECT_CALL(*personal_data_manager_, Refresh()); 1155 EXPECT_CALL(*personal_data_manager_, Refresh());
1156 CreateRootHelper create_root(this, syncable::AUTOFILL); 1156 CreateRootHelper create_root(this, syncer::AUTOFILL);
1157 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 1157 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
1158 ASSERT_TRUE(create_root.success()); 1158 ASSERT_TRUE(create_root.success());
1159 1159
1160 AutofillChangeList changes; 1160 AutofillChangeList changes;
1161 changes.push_back(AutofillChange(AutofillChange::REMOVE, 1161 changes.push_back(AutofillChange(AutofillChange::REMOVE,
1162 original_entry.key())); 1162 original_entry.key()));
1163 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1163 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
1164 db_thread_.DeprecatedGetThreadObject())); 1164 db_thread_.DeprecatedGetThreadObject()));
1165 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 1165 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1166 content::Source<WebDataService>(web_data_service_.get()), 1166 content::Source<WebDataService>(web_data_service_.get()),
1167 content::Details<AutofillChangeList>(&changes)); 1167 content::Details<AutofillChangeList>(&changes));
(...skipping 19 matching lines...) Expand all
1187 1187
1188 std::vector<AutofillProfile*> native_profiles; 1188 std::vector<AutofillProfile*> native_profiles;
1189 native_profiles.push_back(native_profile); 1189 native_profiles.push_back(native_profile);
1190 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). 1190 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).
1191 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1191 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1192 1192
1193 std::vector<AutofillProfile> sync_profiles; 1193 std::vector<AutofillProfile> sync_profiles;
1194 sync_profiles.push_back(sync_profile); 1194 sync_profiles.push_back(sync_profile);
1195 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1195 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1196 EXPECT_CALL(*personal_data_manager_, Refresh()); 1196 EXPECT_CALL(*personal_data_manager_, Refresh());
1197 StartSyncService(add_autofill.callback(), false, syncable::AUTOFILL_PROFILE); 1197 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE);
1198 ASSERT_TRUE(add_autofill.success()); 1198 ASSERT_TRUE(add_autofill.success());
1199 1199
1200 AutofillProfileChange change(AutofillProfileChange::REMOVE, 1200 AutofillProfileChange change(AutofillProfileChange::REMOVE,
1201 sync_profile.guid(), NULL); 1201 sync_profile.guid(), NULL);
1202 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1202 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(
1203 db_thread_.DeprecatedGetThreadObject())); 1203 db_thread_.DeprecatedGetThreadObject()));
1204 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 1204 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1205 content::Source<WebDataService>(web_data_service_.get()), 1205 content::Source<WebDataService>(web_data_service_.get()),
1206 content::Details<AutofillProfileChange>(&change)); 1206 content::Details<AutofillProfileChange>(&change));
1207 1207
1208 std::vector<AutofillProfile> new_sync_profiles; 1208 std::vector<AutofillProfile> new_sync_profiles;
1209 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1209 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
1210 &new_sync_profiles)); 1210 &new_sync_profiles));
1211 ASSERT_EQ(0U, new_sync_profiles.size()); 1211 ASSERT_EQ(0U, new_sync_profiles.size());
1212 } 1212 }
1213 1213
1214 // http://crbug.com/57884 1214 // http://crbug.com/57884
1215 TEST_F(ProfileSyncServiceAutofillTest, DISABLED_ServerChangeRace) { 1215 TEST_F(ProfileSyncServiceAutofillTest, DISABLED_ServerChangeRace) {
1216 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via 1216 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via
1217 // LoadAutofillData(). 1217 // LoadAutofillData().
1218 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 1218 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
1219 Times(3).WillRepeatedly(Return(true)); 1219 Times(3).WillRepeatedly(Return(true));
1220 // On the other hand Autofill and Autocomplete are separated now, so 1220 // On the other hand Autofill and Autocomplete are separated now, so
1221 // GetAutofillProfiles() should not be called. 1221 // GetAutofillProfiles() should not be called.
1222 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).Times(0); 1222 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).Times(0);
1223 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)). 1223 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)).
1224 WillRepeatedly(Return(true)); 1224 WillRepeatedly(Return(true));
1225 EXPECT_CALL(*personal_data_manager_, Refresh()).Times(3); 1225 EXPECT_CALL(*personal_data_manager_, Refresh()).Times(3);
1226 CreateRootHelper create_root(this, syncable::AUTOFILL); 1226 CreateRootHelper create_root(this, syncer::AUTOFILL);
1227 StartSyncService(create_root.callback(), false, syncable::AUTOFILL); 1227 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
1228 ASSERT_TRUE(create_root.success()); 1228 ASSERT_TRUE(create_root.success());
1229 1229
1230 // (true, false) means we have to reset after |Signal|, init to unsignaled. 1230 // (true, false) means we have to reset after |Signal|, init to unsignaled.
1231 scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false)); 1231 scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false));
1232 scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false)); 1232 scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false));
1233 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater( 1233 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater(
1234 service_.get(), &wait_for_start, &wait_for_syncapi)); 1234 service_.get(), &wait_for_start, &wait_for_syncapi));
1235 1235
1236 // This server side update will stall waiting for CommitWaiter. 1236 // This server side update will stall waiting for CommitWaiter.
1237 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1)); 1237 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1));
(...skipping 14 matching lines...) Expand all
1252 std::vector<AutofillEntry> sync_entries; 1252 std::vector<AutofillEntry> sync_entries;
1253 std::vector<AutofillProfile> sync_profiles; 1253 std::vector<AutofillProfile> sync_profiles;
1254 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1254 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1255 EXPECT_EQ(3U, sync_entries.size()); 1255 EXPECT_EQ(3U, sync_entries.size());
1256 EXPECT_EQ(0U, sync_profiles.size()); 1256 EXPECT_EQ(0U, sync_profiles.size());
1257 for (size_t i = 0; i < sync_entries.size(); i++) { 1257 for (size_t i = 0; i < sync_entries.size(); i++) {
1258 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1258 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1259 << ", " << sync_entries[i].key().value(); 1259 << ", " << sync_entries[i].key().value();
1260 } 1260 }
1261 } 1261 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | chrome/browser/sync/profile_sync_service_bookmark_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698