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