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

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

Powered by Google App Engine
This is Rietveld 408576698