| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h" | 10 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 protected: | 65 protected: |
| 66 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesAndResolveConflictsCommandTest); | 66 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesAndResolveConflictsCommandTest); |
| 67 | 67 |
| 68 ApplyUpdatesAndResolveConflictsCommand apply_updates_command_; | 68 ApplyUpdatesAndResolveConflictsCommand apply_updates_command_; |
| 69 scoped_ptr<TestEntryFactory> entry_factory_; | 69 scoped_ptr<TestEntryFactory> entry_factory_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, Simple) { | 72 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, Simple) { |
| 73 string root_server_id = syncable::GetNullId().GetServerId(); | 73 string root_server_id = syncable::GetNullId().GetServerId(); |
| 74 entry_factory_->CreateUnappliedNewItemWithParent("parent", | 74 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 75 DefaultBookmarkSpecifics(), | 75 "parent", DefaultBookmarkSpecifics(), root_server_id); |
| 76 root_server_id); | 76 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 77 entry_factory_->CreateUnappliedNewItemWithParent("child", | 77 "child", DefaultBookmarkSpecifics(), "parent"); |
| 78 DefaultBookmarkSpecifics(), | |
| 79 "parent"); | |
| 80 | 78 |
| 81 ExpectGroupToChange(apply_updates_command_, GROUP_UI); | 79 ExpectGroupToChange(apply_updates_command_, GROUP_UI); |
| 82 apply_updates_command_.ExecuteImpl(session()); | 80 apply_updates_command_.ExecuteImpl(session()); |
| 83 | 81 |
| 84 const sessions::StatusController& status = session()->status_controller(); | 82 const sessions::StatusController& status = session()->status_controller(); |
| 85 EXPECT_EQ(0, status.num_encryption_conflicts()) | 83 EXPECT_EQ(0, status.num_encryption_conflicts()) |
| 86 << "Simple update shouldn't result in conflicts"; | 84 << "Simple update shouldn't result in conflicts"; |
| 87 EXPECT_EQ(0, status.num_hierarchy_conflicts()) | 85 EXPECT_EQ(0, status.num_hierarchy_conflicts()) |
| 88 << "Simple update shouldn't result in conflicts"; | 86 << "Simple update shouldn't result in conflicts"; |
| 89 EXPECT_EQ(2, status.num_updates_applied()) | 87 EXPECT_EQ(2, status.num_updates_applied()) |
| 90 << "All items should have been successfully applied"; | 88 << "All items should have been successfully applied"; |
| 91 } | 89 } |
| 92 | 90 |
| 93 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, | 91 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, |
| 94 UpdateWithChildrenBeforeParents) { | 92 UpdateWithChildrenBeforeParents) { |
| 95 // Set a bunch of updates which are difficult to apply in the order | 93 // Set a bunch of updates which are difficult to apply in the order |
| 96 // they're received due to dependencies on other unseen items. | 94 // they're received due to dependencies on other unseen items. |
| 97 string root_server_id = syncable::GetNullId().GetServerId(); | 95 string root_server_id = syncable::GetNullId().GetServerId(); |
| 98 entry_factory_->CreateUnappliedNewItemWithParent( | 96 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 99 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); | 97 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); |
| 100 entry_factory_->CreateUnappliedNewItemWithParent( | 98 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 101 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); | 99 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); |
| 102 entry_factory_->CreateUnappliedNewItemWithParent( | 100 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 103 "parent", DefaultBookmarkSpecifics(), root_server_id); | 101 "parent", DefaultBookmarkSpecifics(), root_server_id); |
| 104 entry_factory_->CreateUnappliedNewItemWithParent( | 102 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 105 "a_child_created_second", DefaultBookmarkSpecifics(), "parent"); | 103 "a_child_created_second", DefaultBookmarkSpecifics(), "parent"); |
| 106 entry_factory_->CreateUnappliedNewItemWithParent( | 104 entry_factory_->CreateUnappliedNewBookmarkItemWithParent( |
| 107 "x_child_created_second", DefaultBookmarkSpecifics(), "parent"); | 105 "x_child_created_second", DefaultBookmarkSpecifics(), "parent"); |
| 108 | 106 |
| 109 ExpectGroupToChange(apply_updates_command_, GROUP_UI); | 107 ExpectGroupToChange(apply_updates_command_, GROUP_UI); |
| 110 apply_updates_command_.ExecuteImpl(session()); | 108 apply_updates_command_.ExecuteImpl(session()); |
| 111 | 109 |
| 112 const sessions::StatusController& status = session()->status_controller(); | 110 const sessions::StatusController& status = session()->status_controller(); |
| 113 EXPECT_EQ(5, status.num_updates_applied()) | 111 EXPECT_EQ(5, status.num_updates_applied()) |
| 114 << "All updates should have been successfully applied"; | 112 << "All updates should have been successfully applied"; |
| 115 } | 113 } |
| 116 | 114 |
| 117 // Runs the ApplyUpdatesAndResolveConflictsCommand on an item that has both | 115 // Runs the ApplyUpdatesAndResolveConflictsCommand on an item that has both |
| 118 // local and remote modifications (IS_UNSYNCED and IS_UNAPPLIED_UPDATE). We | 116 // local and remote modifications (IS_UNSYNCED and IS_UNAPPLIED_UPDATE). We |
| 119 // expect the command to detect that this update can't be applied because it is | 117 // expect the command to detect that this update can't be applied because it is |
| 120 // in a CONFLICT state. | 118 // in a CONFLICT state. |
| 121 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, SimpleConflict) { | 119 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, SimpleConflict) { |
| 122 entry_factory_->CreateUnappliedAndUnsyncedItem("item", BOOKMARKS); | 120 entry_factory_->CreateUnappliedAndUnsyncedBookmarkItem("item"); |
| 123 | 121 |
| 124 ExpectGroupToChange(apply_updates_command_, GROUP_UI); | 122 ExpectGroupToChange(apply_updates_command_, GROUP_UI); |
| 125 apply_updates_command_.ExecuteImpl(session()); | 123 apply_updates_command_.ExecuteImpl(session()); |
| 126 | 124 |
| 127 const sessions::StatusController& status = session()->status_controller(); | 125 const sessions::StatusController& status = session()->status_controller(); |
| 128 EXPECT_EQ(1, status.num_server_overwrites()) | 126 EXPECT_EQ(1, status.num_server_overwrites()) |
| 129 << "Unsynced and unapplied item conflict should be resolved"; | 127 << "Unsynced and unapplied item conflict should be resolved"; |
| 130 EXPECT_EQ(0, status.num_updates_applied()) | 128 EXPECT_EQ(0, status.num_updates_applied()) |
| 131 << "Update should not be applied; we should override the server."; | 129 << "Update should not be applied; we should override the server."; |
| 132 } | 130 } |
| 133 | 131 |
| 134 // Runs the ApplyUpdatesAndResolveConflictsCommand on an item that has both | 132 // Runs the ApplyUpdatesAndResolveConflictsCommand on an item that has both |
| 135 // local and remote modifications *and* the remote modification cannot be | 133 // local and remote modifications *and* the remote modification cannot be |
| 136 // applied without violating the tree constraints. We expect the command to | 134 // applied without violating the tree constraints. We expect the command to |
| 137 // detect that this update can't be applied and that this situation can't be | 135 // detect that this update can't be applied and that this situation can't be |
| 138 // resolved with the simple conflict processing logic; it is in a | 136 // resolved with the simple conflict processing logic; it is in a |
| 139 // CONFLICT_HIERARCHY state. | 137 // CONFLICT_HIERARCHY state. |
| 140 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, HierarchyAndSimpleConflict) { | 138 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, HierarchyAndSimpleConflict) { |
| 141 // Create a simply-conflicting item. It will start with valid parent ids. | 139 // Create a simply-conflicting item. It will start with valid parent ids. |
| 142 int64 handle = entry_factory_->CreateUnappliedAndUnsyncedItem( | 140 int64 handle = entry_factory_->CreateUnappliedAndUnsyncedBookmarkItem( |
| 143 "orphaned_by_server", BOOKMARKS); | 141 "orphaned_by_server"); |
| 144 { | 142 { |
| 145 // Manually set the SERVER_PARENT_ID to bad value. | 143 // Manually set the SERVER_PARENT_ID to bad value. |
| 146 // A bad parent indicates a hierarchy conflict. | 144 // A bad parent indicates a hierarchy conflict. |
| 147 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 145 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 148 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); | 146 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); |
| 149 ASSERT_TRUE(entry.good()); | 147 ASSERT_TRUE(entry.good()); |
| 150 | 148 |
| 151 entry.Put(syncable::SERVER_PARENT_ID, | 149 entry.Put(syncable::SERVER_PARENT_ID, |
| 152 TestIdFactory::MakeServer("bogus_parent")); | 150 TestIdFactory::MakeServer("bogus_parent")); |
| 153 } | 151 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 233 |
| 236 // Runs the ApplyUpdatesAndResolveConflictsCommand on a directory where the | 234 // Runs the ApplyUpdatesAndResolveConflictsCommand on a directory where the |
| 237 // server is trying to delete a folder that has a recently added (and unsynced) | 235 // server is trying to delete a folder that has a recently added (and unsynced) |
| 238 // child. We expect the command to not apply the update because it is in a | 236 // child. We expect the command to not apply the update because it is in a |
| 239 // CONFLICT_HIERARCHY state. | 237 // CONFLICT_HIERARCHY state. |
| 240 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, | 238 TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, |
| 241 HierarchyConflictDeleteNonEmptyDirectory) { | 239 HierarchyConflictDeleteNonEmptyDirectory) { |
| 242 // Create a server-deleted directory. | 240 // Create a server-deleted directory. |
| 243 { | 241 { |
| 244 // Create it as a child of root node. | 242 // Create it as a child of root node. |
| 245 int64 handle = | 243 int64 handle = entry_factory_->CreateSyncedItem("parent", BOOKMARKS, true); |
| 246 entry_factory_->CreateSyncedItem("parent", BOOKMARKS, true); | |
| 247 | 244 |
| 248 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 245 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 249 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); | 246 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); |
| 250 ASSERT_TRUE(entry.good()); | 247 ASSERT_TRUE(entry.good()); |
| 251 | 248 |
| 252 // Delete it on the server. | 249 // Delete it on the server. |
| 253 entry.Put(syncable::SERVER_VERSION, entry_factory_->GetNextRevision()); | 250 entry.Put(syncable::SERVER_VERSION, entry_factory_->GetNextRevision()); |
| 254 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 251 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 255 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::root()); | 252 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::root()); |
| 256 entry.Put(syncable::SERVER_IS_DEL, true); | 253 entry.Put(syncable::SERVER_IS_DEL, true); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 407 |
| 411 const sessions::StatusController& status = session()->status_controller(); | 408 const sessions::StatusController& status = session()->status_controller(); |
| 412 EXPECT_EQ(1, status.num_encryption_conflicts()) | 409 EXPECT_EQ(1, status.num_encryption_conflicts()) |
| 413 << "The updates that can't be decrypted should be in encryption " | 410 << "The updates that can't be decrypted should be in encryption " |
| 414 << "conflict"; | 411 << "conflict"; |
| 415 EXPECT_EQ(1, status.num_updates_applied()) | 412 EXPECT_EQ(1, status.num_updates_applied()) |
| 416 << "The undecryptable password update shouldn't be applied"; | 413 << "The undecryptable password update shouldn't be applied"; |
| 417 } | 414 } |
| 418 | 415 |
| 419 } // namespace syncer | 416 } // namespace syncer |
| OLD | NEW |