OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/syncable/parent_child_index.h" | 5 #include "sync/syncable/parent_child_index.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 EXPECT_TRUE(index_.Contains(p2)); | 402 EXPECT_TRUE(index_.Contains(p2)); |
403 children = index_.GetChildren(type_root_id); | 403 children = index_.GetChildren(type_root_id); |
404 ASSERT_TRUE(children); | 404 ASSERT_TRUE(children); |
405 EXPECT_EQ(1UL, children->size()); | 405 EXPECT_EQ(1UL, children->size()); |
406 | 406 |
407 index_.Remove(p2); | 407 index_.Remove(p2); |
408 | 408 |
409 EXPECT_FALSE(index_.Contains(p2)); | 409 EXPECT_FALSE(index_.Contains(p2)); |
410 children = index_.GetChildren(type_root); | 410 children = index_.GetChildren(type_root); |
411 ASSERT_EQ(nullptr, children); | 411 ASSERT_EQ(nullptr, children); |
| 412 } |
412 | 413 |
| 414 // Test that the removal isn't sensitive to the order (PurgeEntriesWithTypeIn |
| 415 // removes items in arbitrary order). |
| 416 TEST_F(ParentChildIndexTest, RemoveOutOfOrder) { |
| 417 // Insert a type root and two items (with implicit parent ID). |
| 418 syncable::Id type_root_id = syncable::Id::CreateFromServerId("type_root"); |
| 419 EntryKernel* type_root = MakeTypeRoot(PREFERENCES, type_root_id); |
| 420 index_.Insert(type_root); |
| 421 EntryKernel* p1 = MakeUniqueClientItem(PREFERENCES, 1); |
| 422 EntryKernel* p2 = MakeUniqueClientItem(PREFERENCES, 2); |
| 423 index_.Insert(p1); |
| 424 index_.Insert(p2); |
| 425 |
| 426 // Two items expected under the type root. |
| 427 const OrderedChildSet* children = index_.GetChildren(type_root); |
| 428 ASSERT_TRUE(children); |
| 429 EXPECT_EQ(2UL, children->size()); |
| 430 |
| 431 // Remove all 3 items in arbitrary order. |
| 432 index_.Remove(p2); |
413 index_.Remove(type_root); | 433 index_.Remove(type_root); |
414 EXPECT_EQ(Id(), IndexKnownModelTypeRootId(PREFERENCES)); | 434 index_.Remove(p1); |
| 435 |
| 436 EXPECT_EQ(nullptr, index_.GetChildren(type_root)); |
| 437 |
| 438 // Add a new root and another two items again. |
| 439 type_root = MakeTypeRoot(PREFERENCES, type_root_id); |
| 440 index_.Insert(type_root); |
| 441 |
| 442 index_.Insert(MakeUniqueClientItem(PREFERENCES, 3)); |
| 443 index_.Insert(MakeUniqueClientItem(PREFERENCES, 4)); |
| 444 |
| 445 children = index_.GetChildren(type_root); |
| 446 ASSERT_TRUE(children); |
| 447 // Should have 2 items. If the out of order removal cleared the implicit |
| 448 // parent folder ID prematurely, the collection would have 3 items including |
| 449 // p1. |
| 450 EXPECT_EQ(2UL, children->size()); |
415 } | 451 } |
416 | 452 |
417 } // namespace syncable | 453 } // namespace syncable |
418 } // namespace syncer | 454 } // namespace syncer |
419 | 455 |
OLD | NEW |