| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sync/api/sync_data.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/memory/ref_counted_memory.h" | |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/threading/thread_task_runner_handle.h" | |
| 15 #include "base/time/time.h" | |
| 16 #include "sync/api/attachments/attachment_id.h" | |
| 17 #include "sync/internal_api/public/attachments/attachment_service.h" | |
| 18 #include "sync/internal_api/public/attachments/attachment_service_impl.h" | |
| 19 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" | |
| 20 #include "sync/protocol/sync.pb.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 using std::string; | |
| 24 | |
| 25 namespace syncer { | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 const char kSyncTag[] = "3984729834"; | |
| 30 const ModelType kDatatype = syncer::PREFERENCES; | |
| 31 const char kNonUniqueTitle[] = "my preference"; | |
| 32 const int64_t kId = 439829; | |
| 33 const base::Time kLastModifiedTime = base::Time(); | |
| 34 | |
| 35 class SyncDataTest : public testing::Test { | |
| 36 protected: | |
| 37 SyncDataTest() | |
| 38 : attachment_service(AttachmentServiceImpl::CreateForTest()), | |
| 39 attachment_service_weak_ptr_factory(attachment_service.get()), | |
| 40 attachment_service_proxy( | |
| 41 base::ThreadTaskRunnerHandle::Get(), | |
| 42 attachment_service_weak_ptr_factory.GetWeakPtr()) {} | |
| 43 base::MessageLoop loop; | |
| 44 sync_pb::EntitySpecifics specifics; | |
| 45 std::unique_ptr<AttachmentService> attachment_service; | |
| 46 base::WeakPtrFactory<AttachmentService> attachment_service_weak_ptr_factory; | |
| 47 AttachmentServiceProxy attachment_service_proxy; | |
| 48 }; | |
| 49 | |
| 50 TEST_F(SyncDataTest, NoArgCtor) { | |
| 51 SyncData data; | |
| 52 EXPECT_FALSE(data.IsValid()); | |
| 53 } | |
| 54 | |
| 55 TEST_F(SyncDataTest, CreateLocalDelete) { | |
| 56 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype); | |
| 57 EXPECT_TRUE(data.IsValid()); | |
| 58 EXPECT_TRUE(data.IsLocal()); | |
| 59 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | |
| 60 EXPECT_EQ(kDatatype, data.GetDataType()); | |
| 61 } | |
| 62 | |
| 63 TEST_F(SyncDataTest, CreateLocalData) { | |
| 64 specifics.mutable_preference(); | |
| 65 SyncData data = | |
| 66 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics); | |
| 67 EXPECT_TRUE(data.IsValid()); | |
| 68 EXPECT_TRUE(data.IsLocal()); | |
| 69 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | |
| 70 EXPECT_EQ(kDatatype, data.GetDataType()); | |
| 71 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); | |
| 72 EXPECT_TRUE(data.GetSpecifics().has_preference()); | |
| 73 } | |
| 74 | |
| 75 TEST_F(SyncDataTest, CreateLocalDataWithAttachments) { | |
| 76 specifics.mutable_preference(); | |
| 77 AttachmentIdList attachment_ids; | |
| 78 attachment_ids.push_back(AttachmentId::Create(0, 0)); | |
| 79 attachment_ids.push_back(AttachmentId::Create(0, 0)); | |
| 80 attachment_ids.push_back(AttachmentId::Create(0, 0)); | |
| 81 | |
| 82 SyncData data = SyncData::CreateLocalDataWithAttachments( | |
| 83 kSyncTag, kNonUniqueTitle, specifics, attachment_ids); | |
| 84 EXPECT_TRUE(data.IsValid()); | |
| 85 EXPECT_TRUE(data.IsLocal()); | |
| 86 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | |
| 87 EXPECT_EQ(kDatatype, data.GetDataType()); | |
| 88 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); | |
| 89 EXPECT_TRUE(data.GetSpecifics().has_preference()); | |
| 90 attachment_ids = data.GetAttachmentIds(); | |
| 91 EXPECT_EQ(3U, attachment_ids.size()); | |
| 92 } | |
| 93 | |
| 94 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) { | |
| 95 specifics.mutable_preference(); | |
| 96 AttachmentIdList attachment_ids; | |
| 97 SyncData data = SyncData::CreateLocalDataWithAttachments( | |
| 98 kSyncTag, kNonUniqueTitle, specifics, attachment_ids); | |
| 99 EXPECT_TRUE(data.IsValid()); | |
| 100 EXPECT_TRUE(data.IsLocal()); | |
| 101 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | |
| 102 EXPECT_EQ(kDatatype, data.GetDataType()); | |
| 103 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); | |
| 104 EXPECT_TRUE(data.GetSpecifics().has_preference()); | |
| 105 EXPECT_TRUE(data.GetAttachmentIds().empty()); | |
| 106 } | |
| 107 | |
| 108 TEST_F(SyncDataTest, CreateRemoteData) { | |
| 109 specifics.mutable_preference(); | |
| 110 SyncData data = SyncData::CreateRemoteData(kId, | |
| 111 specifics, | |
| 112 kLastModifiedTime, | |
| 113 AttachmentIdList(), | |
| 114 attachment_service_proxy); | |
| 115 EXPECT_TRUE(data.IsValid()); | |
| 116 EXPECT_FALSE(data.IsLocal()); | |
| 117 EXPECT_EQ(kId, SyncDataRemote(data).GetId()); | |
| 118 EXPECT_EQ(kLastModifiedTime, SyncDataRemote(data).GetModifiedTime()); | |
| 119 EXPECT_TRUE(data.GetSpecifics().has_preference()); | |
| 120 EXPECT_TRUE(data.GetAttachmentIds().empty()); | |
| 121 } | |
| 122 | |
| 123 // TODO(maniscalco): Add test cases that verify GetLocalAttachmentsForUpload | |
| 124 // calls are passed through to the underlying AttachmentService. | |
| 125 | |
| 126 } // namespace | |
| 127 | |
| 128 } // namespace syncer | |
| OLD | NEW |