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

Side by Side Diff: chrome/browser/sync/engine/apply_updates_command_unittest.cc

Issue 9305001: sync: Remove the remaining conflict sets code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More renames, refactors and fixes Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "chrome/browser/sync/engine/apply_updates_command.h" 10 #include "chrome/browser/sync/engine/apply_updates_command.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (item_id.ServerKnows()) { 136 if (item_id.ServerKnows()) {
137 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); 137 entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
138 entry.Put(syncable::SERVER_IS_DIR, is_folder); 138 entry.Put(syncable::SERVER_IS_DIR, is_folder);
139 entry.Put(syncable::SERVER_PARENT_ID, parent_id); 139 entry.Put(syncable::SERVER_PARENT_ID, parent_id);
140 entry.Put(syncable::SERVER_IS_DEL, false); 140 entry.Put(syncable::SERVER_IS_DEL, false);
141 } 141 }
142 if (metahandle_out) 142 if (metahandle_out)
143 *metahandle_out = entry.Get(syncable::META_HANDLE); 143 *metahandle_out = entry.Get(syncable::META_HANDLE);
144 } 144 }
145 145
146 // Creates an item that is both unsynced an an unapplied update. Returns the
147 // metahandle of the created item.
148 int64 CreateUnappliedAndUnsyncedItem(const string& name,
149 syncable::ModelType model_type) {
150 int64 metahandle = 0;
151 CreateUnsyncedItem(id_factory_.MakeServer(name), id_factory_.root(), name,
152 false, model_type, &metahandle);
153
154 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
155 EXPECT_TRUE(dir.good());
akalin 2012/02/10 23:11:54 if dir is bad, probably want to return invalid met
rlarocque 2012/02/11 00:02:16 The dir is never bad. Will fix anyway, just to be
156 WriteTransaction trans(FROM_HERE, UNITTEST, dir);
157 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle);
158 EXPECT_TRUE(entry.good());
akalin 2012/02/10 23:11:54 you can do if(!entry.good()) { ADD_FAILURE();
rlarocque 2012/02/11 00:02:16 Good idea, thanks!
159 if (!entry.good())
160 return -1;
akalin 2012/02/10 23:11:54 use kInvalidMetaHandle from syncable.h
rlarocque 2012/02/11 00:02:16 I was looking for something like that. Will do.
161
162 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
163 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
164
165 return metahandle;
166 }
167
168
169 // Creates an item that has neither IS_UNSYNED or IS_UNAPPLIED_UPDATE. The
170 // item is known to both the server and client. Returns the metahandle of
171 // the created item.
172 int64 CreateSyncedItem(const std::string& name, syncable::ModelType
173 model_type, bool is_folder) {
174 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
175 EXPECT_TRUE(dir.good());
akalin 2012/02/10 23:11:54 as above
rlarocque 2012/02/11 00:02:16 Done.
176 WriteTransaction trans(FROM_HERE, UNITTEST, dir);
177
178 syncable::Id parent_id(id_factory_.root());
179 syncable::Id item_id(id_factory_.MakeServer(name));
180 int64 version = GetNextRevision();
181
182 sync_pb::EntitySpecifics default_specifics;
183 syncable::AddDefaultExtensionValue(model_type, &default_specifics);
184
185 MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
186 EXPECT_TRUE(entry.good());
187 if (!entry.good())
188 return -1;
akalin 2012/02/10 23:11:54 as above
rlarocque 2012/02/11 00:02:16 Done.
189
190 entry.Put(syncable::ID, item_id);
191 entry.Put(syncable::BASE_VERSION, version);
192 entry.Put(syncable::IS_UNSYNCED, false);
193 entry.Put(syncable::NON_UNIQUE_NAME, name);
194 entry.Put(syncable::IS_DIR, is_folder);
195 entry.Put(syncable::IS_DEL, false);
196 entry.Put(syncable::PARENT_ID, parent_id);
197
198 EXPECT_TRUE(entry.PutPredecessor(id_factory_.root()));
akalin 2012/02/10 23:11:54 return invalidmetahandle here?
rlarocque 2012/02/11 00:02:16 Done.
199 entry.Put(syncable::SPECIFICS, default_specifics);
200
201 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
202 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
203 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X");
204 entry.Put(syncable::SERVER_PARENT_ID, id_factory_.MakeServer("Y"));
205 entry.Put(syncable::SERVER_IS_DIR, is_folder);
206 entry.Put(syncable::SERVER_IS_DEL, false);
207 entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
208 entry.Put(syncable::SERVER_PARENT_ID, parent_id);
209
210 return entry.Get(syncable::META_HANDLE);
211 }
212
213 int64 GetNextRevision() {
214 return next_revision_++;
215 }
216
146 ApplyUpdatesCommand apply_updates_command_; 217 ApplyUpdatesCommand apply_updates_command_;
147 TestIdFactory id_factory_; 218 TestIdFactory id_factory_;
148 private: 219 private:
149 int64 next_revision_; 220 int64 next_revision_;
150 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest); 221 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest);
151 }; 222 };
152 223
153 TEST_F(ApplyUpdatesCommandTest, Simple) { 224 TEST_F(ApplyUpdatesCommandTest, Simple) {
154 string root_server_id = syncable::GetNullId().GetServerId(); 225 string root_server_id = syncable::GetNullId().GetServerId();
155 CreateUnappliedNewItemWithParent("parent", 226 CreateUnappliedNewItemWithParent("parent",
156 DefaultBookmarkSpecifics(), 227 DefaultBookmarkSpecifics(),
157 root_server_id); 228 root_server_id);
158 CreateUnappliedNewItemWithParent("child", 229 CreateUnappliedNewItemWithParent("child",
159 DefaultBookmarkSpecifics(), 230 DefaultBookmarkSpecifics(),
160 "parent"); 231 "parent");
161 232
162 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 233 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
163 apply_updates_command_.ExecuteImpl(session()); 234 apply_updates_command_.ExecuteImpl(session());
164 235
165 sessions::StatusController* status = session()->mutable_status_controller(); 236 sessions::StatusController* status = session()->mutable_status_controller();
166 237
167 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 238 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
168 ASSERT_TRUE(status->update_progress()); 239 ASSERT_TRUE(status->update_progress());
169 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) 240 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
170 << "All updates should have been attempted"; 241 << "All updates should have been attempted";
171 ASSERT_TRUE(status->conflict_progress()); 242 ASSERT_TRUE(status->conflict_progress());
172 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 243 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
244 << "Simple update shouldn't result in conflicts";
245 EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize())
246 << "Simple update shouldn't result in conflicts";
247 EXPECT_EQ(0, status->conflict_progress()->HierarchyConflictingItemsSize())
173 << "Simple update shouldn't result in conflicts"; 248 << "Simple update shouldn't result in conflicts";
174 EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount()) 249 EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount())
175 << "All items should have been successfully applied"; 250 << "All items should have been successfully applied";
176 } 251 }
177 252
178 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) { 253 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) {
179 // Set a bunch of updates which are difficult to apply in the order 254 // Set a bunch of updates which are difficult to apply in the order
180 // they're received due to dependencies on other unseen items. 255 // they're received due to dependencies on other unseen items.
181 string root_server_id = syncable::GetNullId().GetServerId(); 256 string root_server_id = syncable::GetNullId().GetServerId();
182 CreateUnappliedNewItemWithParent("a_child_created_first", 257 CreateUnappliedNewItemWithParent("a_child_created_first",
(...skipping 14 matching lines...) Expand all
197 272
198 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 273 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
199 apply_updates_command_.ExecuteImpl(session()); 274 apply_updates_command_.ExecuteImpl(session());
200 275
201 sessions::StatusController* status = session()->mutable_status_controller(); 276 sessions::StatusController* status = session()->mutable_status_controller();
202 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 277 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
203 ASSERT_TRUE(status->update_progress()); 278 ASSERT_TRUE(status->update_progress());
204 EXPECT_EQ(5, status->update_progress()->AppliedUpdatesSize()) 279 EXPECT_EQ(5, status->update_progress()->AppliedUpdatesSize())
205 << "All updates should have been attempted"; 280 << "All updates should have been attempted";
206 ASSERT_TRUE(status->conflict_progress()); 281 ASSERT_TRUE(status->conflict_progress());
207 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 282 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
208 << "Simple update shouldn't result in conflicts, even if out-of-order"; 283 << "Simple update shouldn't result in conflicts, even if out-of-order";
209 EXPECT_EQ(5, status->update_progress()->SuccessfullyAppliedUpdateCount()) 284 EXPECT_EQ(5, status->update_progress()->SuccessfullyAppliedUpdateCount())
210 << "All updates should have been successfully applied"; 285 << "All updates should have been successfully applied";
211 } 286 }
212 287
213 TEST_F(ApplyUpdatesCommandTest, NestedItemsWithUnknownParent) { 288 // Runs the ApplyUpdatesCommand on an item that has both local and remote
289 // modifications (IS_UNSYNCED and IS_UNAPPLIED_UPDATE). We expect the command
290 // to detect that this update can't be applied because it is in a CONFLICT
291 // state.
292 TEST_F(ApplyUpdatesCommandTest, SimpleConflict) {
293 CreateUnappliedAndUnsyncedItem("item", syncable::BOOKMARKS);
294
295 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
296 apply_updates_command_.ExecuteImpl(session());
297
298 sessions::StatusController* status = session()->mutable_status_controller();
299 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
300 ASSERT_TRUE(status->conflict_progress());
301 EXPECT_EQ(1, status->conflict_progress()->SimpleConflictingItemsSize())
302 << "Unsynced and unapplied item should be a simple conflict";
303 }
304
305 // Runs the ApplyUpdatesCommand on an item that has both local and remote
306 // modifications *and* the remote modification cannot be applied without
307 // violating the tree constraints. We expect the command to detect that this
308 // update can't be applied and that this situation can't be resolved with the
309 // simple conflict processing logic; it is in a CONFLICT_HIERARCHY state.
310 TEST_F(ApplyUpdatesCommandTest, HierarchyAndSimpleConflict) {
311 // Create a simply-conflicting item. It will start with valid parent ids.
312 int64 handle = CreateUnappliedAndUnsyncedItem("orphaned_by_server",
313 syncable::BOOKMARKS);
314 {
315 // Manually set the SERVER_PARENT_ID to bad value.
316 // A bad parent indicates a hierarchy conflict.
317 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
318 ASSERT_TRUE(dir.good());
319 WriteTransaction trans(FROM_HERE, UNITTEST, dir);
320 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
321 ASSERT_TRUE(entry.good());
322
323 entry.Put(syncable::SERVER_PARENT_ID,
324 id_factory_.MakeServer("bogus_parent"));
325 }
326
327 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
328 apply_updates_command_.ExecuteImpl(session());
329
330 sessions::StatusController* status = session()->mutable_status_controller();
331 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
332
333 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize());
334
335 // An update that is both a simple conflict and a hierarchy conflict should be
336 // treated as a hierarchy conflict.
337 ASSERT_TRUE(status->conflict_progress());
338 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
339 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
340 }
341
342
343 // Runs the ApplyUpdatesCommand on an item with remote modifications that would
344 // create a directory loop if the update were applied. We expect the command to
345 // detect that this update can't be applied because it is in a
346 // CONFLICT_HIERARCHY state.
347 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDirectoryLoop) {
348 // Item 'X' locally has parent of 'root'. Server is updating it to have
349 // parent of 'Y'.
350 {
351 // Create it as a child of root node.
352 int64 handle = CreateSyncedItem("X", syncable::BOOKMARKS, true);
353
354 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
355 ASSERT_TRUE(dir.good());
356 WriteTransaction trans(FROM_HERE, UNITTEST, dir);
357 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
358 ASSERT_TRUE(entry.good());
359
360 // Re-parent from root to "Y"
361 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
362 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
363 entry.Put(syncable::SERVER_PARENT_ID, id_factory_.MakeServer("Y"));
364 }
365
366 // Item 'Y' is child of 'X'.
367 CreateUnsyncedItem(id_factory_.MakeServer("Y"), id_factory_.MakeServer("X"),
368 "Y", true, syncable::BOOKMARKS, NULL);
369
370 // If the server's update were applied, we would have X be a child of Y, and Y
371 // as a child of X. That's a directory loop. The UpdateApplicator should
372 // prevent the update from being applied and note that this is a hierarchy
373 // conflict.
374
375 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
376 apply_updates_command_.ExecuteImpl(session());
377
378 sessions::StatusController* status = session()->mutable_status_controller();
379 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
380
381 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize());
382
383 // This should count as a hierarchy conflict.
384 ASSERT_TRUE(status->conflict_progress());
385 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
386 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
387 }
388
389 // Runs the ApplyUpdatesCommand on a directory where the server sent us an
390 // update to add a child to a locally deleted (and unsynced) parent. We expect
391 // the command to not apply the update and to indicate the update is in a
392 // CONFLICT_HIERARCHY state.
393 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeletedParent) {
394 // Create a locally deleted parent item.
395 int64 parent_handle;
396 CreateUnsyncedItem(Id::CreateFromServerId("parent"), id_factory_.root(),
397 "parent", true, syncable::BOOKMARKS, &parent_handle);
398 {
399 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
400 ASSERT_TRUE(dir.good());
401 WriteTransaction trans(FROM_HERE, UNITTEST, dir);
402 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, parent_handle);
403 entry.Put(syncable::IS_DEL, true);
404 }
405
406 // Create an incoming child from the server.
407 CreateUnappliedNewItemWithParent("child", DefaultBookmarkSpecifics(),
408 "parent");
409
410 // The server's update may seem valid to some other client, but on this client
411 // that new item's parent no longer exists. The update should not be applied
412 // and the update applicator should indicate this is a hierarchy conflict.
413
414 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
415 apply_updates_command_.ExecuteImpl(session());
416
417 sessions::StatusController* status = session()->mutable_status_controller();
418 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
419
420 // This should count as a hierarchy conflict.
421 ASSERT_TRUE(status->conflict_progress());
422 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
423 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
424 }
425
426 // Runs the ApplyUpdatesCommand on a directory where the server is trying to
427 // delete a folder that has a recently added (and unsynced) child. We expect
428 // the command to not apply the update because it is in a CONFLICT_HIERARCHY
429 // state.
430 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeleteNonEmptyDirectory) {
431 // Create a server-deleted directory.
432 {
433 // Create it as a child of root node.
434 int64 handle = CreateSyncedItem("parent", syncable::BOOKMARKS, true);
435
436 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
437 ASSERT_TRUE(dir.good());
438 WriteTransaction trans(FROM_HERE, UNITTEST, dir);
439 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
440 ASSERT_TRUE(entry.good());
441
442 // Delete it on the server.
443 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
444 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
445 entry.Put(syncable::SERVER_PARENT_ID, id_factory_.root());
446 entry.Put(syncable::SERVER_IS_DEL, true);
447 }
448
449 // Create a local child of the server-deleted directory.
450 CreateUnsyncedItem(id_factory_.MakeServer("child"),
451 id_factory_.MakeServer("parent"), "child", false,
452 syncable::BOOKMARKS, NULL);
453
454 // The server's request to delete the directory must be ignored, otherwise our
455 // unsynced new child would be orphaned. This is a hierarchy conflict.
456
457 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
458 apply_updates_command_.ExecuteImpl(session());
459
460 sessions::StatusController* status = session()->mutable_status_controller();
461 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
462
463 // This should count as a hierarchy conflict.
464 ASSERT_TRUE(status->conflict_progress());
465 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
466 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
467 }
468
469 // Runs the ApplyUpdatesCommand on a server-created item that has a locally
470 // unknown parent. We expect the command to not apply the update because the
471 // item is in a CONFLICT_HIERARCHY state.
472 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictUnknownParent) {
214 // We shouldn't be able to do anything with either of these items. 473 // We shouldn't be able to do anything with either of these items.
215 CreateUnappliedNewItemWithParent("some_item", 474 CreateUnappliedNewItemWithParent("some_item",
216 DefaultBookmarkSpecifics(), 475 DefaultBookmarkSpecifics(),
217 "unknown_parent"); 476 "unknown_parent");
218 CreateUnappliedNewItemWithParent("some_other_item", 477 CreateUnappliedNewItemWithParent("some_other_item",
219 DefaultBookmarkSpecifics(), 478 DefaultBookmarkSpecifics(),
220 "some_item"); 479 "some_item");
221 480
222 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 481 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
223 apply_updates_command_.ExecuteImpl(session()); 482 apply_updates_command_.ExecuteImpl(session());
224 483
225 sessions::StatusController* status = session()->mutable_status_controller(); 484 sessions::StatusController* status = session()->mutable_status_controller();
226 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 485 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
227 ASSERT_TRUE(status->update_progress()); 486 ASSERT_TRUE(status->update_progress());
228 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) 487 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
229 << "All updates should have been attempted"; 488 << "All updates should have been attempted";
230 ASSERT_TRUE(status->conflict_progress()); 489 ASSERT_TRUE(status->conflict_progress());
231 EXPECT_EQ(2, status->conflict_progress()->ConflictingItemsSize()) 490 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
491 << "Updates with unknown parent should not be treated as 'simple'"
492 << " conflicts";
493 EXPECT_EQ(2, status->conflict_progress()->HierarchyConflictingItemsSize())
232 << "All updates with an unknown ancestors should be in conflict"; 494 << "All updates with an unknown ancestors should be in conflict";
233 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) 495 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount())
234 << "No item with an unknown ancestor should be applied"; 496 << "No item with an unknown ancestor should be applied";
235 } 497 }
236 498
237 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) { 499 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) {
238 // See what happens when there's a mixture of good and bad updates. 500 // See what happens when there's a mixture of good and bad updates.
239 string root_server_id = syncable::GetNullId().GetServerId(); 501 string root_server_id = syncable::GetNullId().GetServerId();
240 CreateUnappliedNewItemWithParent("first_unknown_item", 502 CreateUnappliedNewItemWithParent("first_unknown_item",
241 DefaultBookmarkSpecifics(), 503 DefaultBookmarkSpecifics(),
(...skipping 16 matching lines...) Expand all
258 520
259 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 521 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
260 apply_updates_command_.ExecuteImpl(session()); 522 apply_updates_command_.ExecuteImpl(session());
261 523
262 sessions::StatusController* status = session()->mutable_status_controller(); 524 sessions::StatusController* status = session()->mutable_status_controller();
263 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 525 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
264 ASSERT_TRUE(status->update_progress()); 526 ASSERT_TRUE(status->update_progress());
265 EXPECT_EQ(6, status->update_progress()->AppliedUpdatesSize()) 527 EXPECT_EQ(6, status->update_progress()->AppliedUpdatesSize())
266 << "All updates should have been attempted"; 528 << "All updates should have been attempted";
267 ASSERT_TRUE(status->conflict_progress()); 529 ASSERT_TRUE(status->conflict_progress());
268 EXPECT_EQ(2, status->conflict_progress()->ConflictingItemsSize()) 530 EXPECT_EQ(2, status->conflict_progress()->HierarchyConflictingItemsSize())
269 << "The updates with unknown ancestors should be in conflict"; 531 << "The updates with unknown ancestors should be in conflict";
270 EXPECT_EQ(4, status->update_progress()->SuccessfullyAppliedUpdateCount()) 532 EXPECT_EQ(4, status->update_progress()->SuccessfullyAppliedUpdateCount())
271 << "The updates with known ancestors should be successfully applied"; 533 << "The updates with known ancestors should be successfully applied";
272 } 534 }
273 535
274 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) { 536 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) {
275 // Decryptable password updates should be applied. 537 // Decryptable password updates should be applied.
276 Cryptographer* cryptographer; 538 Cryptographer* cryptographer;
277 { 539 {
278 // Storing the cryptographer separately is bad, but for this test we 540 // Storing the cryptographer separately is bad, but for this test we
(...skipping 18 matching lines...) Expand all
297 559
298 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); 560 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
299 apply_updates_command_.ExecuteImpl(session()); 561 apply_updates_command_.ExecuteImpl(session());
300 562
301 sessions::StatusController* status = session()->mutable_status_controller(); 563 sessions::StatusController* status = session()->mutable_status_controller();
302 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); 564 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD);
303 ASSERT_TRUE(status->update_progress()); 565 ASSERT_TRUE(status->update_progress());
304 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 566 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
305 << "All updates should have been attempted"; 567 << "All updates should have been attempted";
306 ASSERT_TRUE(status->conflict_progress()); 568 ASSERT_TRUE(status->conflict_progress());
307 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 569 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
308 << "No update should be in conflict because they're all decryptable"; 570 << "No update should be in conflict because they're all decryptable";
309 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 571 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
310 << "The updates that can be decrypted should be applied"; 572 << "The updates that can be decrypted should be applied";
311 } 573 }
312 574
313 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { 575 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) {
314 // Undecryptable updates should not be applied. 576 // Undecryptable updates should not be applied.
315 sync_pb::EntitySpecifics encrypted_bookmark; 577 sync_pb::EntitySpecifics encrypted_bookmark;
316 encrypted_bookmark.mutable_encrypted(); 578 encrypted_bookmark.mutable_encrypted();
317 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); 579 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark);
(...skipping 12 matching lines...) Expand all
330 sessions::StatusController* status = session()->mutable_status_controller(); 592 sessions::StatusController* status = session()->mutable_status_controller();
331 EXPECT_TRUE(status->HasConflictingUpdates()) 593 EXPECT_TRUE(status->HasConflictingUpdates())
332 << "Updates that can't be decrypted should trigger the syncer to have " 594 << "Updates that can't be decrypted should trigger the syncer to have "
333 << "conflicting updates."; 595 << "conflicting updates.";
334 { 596 {
335 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 597 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
336 ASSERT_TRUE(status->update_progress()); 598 ASSERT_TRUE(status->update_progress());
337 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) 599 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
338 << "All updates should have been attempted"; 600 << "All updates should have been attempted";
339 ASSERT_TRUE(status->conflict_progress()); 601 ASSERT_TRUE(status->conflict_progress());
340 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 602 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
341 << "The updates that can't be decrypted should not be in regular " 603 << "The updates that can't be decrypted should not be in regular "
342 << "conflict"; 604 << "conflict";
343 EXPECT_EQ(2, status->conflict_progress()->NonblockingConflictingItemsSize()) 605 EXPECT_EQ(2, status->conflict_progress()->EncryptionConflictingItemsSize())
344 << "The updates that can't be decrypted should be in nonblocking " 606 << "The updates that can't be decrypted should be in encryption "
345 << "conflict"; 607 << "conflict";
346 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) 608 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount())
347 << "No update that can't be decrypted should be applied"; 609 << "No update that can't be decrypted should be applied";
348 } 610 }
349 { 611 {
350 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); 612 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD);
351 ASSERT_TRUE(status->update_progress()); 613 ASSERT_TRUE(status->update_progress());
352 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 614 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
353 << "All updates should have been attempted"; 615 << "All updates should have been attempted";
354 ASSERT_TRUE(status->conflict_progress()); 616 ASSERT_TRUE(status->conflict_progress());
355 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 617 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
356 << "The updates that can't be decrypted should not be in regular " 618 << "The updates that can't be decrypted should not be in regular "
357 << "conflict"; 619 << "conflict";
358 EXPECT_EQ(1, status->conflict_progress()->NonblockingConflictingItemsSize()) 620 EXPECT_EQ(1, status->conflict_progress()->EncryptionConflictingItemsSize())
359 << "The updates that can't be decrypted should be in nonblocking " 621 << "The updates that can't be decrypted should be in encryption "
360 << "conflict"; 622 << "conflict";
361 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) 623 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount())
362 << "No update that can't be decrypted should be applied"; 624 << "No update that can't be decrypted should be applied";
363 } 625 }
364 } 626 }
365 627
366 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { 628 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) {
367 // Only decryptable password updates should be applied. 629 // Only decryptable password updates should be applied.
368 { 630 {
369 sync_pb::EntitySpecifics specifics; 631 sync_pb::EntitySpecifics specifics;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 sessions::StatusController* status = session()->mutable_status_controller(); 667 sessions::StatusController* status = session()->mutable_status_controller();
406 EXPECT_TRUE(status->HasConflictingUpdates()) 668 EXPECT_TRUE(status->HasConflictingUpdates())
407 << "Updates that can't be decrypted should trigger the syncer to have " 669 << "Updates that can't be decrypted should trigger the syncer to have "
408 << "conflicting updates."; 670 << "conflicting updates.";
409 { 671 {
410 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); 672 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD);
411 ASSERT_TRUE(status->update_progress()); 673 ASSERT_TRUE(status->update_progress());
412 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize()) 674 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
413 << "All updates should have been attempted"; 675 << "All updates should have been attempted";
414 ASSERT_TRUE(status->conflict_progress()); 676 ASSERT_TRUE(status->conflict_progress());
415 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 677 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
416 << "The updates that can't be decrypted should not be in regular " 678 << "The updates that can't be decrypted should not be in regular "
417 << "conflict"; 679 << "conflict";
418 EXPECT_EQ(1, status->conflict_progress()->NonblockingConflictingItemsSize()) 680 EXPECT_EQ(1, status->conflict_progress()->EncryptionConflictingItemsSize())
419 << "The updates that can't be decrypted should be in nonblocking " 681 << "The updates that can't be decrypted should be in encryption "
420 << "conflict"; 682 << "conflict";
421 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 683 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
422 << "The undecryptable password update shouldn't be applied"; 684 << "The undecryptable password update shouldn't be applied";
423 } 685 }
424 } 686 }
425 687
426 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { 688 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
427 // Storing the cryptographer separately is bad, but for this test we 689 // Storing the cryptographer separately is bad, but for this test we
428 // know it's safe. 690 // know it's safe.
429 Cryptographer* cryptographer; 691 Cryptographer* cryptographer;
(...skipping 26 matching lines...) Expand all
456 718
457 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); 719 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
458 apply_updates_command_.ExecuteImpl(session()); 720 apply_updates_command_.ExecuteImpl(session());
459 721
460 sessions::StatusController* status = session()->mutable_status_controller(); 722 sessions::StatusController* status = session()->mutable_status_controller();
461 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 723 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
462 ASSERT_TRUE(status->update_progress()); 724 ASSERT_TRUE(status->update_progress());
463 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 725 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
464 << "All updates should have been attempted"; 726 << "All updates should have been attempted";
465 ASSERT_TRUE(status->conflict_progress()); 727 ASSERT_TRUE(status->conflict_progress());
466 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 728 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
467 << "The nigori update shouldn't be in conflict"; 729 << "The nigori update shouldn't be in conflict";
468 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 730 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
469 << "The nigori update should be applied"; 731 << "The nigori update should be applied";
470 732
471 EXPECT_FALSE(cryptographer->is_ready()); 733 EXPECT_FALSE(cryptographer->is_ready());
472 EXPECT_TRUE(cryptographer->has_pending_keys()); 734 EXPECT_TRUE(cryptographer->has_pending_keys());
473 EXPECT_TRUE( 735 EXPECT_TRUE(
474 cryptographer->GetEncryptedTypes() 736 cryptographer->GetEncryptedTypes()
475 .Equals(syncable::ModelTypeSet::All())); 737 .Equals(syncable::ModelTypeSet::All()));
476 } 738 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 772
511 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); 773 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
512 apply_updates_command_.ExecuteImpl(session()); 774 apply_updates_command_.ExecuteImpl(session());
513 775
514 sessions::StatusController* status = session()->mutable_status_controller(); 776 sessions::StatusController* status = session()->mutable_status_controller();
515 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 777 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
516 ASSERT_TRUE(status->update_progress()); 778 ASSERT_TRUE(status->update_progress());
517 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 779 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
518 << "All updates should have been attempted"; 780 << "All updates should have been attempted";
519 ASSERT_TRUE(status->conflict_progress()); 781 ASSERT_TRUE(status->conflict_progress());
520 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 782 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
521 << "The nigori update shouldn't be in conflict"; 783 << "The nigori update shouldn't be in conflict";
522 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 784 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
523 << "The nigori update should be applied"; 785 << "The nigori update should be applied";
524 786
525 EXPECT_FALSE(cryptographer->is_ready()); 787 EXPECT_FALSE(cryptographer->is_ready());
526 EXPECT_TRUE(cryptographer->has_pending_keys()); 788 EXPECT_TRUE(cryptographer->has_pending_keys());
527 EXPECT_TRUE( 789 EXPECT_TRUE(
528 cryptographer->GetEncryptedTypes() 790 cryptographer->GetEncryptedTypes()
529 .Equals(syncable::ModelTypeSet::All())); 791 .Equals(syncable::ModelTypeSet::All()));
530 } 792 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 862
601 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); 863 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
602 apply_updates_command_.ExecuteImpl(session()); 864 apply_updates_command_.ExecuteImpl(session());
603 865
604 sessions::StatusController* status = session()->mutable_status_controller(); 866 sessions::StatusController* status = session()->mutable_status_controller();
605 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 867 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
606 ASSERT_TRUE(status->update_progress()); 868 ASSERT_TRUE(status->update_progress());
607 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 869 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
608 << "All updates should have been attempted"; 870 << "All updates should have been attempted";
609 ASSERT_TRUE(status->conflict_progress()); 871 ASSERT_TRUE(status->conflict_progress());
610 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 872 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
611 << "No updates should be in conflict"; 873 << "No updates should be in conflict";
612 EXPECT_EQ(0, status->conflict_progress()->NonblockingConflictingItemsSize()) 874 EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize())
613 << "No updates should be in conflict"; 875 << "No updates should be in conflict";
614 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 876 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
615 << "The nigori update should be applied"; 877 << "The nigori update should be applied";
616 EXPECT_FALSE(cryptographer->has_pending_keys()); 878 EXPECT_FALSE(cryptographer->has_pending_keys());
617 EXPECT_TRUE(cryptographer->is_ready()); 879 EXPECT_TRUE(cryptographer->is_ready());
618 { 880 {
619 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); 881 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
620 ASSERT_TRUE(dir.good()); 882 ASSERT_TRUE(dir.good());
621 ReadTransaction trans(FROM_HERE, dir); 883 ReadTransaction trans(FROM_HERE, dir);
622 884
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 965
704 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); 966 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
705 apply_updates_command_.ExecuteImpl(session()); 967 apply_updates_command_.ExecuteImpl(session());
706 968
707 sessions::StatusController* status = session()->mutable_status_controller(); 969 sessions::StatusController* status = session()->mutable_status_controller();
708 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 970 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
709 ASSERT_TRUE(status->update_progress()); 971 ASSERT_TRUE(status->update_progress());
710 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 972 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
711 << "All updates should have been attempted"; 973 << "All updates should have been attempted";
712 ASSERT_TRUE(status->conflict_progress()); 974 ASSERT_TRUE(status->conflict_progress());
713 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) 975 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
714 << "The unsynced changes don't trigger a blocking conflict with the " 976 << "The unsynced changes don't trigger a blocking conflict with the "
715 << "nigori update."; 977 << "nigori update.";
716 EXPECT_EQ(0, status->conflict_progress()->NonblockingConflictingItemsSize()) 978 EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize())
717 << "The unsynced changes don't trigger a non-blocking conflict with the " 979 << "The unsynced changes don't trigger an encryption conflict with the "
718 << "nigori update."; 980 << "nigori update.";
719 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 981 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
720 << "The nigori update should be applied"; 982 << "The nigori update should be applied";
721 EXPECT_FALSE(cryptographer->is_ready()); 983 EXPECT_FALSE(cryptographer->is_ready());
722 EXPECT_TRUE(cryptographer->has_pending_keys()); 984 EXPECT_TRUE(cryptographer->has_pending_keys());
723 { 985 {
724 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); 986 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
725 ASSERT_TRUE(dir.good()); 987 ASSERT_TRUE(dir.good());
726 ReadTransaction trans(FROM_HERE, dir); 988 ReadTransaction trans(FROM_HERE, dir);
727 989
728 // Since we have pending keys, we would have failed to encrypt, but the 990 // Since we have pending keys, we would have failed to encrypt, but the
729 // cryptographer should be updated. 991 // cryptographer should be updated.
730 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); 992 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types));
731 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals( 993 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(
732 syncable::ModelTypeSet().All())); 994 syncable::ModelTypeSet().All()));
733 EXPECT_FALSE(cryptographer->is_ready()); 995 EXPECT_FALSE(cryptographer->is_ready());
734 EXPECT_TRUE(cryptographer->has_pending_keys()); 996 EXPECT_TRUE(cryptographer->has_pending_keys());
735 997
736 Syncer::UnsyncedMetaHandles handles; 998 Syncer::UnsyncedMetaHandles handles;
737 SyncerUtil::GetUnsyncedEntries(&trans, &handles); 999 SyncerUtil::GetUnsyncedEntries(&trans, &handles);
738 EXPECT_EQ(2*batch_s+1, handles.size()); 1000 EXPECT_EQ(2*batch_s+1, handles.size());
739 } 1001 }
740 } 1002 }
741 1003
742 } // namespace browser_sync 1004 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698