| OLD | NEW |
| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 using syncable::AUTOFILL; | 71 using syncable::AUTOFILL; |
| 72 using syncable::BASE_VERSION; | 72 using syncable::BASE_VERSION; |
| 73 using syncable::CREATE; | 73 using syncable::CREATE; |
| 74 using syncable::GET_BY_SERVER_TAG; | 74 using syncable::GET_BY_SERVER_TAG; |
| 75 using syncable::MutableEntry; | 75 using syncable::MutableEntry; |
| 76 using syncable::SERVER_SPECIFICS; | 76 using syncable::SERVER_SPECIFICS; |
| 77 using syncable::SPECIFICS; | 77 using syncable::SPECIFICS; |
| 78 using syncable::UNITTEST; | 78 using syncable::UNITTEST; |
| 79 using syncable::WriterTag; | 79 using syncable::WriterTag; |
| 80 using syncable::WriteTransaction; | 80 using syncable::WriteTransaction; |
| 81 using csync::BaseNode; | 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // We own the syncable services, but don't use a |scoped_ptr| because the | 244 // We own the syncable services, but don't use a |scoped_ptr| because the |
| 245 // lifetime must be managed on the DB thread. | 245 // lifetime must be managed on the DB thread. |
| 246 AutocompleteSyncableService* autocomplete_syncable_service_; | 246 AutocompleteSyncableService* autocomplete_syncable_service_; |
| 247 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 247 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
| 248 WaitableEvent syncable_service_created_or_destroyed_; | 248 WaitableEvent syncable_service_created_or_destroyed_; |
| 249 }; | 249 }; |
| 250 | 250 |
| 251 ACTION_P(MakeAutocompleteSyncComponents, wds) { | 251 ACTION_P(MakeAutocompleteSyncComponents, wds) { |
| 252 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 252 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 253 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 253 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
| 254 return base::WeakPtr<csync::SyncableService>(); | 254 return base::WeakPtr<syncer::SyncableService>(); |
| 255 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); | 255 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 ACTION(MakeGenericChangeProcessor) { | 258 ACTION(MakeGenericChangeProcessor) { |
| 259 csync::UserShare* user_share = arg0->GetUserShare(); | 259 syncer::UserShare* user_share = arg0->GetUserShare(); |
| 260 return new GenericChangeProcessor(arg1, arg2, user_share); | 260 return new GenericChangeProcessor(arg1, arg2, user_share); |
| 261 } | 261 } |
| 262 | 262 |
| 263 ACTION(MakeSharedChangeProcessor) { | 263 ACTION(MakeSharedChangeProcessor) { |
| 264 return new SharedChangeProcessor(); | 264 return new SharedChangeProcessor(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 ACTION_P(MakeAutofillProfileSyncComponents, wds) { | 267 ACTION_P(MakeAutofillProfileSyncComponents, wds) { |
| 268 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 268 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 269 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 269 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
| 270 return base::WeakPtr<csync::SyncableService>();; | 270 return base::WeakPtr<syncer::SyncableService>();; |
| 271 return wds->GetAutofillProfileSyncableService()->AsWeakPtr(); | 271 return wds->GetAutofillProfileSyncableService()->AsWeakPtr(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 class AbstractAutofillFactory { | 274 class AbstractAutofillFactory { |
| 275 public: | 275 public: |
| 276 virtual DataTypeController* CreateDataTypeController( | 276 virtual DataTypeController* CreateDataTypeController( |
| 277 ProfileSyncComponentsFactory* factory, | 277 ProfileSyncComponentsFactory* factory, |
| 278 ProfileMock* profile, | 278 ProfileMock* profile, |
| 279 ProfileSyncService* service) = 0; | 279 ProfileSyncService* service) = 0; |
| 280 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, | 280 virtual void SetExpectation(ProfileSyncComponentsFactoryMock* factory, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 435 |
| 436 // We need tokens to get the tests going | 436 // We need tokens to get the tests going |
| 437 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); | 437 token_service_->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); |
| 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 csync::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 445 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 446 csync::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 syncable::ModelTypeToRootTag(syncable::AUTOFILL)) != |
| 449 BaseNode::INIT_OK) { | 449 BaseNode::INIT_OK) { |
| 450 return false; | 450 return false; |
| 451 } | 451 } |
| 452 | 452 |
| 453 csync::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 csync::WriteNode::InitUniqueByCreationResult result = | 456 syncer::WriteNode::InitUniqueByCreationResult result = |
| 457 node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag); | 457 node.InitUniqueByCreation(syncable::AUTOFILL, autofill_root, tag); |
| 458 if (result != csync::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 csync::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 470 syncer::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 471 csync::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 csync::WriteNode node(&trans); | 476 syncer::WriteNode node(&trans); |
| 477 std::string tag = profile.guid(); | 477 std::string tag = profile.guid(); |
| 478 csync::WriteNode::InitUniqueByCreationResult result = | 478 syncer::WriteNode::InitUniqueByCreationResult result = |
| 479 node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, | 479 node.InitUniqueByCreation(syncable::AUTOFILL_PROFILE, |
| 480 autofill_root, tag); | 480 autofill_root, tag); |
| 481 if (result != csync::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 csync::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 494 syncer::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 495 csync::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 syncable::ModelTypeToRootTag(syncable::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 != csync::kInvalidId) { | 503 while (child_id != syncer::kInvalidId) { |
| 504 csync::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 |
| 508 const sync_pb::AutofillSpecifics& autofill( | 508 const sync_pb::AutofillSpecifics& autofill( |
| 509 child_node.GetAutofillSpecifics()); | 509 child_node.GetAutofillSpecifics()); |
| 510 if (autofill.has_value()) { | 510 if (autofill.has_value()) { |
| 511 AutofillKey key(UTF8ToUTF16(autofill.name()), | 511 AutofillKey key(UTF8ToUTF16(autofill.name()), |
| 512 UTF8ToUTF16(autofill.value())); | 512 UTF8ToUTF16(autofill.value())); |
| 513 std::vector<base::Time> timestamps; | 513 std::vector<base::Time> timestamps; |
| 514 int timestamps_count = autofill.usage_timestamp_size(); | 514 int timestamps_count = autofill.usage_timestamp_size(); |
| 515 for (int i = 0; i < timestamps_count; ++i) { | 515 for (int i = 0; i < timestamps_count; ++i) { |
| 516 timestamps.push_back(Time::FromInternalValue( | 516 timestamps.push_back(Time::FromInternalValue( |
| 517 autofill.usage_timestamp(i))); | 517 autofill.usage_timestamp(i))); |
| 518 } | 518 } |
| 519 entries->push_back(AutofillEntry(key, timestamps)); | 519 entries->push_back(AutofillEntry(key, timestamps)); |
| 520 } else if (autofill.has_profile()) { | 520 } else if (autofill.has_profile()) { |
| 521 AutofillProfile p; | 521 AutofillProfile p; |
| 522 p.set_guid(autofill.profile().guid()); | 522 p.set_guid(autofill.profile().guid()); |
| 523 AutofillProfileSyncableService::OverwriteProfileWithServerData( | 523 AutofillProfileSyncableService::OverwriteProfileWithServerData( |
| 524 autofill.profile(), &p); | 524 autofill.profile(), &p); |
| 525 profiles->push_back(p); | 525 profiles->push_back(p); |
| 526 } | 526 } |
| 527 child_id = child_node.GetSuccessorId(); | 527 child_id = child_node.GetSuccessorId(); |
| 528 } | 528 } |
| 529 return true; | 529 return true; |
| 530 } | 530 } |
| 531 | 531 |
| 532 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 532 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 533 std::vector<AutofillProfile>* profiles) { | 533 std::vector<AutofillProfile>* profiles) { |
| 534 csync::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 534 syncer::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 535 csync::ReadNode autofill_root(&trans); | 535 syncer::ReadNode autofill_root(&trans); |
| 536 if (autofill_root.InitByTagLookup(kAutofillProfileTag) != | 536 if (autofill_root.InitByTagLookup(kAutofillProfileTag) != |
| 537 BaseNode::INIT_OK) { | 537 BaseNode::INIT_OK) { |
| 538 return false; | 538 return false; |
| 539 } | 539 } |
| 540 | 540 |
| 541 int64 child_id = autofill_root.GetFirstChildId(); | 541 int64 child_id = autofill_root.GetFirstChildId(); |
| 542 while (child_id != csync::kInvalidId) { | 542 while (child_id != syncer::kInvalidId) { |
| 543 csync::ReadNode child_node(&trans); | 543 syncer::ReadNode child_node(&trans); |
| 544 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 544 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
| 545 return false; | 545 return false; |
| 546 | 546 |
| 547 const sync_pb::AutofillProfileSpecifics& autofill( | 547 const sync_pb::AutofillProfileSpecifics& autofill( |
| 548 child_node.GetAutofillProfileSpecifics()); | 548 child_node.GetAutofillProfileSpecifics()); |
| 549 AutofillProfile p; | 549 AutofillProfile p; |
| 550 p.set_guid(autofill.guid()); | 550 p.set_guid(autofill.guid()); |
| 551 AutofillProfileSyncableService::OverwriteProfileWithServerData( | 551 AutofillProfileSyncableService::OverwriteProfileWithServerData( |
| 552 autofill, &p); | 552 autofill, &p); |
| 553 profiles->push_back(p); | 553 profiles->push_back(p); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), | 660 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), |
| 661 service_(service), | 661 service_(service), |
| 662 wait_for_start_(wait_for_start), | 662 wait_for_start_(wait_for_start), |
| 663 wait_for_syncapi_(wait_for_syncapi), | 663 wait_for_syncapi_(wait_for_syncapi), |
| 664 is_finished_(false, false) { } | 664 is_finished_(false, false) { } |
| 665 | 665 |
| 666 void Update() { | 666 void Update() { |
| 667 // This gets called in a modelsafeworker thread. | 667 // This gets called in a modelsafeworker thread. |
| 668 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 668 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 669 | 669 |
| 670 csync::UserShare* user_share = service_->GetUserShare(); | 670 syncer::UserShare* user_share = service_->GetUserShare(); |
| 671 syncable::Directory* directory = user_share->directory.get(); | 671 syncable::Directory* directory = user_share->directory.get(); |
| 672 | 672 |
| 673 // Create autofill protobuf. | 673 // Create autofill protobuf. |
| 674 std::string tag = AutocompleteSyncableService::KeyToTag( | 674 std::string tag = AutocompleteSyncableService::KeyToTag( |
| 675 UTF16ToUTF8(entry_.key().name()), UTF16ToUTF8(entry_.key().value())); | 675 UTF16ToUTF8(entry_.key().name()), UTF16ToUTF8(entry_.key().value())); |
| 676 sync_pb::AutofillSpecifics new_autofill; | 676 sync_pb::AutofillSpecifics new_autofill; |
| 677 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); | 677 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); |
| 678 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); | 678 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); |
| 679 const std::vector<base::Time>& ts(entry_.timestamps()); | 679 const std::vector<base::Time>& ts(entry_.timestamps()); |
| 680 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 680 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 std::vector<AutofillEntry> sync_entries; | 1251 std::vector<AutofillEntry> sync_entries; |
| 1252 std::vector<AutofillProfile> sync_profiles; | 1252 std::vector<AutofillProfile> sync_profiles; |
| 1253 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1253 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1254 EXPECT_EQ(3U, sync_entries.size()); | 1254 EXPECT_EQ(3U, sync_entries.size()); |
| 1255 EXPECT_EQ(0U, sync_profiles.size()); | 1255 EXPECT_EQ(0U, sync_profiles.size()); |
| 1256 for (size_t i = 0; i < sync_entries.size(); i++) { | 1256 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1257 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1257 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1258 << ", " << sync_entries[i].key().value(); | 1258 << ", " << sync_entries[i].key().value(); |
| 1259 } | 1259 } |
| 1260 } | 1260 } |
| OLD | NEW |