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

Side by Side Diff: sync/engine/syncer_util_unittest.cc

Issue 1545553003: Switch to standard integer types in sync/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/engine/syncer_util.cc ('k') | sync/engine/update_applicator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/engine/syncer_util.h" 5 #include "sync/engine/syncer_util.h"
6 6
7 #include <stdint.h>
8
7 #include "base/rand_util.h" 9 #include "base/rand_util.h"
8 #include "sync/internal_api/public/base/unique_position.h" 10 #include "sync/internal_api/public/base/unique_position.h"
9 #include "sync/internal_api/public/test/test_entry_factory.h" 11 #include "sync/internal_api/public/test/test_entry_factory.h"
10 #include "sync/protocol/sync.pb.h" 12 #include "sync/protocol/sync.pb.h"
11 #include "sync/syncable/mutable_entry.h" 13 #include "sync/syncable/mutable_entry.h"
12 #include "sync/syncable/syncable_write_transaction.h" 14 #include "sync/syncable/syncable_write_transaction.h"
13 #include "sync/test/engine/test_directory_setter_upper.h" 15 #include "sync/test/engine/test_directory_setter_upper.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace syncer { 18 namespace syncer {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 57
56 void InitSuffixIngredients() { 58 void InitSuffixIngredients() {
57 update.set_originator_cache_guid("CacheGUID"); 59 update.set_originator_cache_guid("CacheGUID");
58 update.set_originator_client_item_id("OrigID"); 60 update.set_originator_client_item_id("OrigID");
59 } 61 }
60 62
61 void InitProtoPosition() { 63 void InitProtoPosition() {
62 test_position.ToProto(update.mutable_unique_position()); 64 test_position.ToProto(update.mutable_unique_position());
63 } 65 }
64 66
65 void InitInt64Position(int64 pos_value) { 67 void InitInt64Position(int64_t pos_value) {
66 update.set_position_in_parent(pos_value); 68 update.set_position_in_parent(pos_value);
67 } 69 }
68 70
69 sync_pb::SyncEntity update; 71 sync_pb::SyncEntity update;
70 UniquePosition test_position; 72 UniquePosition test_position;
71 base::MessageLoop message_loop_; 73 base::MessageLoop message_loop_;
72 TestDirectorySetterUpper dir_maker_; 74 TestDirectorySetterUpper dir_maker_;
73 scoped_ptr<TestEntryFactory> entry_factory_; 75 scoped_ptr<TestEntryFactory> entry_factory_;
74 }; 76 };
75 77
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 EXPECT_TRUE(pos.LessThan( 120 EXPECT_TRUE(pos.LessThan(
119 UniquePosition::FromInt64(11, UniquePosition::RandomSuffix()))); 121 UniquePosition::FromInt64(11, UniquePosition::RandomSuffix())));
120 } 122 }
121 123
122 TEST_F(GetUpdatePositionTest, FromProto) { 124 TEST_F(GetUpdatePositionTest, FromProto) {
123 InitSuffixIngredients(); 125 InitSuffixIngredients();
124 InitInt64Position(10); 126 InitInt64Position(10);
125 127
126 std::string suffix = GetUniqueBookmarkTagFromUpdate(update); 128 std::string suffix = GetUniqueBookmarkTagFromUpdate(update);
127 129
128 // The proto position is not set, so we should get one based on the int64. 130 // The proto position is not set, so we should get one based on the int64_t.
129 // It should not match the proto we defined in the test harness. 131 // It should not match the proto we defined in the test harness.
130 UniquePosition int64_pos = GetUpdatePosition(update, suffix); 132 UniquePosition int64_pos = GetUpdatePosition(update, suffix);
131 EXPECT_FALSE(int64_pos.Equals(test_position)); 133 EXPECT_FALSE(int64_pos.Equals(test_position));
132 134
133 // Move the test harness' position value into the update proto. 135 // Move the test harness' position value into the update proto.
134 // Expect that it takes precedence over the int64-based position. 136 // Expect that it takes precedence over the int64_t-based position.
135 InitProtoPosition(); 137 InitProtoPosition();
136 UniquePosition pos = GetUpdatePosition(update, suffix); 138 UniquePosition pos = GetUpdatePosition(update, suffix);
137 EXPECT_TRUE(pos.Equals(test_position)); 139 EXPECT_TRUE(pos.Equals(test_position));
138 } 140 }
139 141
140 TEST_F(GetUpdatePositionTest, FromNothing) { 142 TEST_F(GetUpdatePositionTest, FromNothing) {
141 // Init none of the ingredients necessary to make a position. 143 // Init none of the ingredients necessary to make a position.
142 // Verify we still generate a valid position locally. 144 // Verify we still generate a valid position locally.
143 145
144 std::string suffix = GetUniqueBookmarkTagFromUpdate(update); 146 std::string suffix = GetUniqueBookmarkTagFromUpdate(update);
(...skipping 10 matching lines...) Expand all
155 } 157 }
156 158
157 } // namespace 159 } // namespace
158 160
159 // Checks that whole cycle of unique_position updating from 161 // Checks that whole cycle of unique_position updating from
160 // server works fine and does not browser crash. 162 // server works fine and does not browser crash.
161 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromUpdateTest) { 163 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromUpdateTest) {
162 InitSuffixIngredients(); // Initialize update with valid data. 164 InitSuffixIngredients(); // Initialize update with valid data.
163 165
164 std::string root_server_id = syncable::Id::GetRoot().GetServerId(); 166 std::string root_server_id = syncable::Id::GetRoot().GetServerId();
165 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 167 int64_t handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
166 "I", DefaultBookmarkSpecifics(), root_server_id); 168 "I", DefaultBookmarkSpecifics(), root_server_id);
167 169
168 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); 170 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory());
169 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); 171 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle);
170 172
171 // Before update, target has invalid bookmark tag and unique position. 173 // Before update, target has invalid bookmark tag and unique position.
172 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); 174 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
173 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); 175 EXPECT_FALSE(target.GetServerUniquePosition().IsValid());
174 UpdateServerFieldsFromUpdate(&target, update, "name"); 176 UpdateServerFieldsFromUpdate(&target, update, "name");
175 177
176 // After update, target has valid bookmark tag and unique position. 178 // After update, target has valid bookmark tag and unique position.
177 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); 179 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
178 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); 180 EXPECT_TRUE(target.GetServerUniquePosition().IsValid());
179 } 181 }
180 182
181 // Checks that whole cycle of unique_position updating does not 183 // Checks that whole cycle of unique_position updating does not
182 // browser crash even data from server is invalid. 184 // browser crash even data from server is invalid.
183 // It looks like server bug, but browser should not crash and work further. 185 // It looks like server bug, but browser should not crash and work further.
184 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUpdateTest) { 186 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUpdateTest) {
185 // Do not initialize data in update, update is invalid. 187 // Do not initialize data in update, update is invalid.
186 188
187 std::string root_server_id = syncable::Id::GetRoot().GetServerId(); 189 std::string root_server_id = syncable::Id::GetRoot().GetServerId();
188 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 190 int64_t handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
189 "I", DefaultBookmarkSpecifics(), root_server_id); 191 "I", DefaultBookmarkSpecifics(), root_server_id);
190 192
191 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); 193 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory());
192 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); 194 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle);
193 195
194 // Before update, target has invalid bookmark tag and unique position. 196 // Before update, target has invalid bookmark tag and unique position.
195 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); 197 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
196 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); 198 EXPECT_FALSE(target.GetServerUniquePosition().IsValid());
197 UpdateServerFieldsFromUpdate(&target, update, "name"); 199 UpdateServerFieldsFromUpdate(&target, update, "name");
198 200
199 // After update, target has valid bookmark tag and unique position. 201 // After update, target has valid bookmark tag and unique position.
200 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); 202 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
201 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); 203 EXPECT_TRUE(target.GetServerUniquePosition().IsValid());
202 } 204 }
203 205
204 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUniquePositionTest) { 206 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUniquePositionTest) {
205 InitSuffixIngredients(); // Initialize update with valid data. 207 InitSuffixIngredients(); // Initialize update with valid data.
206 sync_pb::SyncEntity invalid_update(update); 208 sync_pb::SyncEntity invalid_update(update);
207 209
208 // Create and Setup an invalid position 210 // Create and Setup an invalid position
209 sync_pb::UniquePosition* invalid_position = new sync_pb::UniquePosition(); 211 sync_pb::UniquePosition* invalid_position = new sync_pb::UniquePosition();
210 invalid_position->set_value(""); 212 invalid_position->set_value("");
211 invalid_update.set_allocated_unique_position(invalid_position); 213 invalid_update.set_allocated_unique_position(invalid_position);
212 214
213 std::string root_server_id = syncable::Id::GetRoot().GetServerId(); 215 std::string root_server_id = syncable::Id::GetRoot().GetServerId();
214 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 216 int64_t handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
215 "I", DefaultBookmarkSpecifics(), root_server_id); 217 "I", DefaultBookmarkSpecifics(), root_server_id);
216 218
217 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); 219 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory());
218 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); 220 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle);
219 221
220 // Before update, target has invalid bookmark tag and unique position. 222 // Before update, target has invalid bookmark tag and unique position.
221 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); 223 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
222 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); 224 EXPECT_FALSE(target.GetServerUniquePosition().IsValid());
223 UpdateServerFieldsFromUpdate(&target, invalid_update, "name"); 225 UpdateServerFieldsFromUpdate(&target, invalid_update, "name");
224 226
225 // After update, target has valid bookmark tag and unique position. 227 // After update, target has valid bookmark tag and unique position.
226 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); 228 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
227 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); 229 EXPECT_TRUE(target.GetServerUniquePosition().IsValid());
228 } 230 }
229 231
230 } // namespace syncer 232 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer_util.cc ('k') | sync/engine/update_applicator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698