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