OLD | NEW |
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/internal_api/public/test/test_entry_factory.h" |
10 #include "sync/protocol/sync.pb.h" | 10 #include "sync/protocol/sync.pb.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return result; | 156 return result; |
157 } | 157 } |
158 | 158 |
159 } // namespace | 159 } // namespace |
160 | 160 |
161 // Checks that whole cycle of unique_position updating from | 161 // Checks that whole cycle of unique_position updating from |
162 // server works fine and does not browser crash. | 162 // server works fine and does not browser crash. |
163 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromUpdateTest) { | 163 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromUpdateTest) { |
164 InitSuffixIngredients(); // Initialize update with valid data. | 164 InitSuffixIngredients(); // Initialize update with valid data. |
165 | 165 |
166 std::string root_server_id = syncable::GetNullId().GetServerId(); | 166 std::string root_server_id = syncable::Id::GetRoot().GetServerId(); |
167 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 167 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
168 "I", DefaultBookmarkSpecifics(), root_server_id); | 168 "I", DefaultBookmarkSpecifics(), root_server_id); |
169 | 169 |
170 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); | 170 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); |
171 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); | 171 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); |
172 | 172 |
173 // Before update, target has invalid bookmark tag and unique position. | 173 // Before update, target has invalid bookmark tag and unique position. |
174 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); | 174 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
175 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); | 175 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); |
176 UpdateServerFieldsFromUpdate(&target, update, "name"); | 176 UpdateServerFieldsFromUpdate(&target, update, "name"); |
177 | 177 |
178 // After update, target has valid bookmark tag and unique position. | 178 // After update, target has valid bookmark tag and unique position. |
179 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); | 179 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
180 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); | 180 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); |
181 } | 181 } |
182 | 182 |
183 // Checks that whole cycle of unique_position updating does not | 183 // Checks that whole cycle of unique_position updating does not |
184 // browser crash even data from server is invalid. | 184 // browser crash even data from server is invalid. |
185 // 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. |
186 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUpdateTest) { | 186 TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUpdateTest) { |
187 // Do not initialize data in update, update is invalid. | 187 // Do not initialize data in update, update is invalid. |
188 | 188 |
189 std::string root_server_id = syncable::GetNullId().GetServerId(); | 189 std::string root_server_id = syncable::Id::GetRoot().GetServerId(); |
190 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 190 int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
191 "I", DefaultBookmarkSpecifics(), root_server_id); | 191 "I", DefaultBookmarkSpecifics(), root_server_id); |
192 | 192 |
193 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); | 193 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); |
194 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); | 194 syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); |
195 | 195 |
196 // Before update, target has invalid bookmark tag and unique position. | 196 // Before update, target has invalid bookmark tag and unique position. |
197 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); | 197 EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
198 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); | 198 EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); |
199 UpdateServerFieldsFromUpdate(&target, update, "name"); | 199 UpdateServerFieldsFromUpdate(&target, update, "name"); |
200 | 200 |
201 // After update, target has valid bookmark tag and unique position. | 201 // After update, target has valid bookmark tag and unique position. |
202 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); | 202 EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
203 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); | 203 EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); |
204 } | 204 } |
205 | 205 |
206 } // namespace syncer | 206 } // namespace syncer |
OLD | NEW |