| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 syncable::AUTOFILL; | 71 using syncer::syncable::AUTOFILL; |
| 72 using syncable::BASE_VERSION; | 72 using syncer::syncable::BASE_VERSION; |
| 73 using syncable::CREATE; | 73 using syncer::syncable::CREATE; |
| 74 using syncable::GET_BY_SERVER_TAG; | 74 using syncer::syncable::GET_BY_SERVER_TAG; |
| 75 using syncable::MutableEntry; | 75 using syncer::syncable::MutableEntry; |
| 76 using syncable::SERVER_SPECIFICS; | 76 using syncer::syncable::SERVER_SPECIFICS; |
| 77 using syncable::SPECIFICS; | 77 using syncer::syncable::SPECIFICS; |
| 78 using syncable::UNITTEST; | 78 using syncer::syncable::UNITTEST; |
| 79 using syncable::WriterTag; | 79 using syncer::syncable::WriterTag; |
| 80 using syncable::WriteTransaction; | 80 using syncer::syncable::WriteTransaction; |
| 81 using syncer::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 } |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 625 |
| 626 base::Closure callback_; | 626 base::Closure callback_; |
| 627 bool success_; | 627 bool success_; |
| 628 }; | 628 }; |
| 629 | 629 |
| 630 // Overload write transaction to use custom NotifyTransactionComplete | 630 // Overload write transaction to use custom NotifyTransactionComplete |
| 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 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 syncable::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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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 syncer::UserShare* user_share = service_->GetUserShare(); | 670 syncer::UserShare* user_share = service_->GetUserShare(); |
| 671 syncable::Directory* directory = user_share->directory.get(); | 671 syncer::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(); |
| 681 timestamp != ts.end(); ++timestamp) { | 681 timestamp != ts.end(); ++timestamp) { |
| 682 new_autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 682 new_autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
| 683 } | 683 } |
| 684 | 684 |
| 685 sync_pb::EntitySpecifics entity_specifics; | 685 sync_pb::EntitySpecifics entity_specifics; |
| 686 entity_specifics.mutable_autofill()->CopyFrom(new_autofill); | 686 entity_specifics.mutable_autofill()->CopyFrom(new_autofill); |
| 687 | 687 |
| 688 { | 688 { |
| 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 syncable::ModelTypeToRootTag(syncable::AUTOFILL)); |
| 700 MutableEntry item(&trans, CREATE, parent.Get(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 syncable::Id server_item_id = service_->id_factory()->NewServerId(); | 705 syncer::syncable::Id server_item_id = |
| 706 item.Put(syncable::ID, server_item_id); | 706 service_->id_factory()->NewServerId(); |
| 707 syncable::Id new_predecessor; | 707 item.Put(syncer::syncable::ID, server_item_id); |
| 708 syncer::syncable::Id new_predecessor; |
| 708 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); | 709 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); |
| 709 } | 710 } |
| 710 DVLOG(1) << "FakeServerUpdater finishing."; | 711 DVLOG(1) << "FakeServerUpdater finishing."; |
| 711 is_finished_.Signal(); | 712 is_finished_.Signal(); |
| 712 } | 713 } |
| 713 | 714 |
| 714 void CreateNewEntry(const AutofillEntry& entry) { | 715 void CreateNewEntry(const AutofillEntry& entry) { |
| 715 entry_ = entry; | 716 entry_ = entry; |
| 716 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 717 ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 717 if (!BrowserThread::PostTask( | 718 if (!BrowserThread::PostTask( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 736 | 737 |
| 737 private: | 738 private: |
| 738 friend class base::RefCountedThreadSafe<FakeServerUpdater>; | 739 friend class base::RefCountedThreadSafe<FakeServerUpdater>; |
| 739 ~FakeServerUpdater() { } | 740 ~FakeServerUpdater() { } |
| 740 | 741 |
| 741 AutofillEntry entry_; | 742 AutofillEntry entry_; |
| 742 TestProfileSyncService* service_; | 743 TestProfileSyncService* service_; |
| 743 scoped_ptr<WaitableEvent>* wait_for_start_; | 744 scoped_ptr<WaitableEvent>* wait_for_start_; |
| 744 scoped_ptr<WaitableEvent>* wait_for_syncapi_; | 745 scoped_ptr<WaitableEvent>* wait_for_syncapi_; |
| 745 WaitableEvent is_finished_; | 746 WaitableEvent is_finished_; |
| 746 syncable::Id parent_id_; | 747 syncer::syncable::Id parent_id_; |
| 747 }; | 748 }; |
| 748 | 749 |
| 749 namespace { | 750 namespace { |
| 750 | 751 |
| 751 // Checks if the field of type |field_type| in |profile1| includes all values | 752 // Checks if the field of type |field_type| in |profile1| includes all values |
| 752 // of the field in |profile2|. | 753 // of the field in |profile2|. |
| 753 bool IncludesField(const AutofillProfile& profile1, | 754 bool IncludesField(const AutofillProfile& profile1, |
| 754 const AutofillProfile& profile2, | 755 const AutofillProfile& profile2, |
| 755 AutofillFieldType field_type) { | 756 AutofillFieldType field_type) { |
| 756 std::vector<string16> values1; | 757 std::vector<string16> values1; |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 std::vector<AutofillEntry> sync_entries; | 1252 std::vector<AutofillEntry> sync_entries; |
| 1252 std::vector<AutofillProfile> sync_profiles; | 1253 std::vector<AutofillProfile> sync_profiles; |
| 1253 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1254 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1254 EXPECT_EQ(3U, sync_entries.size()); | 1255 EXPECT_EQ(3U, sync_entries.size()); |
| 1255 EXPECT_EQ(0U, sync_profiles.size()); | 1256 EXPECT_EQ(0U, sync_profiles.size()); |
| 1256 for (size_t i = 0; i < sync_entries.size(); i++) { | 1257 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1257 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1258 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1258 << ", " << sync_entries[i].key().value(); | 1259 << ", " << sync_entries[i].key().value(); |
| 1259 } | 1260 } |
| 1260 } | 1261 } |
| OLD | NEW |