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

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

Issue 10933075: FYI: Remove PerModelSafeGroupState + move ConflictResolution (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
« no previous file with comments | « sync/engine/apply_updates_command.cc ('k') | sync/engine/conflict_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_command.h" 10 #include "sync/engine/apply_updates_command.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 root_server_id); 76 root_server_id);
77 entry_factory_->CreateUnappliedNewItemWithParent("child", 77 entry_factory_->CreateUnappliedNewItemWithParent("child",
78 DefaultBookmarkSpecifics(), 78 DefaultBookmarkSpecifics(),
79 "parent"); 79 "parent");
80 80
81 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 81 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
82 apply_updates_command_.ExecuteImpl(session()); 82 apply_updates_command_.ExecuteImpl(session());
83 83
84 sessions::StatusController* status = session()->mutable_status_controller(); 84 sessions::StatusController* status = session()->mutable_status_controller();
85 85
86 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 86 EXPECT_EQ(0, status->num_encryption_conflicts())
87 ASSERT_TRUE(status->update_progress());
88 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
89 << "All updates should have been attempted";
90 ASSERT_TRUE(status->conflict_progress());
91 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
92 << "Simple update shouldn't result in conflicts"; 87 << "Simple update shouldn't result in conflicts";
93 EXPECT_EQ(0, status->conflict_progress()->EncryptionConflictingItemsSize()) 88 EXPECT_EQ(0, status->num_hierarchy_conflicts())
94 << "Simple update shouldn't result in conflicts"; 89 << "Simple update shouldn't result in conflicts";
95 EXPECT_EQ(0, status->conflict_progress()->HierarchyConflictingItemsSize()) 90 EXPECT_EQ(2, status->num_updates_applied())
96 << "Simple update shouldn't result in conflicts";
97 EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount())
98 << "All items should have been successfully applied"; 91 << "All items should have been successfully applied";
99 } 92 }
100 93
101 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) { 94 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) {
102 // 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
103 // they're received due to dependencies on other unseen items. 96 // they're received due to dependencies on other unseen items.
104 string root_server_id = syncable::GetNullId().GetServerId(); 97 string root_server_id = syncable::GetNullId().GetServerId();
105 entry_factory_->CreateUnappliedNewItemWithParent( 98 entry_factory_->CreateUnappliedNewItemWithParent(
106 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); 99 "a_child_created_first", DefaultBookmarkSpecifics(), "parent");
107 entry_factory_->CreateUnappliedNewItemWithParent( 100 entry_factory_->CreateUnappliedNewItemWithParent(
108 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); 101 "x_child_created_first", DefaultBookmarkSpecifics(), "parent");
109 entry_factory_->CreateUnappliedNewItemWithParent( 102 entry_factory_->CreateUnappliedNewItemWithParent(
110 "parent", DefaultBookmarkSpecifics(), root_server_id); 103 "parent", DefaultBookmarkSpecifics(), root_server_id);
111 entry_factory_->CreateUnappliedNewItemWithParent( 104 entry_factory_->CreateUnappliedNewItemWithParent(
112 "a_child_created_second", DefaultBookmarkSpecifics(), "parent"); 105 "a_child_created_second", DefaultBookmarkSpecifics(), "parent");
113 entry_factory_->CreateUnappliedNewItemWithParent( 106 entry_factory_->CreateUnappliedNewItemWithParent(
114 "x_child_created_second", DefaultBookmarkSpecifics(), "parent"); 107 "x_child_created_second", DefaultBookmarkSpecifics(), "parent");
115 108
116 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 109 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
117 apply_updates_command_.ExecuteImpl(session()); 110 apply_updates_command_.ExecuteImpl(session());
118 111
119 sessions::StatusController* status = session()->mutable_status_controller(); 112 sessions::StatusController* status = session()->mutable_status_controller();
120 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 113 EXPECT_EQ(5, status->num_updates_applied())
121 ASSERT_TRUE(status->update_progress());
122 EXPECT_EQ(5, status->update_progress()->AppliedUpdatesSize())
123 << "All updates should have been attempted";
124 ASSERT_TRUE(status->conflict_progress());
125 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
126 << "Simple update shouldn't result in conflicts, even if out-of-order";
127 EXPECT_EQ(5, status->update_progress()->SuccessfullyAppliedUpdateCount())
128 << "All updates should have been successfully applied"; 114 << "All updates should have been successfully applied";
129 } 115 }
130 116
131 // Runs the ApplyUpdatesCommand on an item that has both local and remote 117 // Runs the ApplyUpdatesCommand on an item that has both local and remote
132 // modifications (IS_UNSYNCED and IS_UNAPPLIED_UPDATE). We expect the command 118 // modifications (IS_UNSYNCED and IS_UNAPPLIED_UPDATE). We expect the command
133 // to detect that this update can't be applied because it is in a CONFLICT 119 // to detect that this update can't be applied because it is in a CONFLICT
134 // state. 120 // state.
135 TEST_F(ApplyUpdatesCommandTest, SimpleConflict) { 121 TEST_F(ApplyUpdatesCommandTest, SimpleConflict) {
136 entry_factory_->CreateUnappliedAndUnsyncedItem("item", BOOKMARKS); 122 entry_factory_->CreateUnappliedAndUnsyncedItem("item", BOOKMARKS);
137 123
138 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 124 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
139 apply_updates_command_.ExecuteImpl(session()); 125 apply_updates_command_.ExecuteImpl(session());
140 126
141 sessions::StatusController* status = session()->mutable_status_controller(); 127 sessions::StatusController* status = session()->mutable_status_controller();
142 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 128 EXPECT_EQ(1, status->num_server_overwrites())
143 ASSERT_TRUE(status->conflict_progress()); 129 << "Unsynced and unapplied item conflict should be resolved";
144 EXPECT_EQ(1, status->conflict_progress()->SimpleConflictingItemsSize()) 130 EXPECT_EQ(0, status->num_updates_applied())
145 << "Unsynced and unapplied item should be a simple conflict"; 131 << "Update should not be applied; we should override the server.";
146 } 132 }
147 133
148 // Runs the ApplyUpdatesCommand on an item that has both local and remote 134 // Runs the ApplyUpdatesCommand on an item that has both local and remote
149 // modifications *and* the remote modification cannot be applied without 135 // modifications *and* the remote modification cannot be applied without
150 // violating the tree constraints. We expect the command to detect that this 136 // violating the tree constraints. We expect the command to detect that this
151 // update can't be applied and that this situation can't be resolved with the 137 // update can't be applied and that this situation can't be resolved with the
152 // simple conflict processing logic; it is in a CONFLICT_HIERARCHY state. 138 // simple conflict processing logic; it is in a CONFLICT_HIERARCHY state.
153 TEST_F(ApplyUpdatesCommandTest, HierarchyAndSimpleConflict) { 139 TEST_F(ApplyUpdatesCommandTest, HierarchyAndSimpleConflict) {
154 // Create a simply-conflicting item. It will start with valid parent ids. 140 // Create a simply-conflicting item. It will start with valid parent ids.
155 int64 handle = entry_factory_->CreateUnappliedAndUnsyncedItem( 141 int64 handle = entry_factory_->CreateUnappliedAndUnsyncedItem(
156 "orphaned_by_server", BOOKMARKS); 142 "orphaned_by_server", BOOKMARKS);
157 { 143 {
158 // Manually set the SERVER_PARENT_ID to bad value. 144 // Manually set the SERVER_PARENT_ID to bad value.
159 // A bad parent indicates a hierarchy conflict. 145 // A bad parent indicates a hierarchy conflict.
160 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 146 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
161 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); 147 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
162 ASSERT_TRUE(entry.good()); 148 ASSERT_TRUE(entry.good());
163 149
164 entry.Put(syncable::SERVER_PARENT_ID, 150 entry.Put(syncable::SERVER_PARENT_ID,
165 TestIdFactory::MakeServer("bogus_parent")); 151 TestIdFactory::MakeServer("bogus_parent"));
166 } 152 }
167 153
168 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 154 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
169 apply_updates_command_.ExecuteImpl(session()); 155 apply_updates_command_.ExecuteImpl(session());
170 156
171 sessions::StatusController* status = session()->mutable_status_controller(); 157 sessions::StatusController* status = session()->mutable_status_controller();
172 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
173
174 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize());
175 158
176 // An update that is both a simple conflict and a hierarchy conflict should be 159 // An update that is both a simple conflict and a hierarchy conflict should be
177 // treated as a hierarchy conflict. 160 // treated as a hierarchy conflict.
178 ASSERT_TRUE(status->conflict_progress()); 161 EXPECT_EQ(1, status->num_hierarchy_conflicts());
179 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
180 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
181 } 162 }
182 163
183 164
184 // Runs the ApplyUpdatesCommand on an item with remote modifications that would 165 // Runs the ApplyUpdatesCommand on an item with remote modifications that would
185 // create a directory loop if the update were applied. We expect the command to 166 // create a directory loop if the update were applied. We expect the command to
186 // detect that this update can't be applied because it is in a 167 // detect that this update can't be applied because it is in a
187 // CONFLICT_HIERARCHY state. 168 // CONFLICT_HIERARCHY state.
188 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDirectoryLoop) { 169 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDirectoryLoop) {
189 // Item 'X' locally has parent of 'root'. Server is updating it to have 170 // Item 'X' locally has parent of 'root'. Server is updating it to have
190 // parent of 'Y'. 171 // parent of 'Y'.
(...skipping 18 matching lines...) Expand all
209 190
210 // If the server's update were applied, we would have X be a child of Y, and Y 191 // If the server's update were applied, we would have X be a child of Y, and Y
211 // as a child of X. That's a directory loop. The UpdateApplicator should 192 // as a child of X. That's a directory loop. The UpdateApplicator should
212 // prevent the update from being applied and note that this is a hierarchy 193 // prevent the update from being applied and note that this is a hierarchy
213 // conflict. 194 // conflict.
214 195
215 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 196 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
216 apply_updates_command_.ExecuteImpl(session()); 197 apply_updates_command_.ExecuteImpl(session());
217 198
218 sessions::StatusController* status = session()->mutable_status_controller(); 199 sessions::StatusController* status = session()->mutable_status_controller();
219 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
220
221 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize());
222 200
223 // This should count as a hierarchy conflict. 201 // This should count as a hierarchy conflict.
224 ASSERT_TRUE(status->conflict_progress()); 202 EXPECT_EQ(1, status->num_hierarchy_conflicts());
225 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
226 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
227 } 203 }
228 204
229 // Runs the ApplyUpdatesCommand on a directory where the server sent us an 205 // Runs the ApplyUpdatesCommand on a directory where the server sent us an
230 // update to add a child to a locally deleted (and unsynced) parent. We expect 206 // update to add a child to a locally deleted (and unsynced) parent. We expect
231 // the command to not apply the update and to indicate the update is in a 207 // the command to not apply the update and to indicate the update is in a
232 // CONFLICT_HIERARCHY state. 208 // CONFLICT_HIERARCHY state.
233 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeletedParent) { 209 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeletedParent) {
234 // Create a locally deleted parent item. 210 // Create a locally deleted parent item.
235 int64 parent_handle; 211 int64 parent_handle;
236 entry_factory_->CreateUnsyncedItem( 212 entry_factory_->CreateUnsyncedItem(
(...skipping 10 matching lines...) Expand all
247 "child", DefaultBookmarkSpecifics(), "parent"); 223 "child", DefaultBookmarkSpecifics(), "parent");
248 224
249 // The server's update may seem valid to some other client, but on this client 225 // The server's update may seem valid to some other client, but on this client
250 // that new item's parent no longer exists. The update should not be applied 226 // that new item's parent no longer exists. The update should not be applied
251 // and the update applicator should indicate this is a hierarchy conflict. 227 // and the update applicator should indicate this is a hierarchy conflict.
252 228
253 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 229 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
254 apply_updates_command_.ExecuteImpl(session()); 230 apply_updates_command_.ExecuteImpl(session());
255 231
256 sessions::StatusController* status = session()->mutable_status_controller(); 232 sessions::StatusController* status = session()->mutable_status_controller();
257 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 233 EXPECT_EQ(1, status->num_hierarchy_conflicts());
258
259 // This should count as a hierarchy conflict.
260 ASSERT_TRUE(status->conflict_progress());
261 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
262 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
263 } 234 }
264 235
265 // Runs the ApplyUpdatesCommand on a directory where the server is trying to 236 // Runs the ApplyUpdatesCommand on a directory where the server is trying to
266 // delete a folder that has a recently added (and unsynced) child. We expect 237 // delete a folder that has a recently added (and unsynced) child. We expect
267 // the command to not apply the update because it is in a CONFLICT_HIERARCHY 238 // the command to not apply the update because it is in a CONFLICT_HIERARCHY
268 // state. 239 // state.
269 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeleteNonEmptyDirectory) { 240 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictDeleteNonEmptyDirectory) {
270 // Create a server-deleted directory. 241 // Create a server-deleted directory.
271 { 242 {
272 // Create it as a child of root node. 243 // Create it as a child of root node.
(...skipping 16 matching lines...) Expand all
289 TestIdFactory::MakeServer("child"), TestIdFactory::MakeServer("parent"), 260 TestIdFactory::MakeServer("child"), TestIdFactory::MakeServer("parent"),
290 "child", false, BOOKMARKS, NULL); 261 "child", false, BOOKMARKS, NULL);
291 262
292 // The server's request to delete the directory must be ignored, otherwise our 263 // The server's request to delete the directory must be ignored, otherwise our
293 // unsynced new child would be orphaned. This is a hierarchy conflict. 264 // unsynced new child would be orphaned. This is a hierarchy conflict.
294 265
295 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 266 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
296 apply_updates_command_.ExecuteImpl(session()); 267 apply_updates_command_.ExecuteImpl(session());
297 268
298 sessions::StatusController* status = session()->mutable_status_controller(); 269 sessions::StatusController* status = session()->mutable_status_controller();
299 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
300
301 // This should count as a hierarchy conflict. 270 // This should count as a hierarchy conflict.
302 ASSERT_TRUE(status->conflict_progress()); 271 EXPECT_EQ(1, status->num_hierarchy_conflicts());
303 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize());
304 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize());
305 } 272 }
306 273
307 // Runs the ApplyUpdatesCommand on a server-created item that has a locally 274 // Runs the ApplyUpdatesCommand on a server-created item that has a locally
308 // unknown parent. We expect the command to not apply the update because the 275 // unknown parent. We expect the command to not apply the update because the
309 // item is in a CONFLICT_HIERARCHY state. 276 // item is in a CONFLICT_HIERARCHY state.
310 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictUnknownParent) { 277 TEST_F(ApplyUpdatesCommandTest, HierarchyConflictUnknownParent) {
311 // We shouldn't be able to do anything with either of these items. 278 // We shouldn't be able to do anything with either of these items.
312 entry_factory_->CreateUnappliedNewItemWithParent( 279 entry_factory_->CreateUnappliedNewItemWithParent(
313 "some_item", DefaultBookmarkSpecifics(), "unknown_parent"); 280 "some_item", DefaultBookmarkSpecifics(), "unknown_parent");
314 entry_factory_->CreateUnappliedNewItemWithParent( 281 entry_factory_->CreateUnappliedNewItemWithParent(
315 "some_other_item", DefaultBookmarkSpecifics(), "some_item"); 282 "some_other_item", DefaultBookmarkSpecifics(), "some_item");
316 283
317 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 284 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
318 apply_updates_command_.ExecuteImpl(session()); 285 apply_updates_command_.ExecuteImpl(session());
319 286
320 sessions::StatusController* status = session()->mutable_status_controller(); 287 sessions::StatusController* status = session()->mutable_status_controller();
321 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 288
322 ASSERT_TRUE(status->update_progress()); 289 EXPECT_EQ(2, status->num_hierarchy_conflicts())
323 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
324 << "All updates should have been attempted";
325 ASSERT_TRUE(status->conflict_progress());
326 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
327 << "Updates with unknown parent should not be treated as 'simple'"
328 << " conflicts";
329 EXPECT_EQ(2, status->conflict_progress()->HierarchyConflictingItemsSize())
330 << "All updates with an unknown ancestors should be in conflict"; 290 << "All updates with an unknown ancestors should be in conflict";
331 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) 291 EXPECT_EQ(0, status->num_updates_applied())
332 << "No item with an unknown ancestor should be applied"; 292 << "No item with an unknown ancestor should be applied";
333 } 293 }
334 294
335 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) { 295 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) {
336 // See what happens when there's a mixture of good and bad updates. 296 // See what happens when there's a mixture of good and bad updates.
337 string root_server_id = syncable::GetNullId().GetServerId(); 297 string root_server_id = syncable::GetNullId().GetServerId();
338 entry_factory_->CreateUnappliedNewItemWithParent( 298 entry_factory_->CreateUnappliedNewItemWithParent(
339 "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); 299 "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent");
340 entry_factory_->CreateUnappliedNewItemWithParent( 300 entry_factory_->CreateUnappliedNewItemWithParent(
341 "first_known_item", DefaultBookmarkSpecifics(), root_server_id); 301 "first_known_item", DefaultBookmarkSpecifics(), root_server_id);
342 entry_factory_->CreateUnappliedNewItemWithParent( 302 entry_factory_->CreateUnappliedNewItemWithParent(
343 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); 303 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent");
344 entry_factory_->CreateUnappliedNewItemWithParent( 304 entry_factory_->CreateUnappliedNewItemWithParent(
345 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); 305 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item");
346 entry_factory_->CreateUnappliedNewItemWithParent( 306 entry_factory_->CreateUnappliedNewItemWithParent(
347 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item"); 307 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item");
348 entry_factory_->CreateUnappliedNewItemWithParent( 308 entry_factory_->CreateUnappliedNewItemWithParent(
349 "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id); 309 "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id);
350 310
351 ExpectGroupToChange(apply_updates_command_, GROUP_UI); 311 ExpectGroupToChange(apply_updates_command_, GROUP_UI);
352 apply_updates_command_.ExecuteImpl(session()); 312 apply_updates_command_.ExecuteImpl(session());
353 313
354 sessions::StatusController* status = session()->mutable_status_controller(); 314 sessions::StatusController* status = session()->mutable_status_controller();
355 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI); 315
356 ASSERT_TRUE(status->update_progress()); 316 EXPECT_EQ(2, status->num_hierarchy_conflicts())
357 EXPECT_EQ(6, status->update_progress()->AppliedUpdatesSize())
358 << "All updates should have been attempted";
359 ASSERT_TRUE(status->conflict_progress());
360 EXPECT_EQ(2, status->conflict_progress()->HierarchyConflictingItemsSize())
361 << "The updates with unknown ancestors should be in conflict"; 317 << "The updates with unknown ancestors should be in conflict";
362 EXPECT_EQ(4, status->update_progress()->SuccessfullyAppliedUpdateCount()) 318 EXPECT_EQ(4, status->num_updates_applied())
363 << "The updates with known ancestors should be successfully applied"; 319 << "The updates with known ancestors should be successfully applied";
364 } 320 }
365 321
366 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) { 322 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) {
367 // Decryptable password updates should be applied. 323 // Decryptable password updates should be applied.
368 Cryptographer* cryptographer; 324 Cryptographer* cryptographer;
369 { 325 {
370 // Storing the cryptographer separately is bad, but for this test we 326 // Storing the cryptographer separately is bad, but for this test we
371 // know it's safe. 327 // know it's safe.
372 syncable::ReadTransaction trans(FROM_HERE, directory()); 328 syncable::ReadTransaction trans(FROM_HERE, directory());
373 cryptographer = directory()->GetCryptographer(&trans); 329 cryptographer = directory()->GetCryptographer(&trans);
374 } 330 }
375 331
376 KeyParams params = {"localhost", "dummy", "foobar"}; 332 KeyParams params = {"localhost", "dummy", "foobar"};
377 cryptographer->AddKey(params); 333 cryptographer->AddKey(params);
378 334
379 sync_pb::EntitySpecifics specifics; 335 sync_pb::EntitySpecifics specifics;
380 sync_pb::PasswordSpecificsData data; 336 sync_pb::PasswordSpecificsData data;
381 data.set_origin("http://example.com"); 337 data.set_origin("http://example.com");
382 338
383 cryptographer->Encrypt(data, 339 cryptographer->Encrypt(data,
384 specifics.mutable_password()->mutable_encrypted()); 340 specifics.mutable_password()->mutable_encrypted());
385 entry_factory_->CreateUnappliedNewItem("item", specifics, false); 341 entry_factory_->CreateUnappliedNewItem("item", specifics, false);
386 342
387 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); 343 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
388 apply_updates_command_.ExecuteImpl(session()); 344 apply_updates_command_.ExecuteImpl(session());
389 345
390 sessions::StatusController* status = session()->mutable_status_controller(); 346 sessions::StatusController* status = session()->mutable_status_controller();
391 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); 347
392 ASSERT_TRUE(status->update_progress()); 348 EXPECT_EQ(1, status->num_updates_applied())
393 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
394 << "All updates should have been attempted";
395 ASSERT_TRUE(status->conflict_progress());
396 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
397 << "No update should be in conflict because they're all decryptable";
398 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
399 << "The updates that can be decrypted should be applied"; 349 << "The updates that can be decrypted should be applied";
400 } 350 }
401 351
402 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { 352 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) {
403 // Undecryptable updates should not be applied. 353 // Undecryptable updates should not be applied.
404 sync_pb::EntitySpecifics encrypted_bookmark; 354 sync_pb::EntitySpecifics encrypted_bookmark;
405 encrypted_bookmark.mutable_encrypted(); 355 encrypted_bookmark.mutable_encrypted();
406 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); 356 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark);
407 string root_server_id = syncable::GetNullId().GetServerId(); 357 string root_server_id = syncable::GetNullId().GetServerId();
408 entry_factory_->CreateUnappliedNewItemWithParent( 358 entry_factory_->CreateUnappliedNewItemWithParent(
409 "folder", encrypted_bookmark, root_server_id); 359 "folder", encrypted_bookmark, root_server_id);
410 entry_factory_->CreateUnappliedNewItem("item2", encrypted_bookmark, false); 360 entry_factory_->CreateUnappliedNewItem("item2", encrypted_bookmark, false);
411 sync_pb::EntitySpecifics encrypted_password; 361 sync_pb::EntitySpecifics encrypted_password;
412 encrypted_password.mutable_password(); 362 encrypted_password.mutable_password();
413 entry_factory_->CreateUnappliedNewItem("item3", encrypted_password, false); 363 entry_factory_->CreateUnappliedNewItem("item3", encrypted_password, false);
414 364
415 ExpectGroupsToChange(apply_updates_command_, GROUP_UI, GROUP_PASSWORD); 365 ExpectGroupsToChange(apply_updates_command_, GROUP_UI, GROUP_PASSWORD);
416 apply_updates_command_.ExecuteImpl(session()); 366 apply_updates_command_.ExecuteImpl(session());
417 367
418 sessions::StatusController* status = session()->mutable_status_controller(); 368 sessions::StatusController* status = session()->mutable_status_controller();
419 EXPECT_TRUE(status->HasConflictingUpdates()) 369 EXPECT_EQ(3, status->num_encryption_conflicts())
420 << "Updates that can't be decrypted should trigger the syncer to have " 370 << "Updates that can't be decrypted should be in encryption conflict";
421 << "conflicting updates."; 371 EXPECT_EQ(0, status->num_updates_applied())
422 { 372 << "No update that can't be decrypted should be applied";
423 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_UI);
424 ASSERT_TRUE(status->update_progress());
425 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
426 << "All updates should have been attempted";
427 ASSERT_TRUE(status->conflict_progress());
428 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
429 << "The updates that can't be decrypted should not be in regular "
430 << "conflict";
431 EXPECT_EQ(2, status->conflict_progress()->EncryptionConflictingItemsSize())
432 << "The updates that can't be decrypted should be in encryption "
433 << "conflict";
434 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount())
435 << "No update that can't be decrypted should be applied";
436 }
437 {
438 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD);
439 ASSERT_TRUE(status->update_progress());
440 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
441 << "All updates should have been attempted";
442 ASSERT_TRUE(status->conflict_progress());
443 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
444 << "The updates that can't be decrypted should not be in regular "
445 << "conflict";
446 EXPECT_EQ(1, status->conflict_progress()->EncryptionConflictingItemsSize())
447 << "The updates that can't be decrypted should be in encryption "
448 << "conflict";
449 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount())
450 << "No update that can't be decrypted should be applied";
451 }
452 } 373 }
453 374
454 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { 375 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) {
455 Cryptographer* cryptographer; 376 Cryptographer* cryptographer;
456 // Only decryptable password updates should be applied. 377 // Only decryptable password updates should be applied.
457 { 378 {
458 sync_pb::EntitySpecifics specifics; 379 sync_pb::EntitySpecifics specifics;
459 sync_pb::PasswordSpecificsData data; 380 sync_pb::PasswordSpecificsData data;
460 data.set_origin("http://example.com/1"); 381 data.set_origin("http://example.com/1");
461 { 382 {
(...skipping 20 matching lines...) Expand all
482 403
483 other_cryptographer.Encrypt(data, 404 other_cryptographer.Encrypt(data,
484 specifics.mutable_password()->mutable_encrypted()); 405 specifics.mutable_password()->mutable_encrypted());
485 entry_factory_->CreateUnappliedNewItem("item2", specifics, false); 406 entry_factory_->CreateUnappliedNewItem("item2", specifics, false);
486 } 407 }
487 408
488 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); 409 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
489 apply_updates_command_.ExecuteImpl(session()); 410 apply_updates_command_.ExecuteImpl(session());
490 411
491 sessions::StatusController* status = session()->mutable_status_controller(); 412 sessions::StatusController* status = session()->mutable_status_controller();
492 EXPECT_TRUE(status->HasConflictingUpdates())
493 << "Updates that can't be decrypted should trigger the syncer to have "
494 << "conflicting updates.";
495 { 413 {
496 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); 414 EXPECT_EQ(1, status->num_encryption_conflicts())
497 ASSERT_TRUE(status->update_progress());
498 EXPECT_EQ(2, status->update_progress()->AppliedUpdatesSize())
499 << "All updates should have been attempted";
500 ASSERT_TRUE(status->conflict_progress());
501 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
502 << "The updates that can't be decrypted should not be in regular "
503 << "conflict";
504 EXPECT_EQ(1, status->conflict_progress()->EncryptionConflictingItemsSize())
505 << "The updates that can't be decrypted should be in encryption " 415 << "The updates that can't be decrypted should be in encryption "
506 << "conflict"; 416 << "conflict";
507 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 417 EXPECT_EQ(1, status->num_updates_applied())
508 << "The undecryptable password update shouldn't be applied"; 418 << "The undecryptable password update shouldn't be applied";
509 } 419 }
510 } 420 }
511 421
512 } // namespace syncer 422 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/apply_updates_command.cc ('k') | sync/engine/conflict_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698