Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: sync/api/sync_change_unittest.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/api/sync_change_processor_wrapper_for_test.cc ('k') | sync/api/sync_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/api/sync_change.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h"
12 #include "base/values.h"
13 #include "sync/api/attachments/attachment_id.h"
14 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h"
15 #include "sync/protocol/preference_specifics.pb.h"
16 #include "sync/protocol/proto_value_conversions.h"
17 #include "sync/protocol/sync.pb.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace syncer {
21
22 // Ordered list of SyncChange's.
23 typedef std::vector<SyncChange> SyncChangeList;
24
25 namespace {
26
27 class SyncChangeTest : public testing::Test {
28 private:
29 base::MessageLoop message_loop;
30 };
31
32 TEST_F(SyncChangeTest, LocalDelete) {
33 SyncChange::SyncChangeType change_type = SyncChange::ACTION_DELETE;
34 std::string tag = "client_tag";
35 SyncChange e(FROM_HERE,
36 change_type,
37 SyncData::CreateLocalDelete(tag, PREFERENCES));
38 EXPECT_EQ(change_type, e.change_type());
39 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag());
40 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType());
41 }
42
43 TEST_F(SyncChangeTest, LocalUpdate) {
44 SyncChange::SyncChangeType change_type = SyncChange::ACTION_UPDATE;
45 sync_pb::EntitySpecifics specifics;
46 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
47 pref_specifics->set_name("test");
48 std::string tag = "client_tag";
49 std::string title = "client_title";
50 SyncChange e(FROM_HERE,
51 change_type,
52 SyncData::CreateLocalData(tag, title, specifics));
53 EXPECT_EQ(change_type, e.change_type());
54 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag());
55 EXPECT_EQ(title, e.sync_data().GetTitle());
56 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType());
57 std::unique_ptr<base::DictionaryValue> ref_spec(
58 EntitySpecificsToValue(specifics));
59 std::unique_ptr<base::DictionaryValue> e_spec(
60 EntitySpecificsToValue(e.sync_data().GetSpecifics()));
61 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
62 }
63
64 TEST_F(SyncChangeTest, LocalAdd) {
65 SyncChange::SyncChangeType change_type = SyncChange::ACTION_ADD;
66 sync_pb::EntitySpecifics specifics;
67 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
68 pref_specifics->set_name("test");
69 std::string tag = "client_tag";
70 std::string title = "client_title";
71 SyncChange e(FROM_HERE,
72 change_type,
73 SyncData::CreateLocalData(tag, title, specifics));
74 EXPECT_EQ(change_type, e.change_type());
75 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag());
76 EXPECT_EQ(title, e.sync_data().GetTitle());
77 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType());
78 std::unique_ptr<base::DictionaryValue> ref_spec(
79 EntitySpecificsToValue(specifics));
80 std::unique_ptr<base::DictionaryValue> e_spec(
81 EntitySpecificsToValue(e.sync_data().GetSpecifics()));
82 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
83 }
84
85 TEST_F(SyncChangeTest, SyncerChanges) {
86 SyncChangeList change_list;
87
88 // Create an update.
89 sync_pb::EntitySpecifics update_specifics;
90 sync_pb::PreferenceSpecifics* pref_specifics =
91 update_specifics.mutable_preference();
92 pref_specifics->set_name("update");
93 change_list.push_back(
94 SyncChange(FROM_HERE,
95 SyncChange::ACTION_UPDATE,
96 SyncData::CreateRemoteData(
97 1,
98 update_specifics,
99 base::Time(),
100 syncer::AttachmentIdList(),
101 syncer::AttachmentServiceProxyForTest::Create())));
102
103 // Create an add.
104 sync_pb::EntitySpecifics add_specifics;
105 pref_specifics = add_specifics.mutable_preference();
106 pref_specifics->set_name("add");
107 change_list.push_back(
108 SyncChange(FROM_HERE,
109 SyncChange::ACTION_ADD,
110 SyncData::CreateRemoteData(
111 2,
112 add_specifics,
113 base::Time(),
114 syncer::AttachmentIdList(),
115 syncer::AttachmentServiceProxyForTest::Create())));
116
117 // Create a delete.
118 sync_pb::EntitySpecifics delete_specifics;
119 pref_specifics = delete_specifics.mutable_preference();
120 pref_specifics->set_name("add");
121 change_list.push_back(
122 SyncChange(FROM_HERE,
123 SyncChange::ACTION_DELETE,
124 SyncData::CreateRemoteData(
125 3,
126 delete_specifics,
127 base::Time(),
128 syncer::AttachmentIdList(),
129 syncer::AttachmentServiceProxyForTest::Create())));
130
131 ASSERT_EQ(3U, change_list.size());
132
133 // Verify update.
134 SyncChange e = change_list[0];
135 EXPECT_EQ(SyncChange::ACTION_UPDATE, e.change_type());
136 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType());
137 std::unique_ptr<base::DictionaryValue> ref_spec(
138 EntitySpecificsToValue(update_specifics));
139 std::unique_ptr<base::DictionaryValue> e_spec(
140 EntitySpecificsToValue(e.sync_data().GetSpecifics()));
141 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
142
143 // Verify add.
144 e = change_list[1];
145 EXPECT_EQ(SyncChange::ACTION_ADD, e.change_type());
146 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType());
147 ref_spec = EntitySpecificsToValue(add_specifics);
148 e_spec = EntitySpecificsToValue(e.sync_data().GetSpecifics());
149 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
150
151 // Verify delete.
152 e = change_list[2];
153 EXPECT_EQ(SyncChange::ACTION_DELETE, e.change_type());
154 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType());
155 ref_spec = EntitySpecificsToValue(delete_specifics);
156 e_spec = EntitySpecificsToValue(e.sync_data().GetSpecifics());
157 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
158 }
159
160 } // namespace
161
162 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/api/sync_change_processor_wrapper_for_test.cc ('k') | sync/api/sync_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698