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

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

Issue 533113002: Add test that checks function UpdateServerFieldsFromUpdate is working (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/engine/syncer_util.h ('k') | no next file » | 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 "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "sync/internal_api/public/base/unique_position.h" 8 #include "sync/internal_api/public/base/unique_position.h"
9 #include "sync/internal_api/public/test/test_entry_factory.h"
9 #include "sync/protocol/sync.pb.h" 10 #include "sync/protocol/sync.pb.h"
11 #include "sync/syncable/mutable_entry.h"
12 #include "sync/syncable/syncable_write_transaction.h"
13 #include "sync/test/engine/test_directory_setter_upper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
11 15
12 namespace syncer { 16 namespace syncer {
13 17
14 class GetUpdatePositionTest : public ::testing::Test { 18 class GetUpdatePositionTest : public ::testing::Test {
15 public: 19 public:
20 virtual void SetUp() {
21 dir_maker_.SetUp();
22 entry_factory_.reset(new TestEntryFactory(directory()));
23 }
24 virtual void TearDown() {
25 dir_maker_.TearDown();
26 }
27
28 syncable::Directory* directory() {
29 return dir_maker_.directory();
30 }
31
32 TestEntryFactory* entry_factory() {
33 return entry_factory_.get();
34 }
35
16 GetUpdatePositionTest() { 36 GetUpdatePositionTest() {
17 InitUpdate(); 37 InitUpdate();
18 38
19 // Init test_position to some valid position value, but don't assign 39 // Init test_position to some valid position value, but don't assign
20 // it to the update just yet. 40 // it to the update just yet.
21 std::string pos_suffix = UniquePosition::RandomSuffix(); 41 std::string pos_suffix = UniquePosition::RandomSuffix();
22 test_position = UniquePosition::InitialPosition(pos_suffix); 42 test_position = UniquePosition::InitialPosition(pos_suffix);
23 } 43 }
24 44
25 void InitUpdate() { 45 void InitUpdate() {
(...skipping 16 matching lines...) Expand all
42 void InitProtoPosition() { 62 void InitProtoPosition() {
43 test_position.ToProto(update.mutable_unique_position()); 63 test_position.ToProto(update.mutable_unique_position());
44 } 64 }
45 65
46 void InitInt64Position(int64 pos_value) { 66 void InitInt64Position(int64 pos_value) {
47 update.set_position_in_parent(pos_value); 67 update.set_position_in_parent(pos_value);
48 } 68 }
49 69
50 sync_pb::SyncEntity update; 70 sync_pb::SyncEntity update;
51 UniquePosition test_position; 71 UniquePosition test_position;
72 base::MessageLoop message_loop_;
73 TestDirectorySetterUpper dir_maker_;
74 scoped_ptr<TestEntryFactory> entry_factory_;
52 }; 75 };
53 76
54 // Generate a suffix from originator client GUID and client-assigned ID. These 77 // Generate a suffix from originator client GUID and client-assigned ID. These
55 // values should always be present in updates sent down to the client, and 78 // values should always be present in updates sent down to the client, and
56 // combine to create a globally unique value. 79 // combine to create a globally unique value.
57 TEST_F(GetUpdatePositionTest, SuffixFromUpdate) { 80 TEST_F(GetUpdatePositionTest, SuffixFromUpdate) {
58 InitSuffixIngredients(); 81 InitSuffixIngredients();
59 82
60 // Expect suffix is valid and consistent. 83 // Expect suffix is valid and consistent.
61 std::string suffix1 = GetUniqueBookmarkTagFromUpdate(update); 84 std::string suffix1 = GetUniqueBookmarkTagFromUpdate(update);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 140
118 TEST_F(GetUpdatePositionTest, FromNothing) { 141 TEST_F(GetUpdatePositionTest, FromNothing) {
119 // Init none of the ingredients necessary to make a position. 142 // Init none of the ingredients necessary to make a position.
120 // Verify we still generate a valid position locally. 143 // Verify we still generate a valid position locally.
121 144
122 std::string suffix = GetUniqueBookmarkTagFromUpdate(update); 145 std::string suffix = GetUniqueBookmarkTagFromUpdate(update);
123 UniquePosition pos = GetUpdatePosition(update, suffix); 146 UniquePosition pos = GetUpdatePosition(update, suffix);
124 EXPECT_TRUE(pos.IsValid()); 147 EXPECT_TRUE(pos.IsValid());
125 } 148 }
126 149
150 namespace {
151
152 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
153 sync_pb::EntitySpecifics result;
154 AddDefaultFieldValue(BOOKMARKS, &result);
155 return result;
156 }
157
158 } // namespace
159
160 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromUpdateTest) {
Nicolas Zea 2014/09/03 20:58:52 Comment what the purpose of this test is, here and
reat 2014/09/04 04:32:20 Yes, exactly so. The commit https://codereview.chr
161 // Initialize update with valid data
Nicolas Zea 2014/09/03 20:58:52 nit: periods after comments (here and below)
162 InitSuffixIngredients();
163
164 std::string root_server_id = syncable::GetNullId().GetServerId();
165 int64 handle =
166 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
167 "I", DefaultBookmarkSpecifics(), root_server_id);
168
169 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory());
170 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle);
171
172 // Before update, target has invalid bookmark tag and unique position
173 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
174 EXPECT_FALSE(target.GetServerUniquePosition().IsValid());
175 UpdateServerFieldsFromUpdate(&target, update, "name");
176 // After update, target has valid bookmark tag and unique position
177 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
178 EXPECT_TRUE(target.GetServerUniquePosition().IsValid());
179 }
180
181 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUpdateTest) {
182 // Do not initialize data in update
183 std::string root_server_id = syncable::GetNullId().GetServerId();
184 int64 handle =
185 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
186 "I", DefaultBookmarkSpecifics(), root_server_id);
187
188 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory());
189 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle);
190
191 // Before update, target has invalid bookmark tag and unique position
192 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
193 EXPECT_FALSE(target.GetServerUniquePosition().IsValid());
194 UpdateServerFieldsFromUpdate(&target, update, "name");
195 // After update, target has valid bookmark tag and unique position
196 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag()));
197 EXPECT_TRUE(target.GetServerUniquePosition().IsValid());
198 }
199
127 } // namespace syncer 200 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698