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

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

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

Powered by Google App Engine
This is Rietveld 408576698