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

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

Issue 271613006: sync: Populate debug counters for directory types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/engine/directory_update_handler.h" 5 #include "sync/engine/directory_update_handler.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "sync/engine/syncer_proto_util.h" 10 #include "sync/engine/syncer_proto_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return ui_worker_; 79 return ui_worker_;
80 } 80 }
81 81
82 bool EntryExists(const std::string& id) { 82 bool EntryExists(const std::string& id) {
83 syncable::ReadTransaction trans(FROM_HERE, dir()); 83 syncable::ReadTransaction trans(FROM_HERE, dir());
84 syncable::Entry e(&trans, syncable::GET_BY_ID, 84 syncable::Entry e(&trans, syncable::GET_BY_ID,
85 syncable::Id::CreateFromServerId(id)); 85 syncable::Id::CreateFromServerId(id));
86 return e.good() && !e.GetIsDel(); 86 return e.good() && !e.GetIsDel();
87 } 87 }
88 88
89 protected:
90 // Used in the construction of DirectoryTypeDebugInfoEmitters.
91 ObserverList<TypeDebugInfoObserver> type_observers_;
92
89 private: 93 private:
90 base::MessageLoop loop_; // Needed to initialize the directory. 94 base::MessageLoop loop_; // Needed to initialize the directory.
91 TestDirectorySetterUpper dir_maker_; 95 TestDirectorySetterUpper dir_maker_;
92 scoped_refptr<FakeModelWorker> ui_worker_; 96 scoped_refptr<FakeModelWorker> ui_worker_;
93 }; 97 };
94 98
95 scoped_ptr<sync_pb::SyncEntity> 99 scoped_ptr<sync_pb::SyncEntity>
96 DirectoryUpdateHandlerProcessUpdateTest::CreateUpdate( 100 DirectoryUpdateHandlerProcessUpdateTest::CreateUpdate(
97 const std::string& id, 101 const std::string& id,
98 const std::string& parent, 102 const std::string& parent,
(...skipping 19 matching lines...) Expand all
118 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers( 122 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers(
119 DirectoryUpdateHandler* handler, 123 DirectoryUpdateHandler* handler,
120 const sync_pb::DataTypeProgressMarker& progress) { 124 const sync_pb::DataTypeProgressMarker& progress) {
121 handler->UpdateProgressMarker(progress); 125 handler->UpdateProgressMarker(progress);
122 } 126 }
123 127
124 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; 128 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ==";
125 129
126 // Test that the bookmark tag is set on newly downloaded items. 130 // Test that the bookmark tag is set on newly downloaded items.
127 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { 131 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) {
128 DirectoryTypeDebugInfoEmitter emitter; 132 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
129 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); 133 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
130 sync_pb::GetUpdatesResponse gu_response; 134 sync_pb::GetUpdatesResponse gu_response;
131 sessions::StatusController status; 135 sessions::StatusController status;
132 136
133 // Add a bookmark item to the update message. 137 // Add a bookmark item to the update message.
134 std::string root = syncable::GetNullId().GetServerId(); 138 std::string root = syncable::GetNullId().GetServerId();
135 syncable::Id server_id = syncable::Id::CreateFromServerId("b1"); 139 syncable::Id server_id = syncable::Id::CreateFromServerId("b1");
136 scoped_ptr<sync_pb::SyncEntity> e = 140 scoped_ptr<sync_pb::SyncEntity> e =
137 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); 141 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS);
138 e->set_originator_cache_guid( 142 e->set_originator_cache_guid(
(...skipping 18 matching lines...) Expand all
157 // If this assertion fails, that might indicate that the algorithm used to 161 // If this assertion fails, that might indicate that the algorithm used to
158 // generate bookmark tags has been modified. This could have implications for 162 // generate bookmark tags has been modified. This could have implications for
159 // bookmark ordering. Please make sure you know what you're doing if you 163 // bookmark ordering. Please make sure you know what you're doing if you
160 // intend to make such a change. 164 // intend to make such a change.
161 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag()); 165 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag());
162 } 166 }
163 167
164 // Test the receipt of a type root node. 168 // Test the receipt of a type root node.
165 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, 169 TEST_F(DirectoryUpdateHandlerProcessUpdateTest,
166 ReceiveServerCreatedBookmarkFolders) { 170 ReceiveServerCreatedBookmarkFolders) {
167 DirectoryTypeDebugInfoEmitter emitter; 171 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
168 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); 172 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
169 sync_pb::GetUpdatesResponse gu_response; 173 sync_pb::GetUpdatesResponse gu_response;
170 sessions::StatusController status; 174 sessions::StatusController status;
171 175
172 // Create an update that mimics the bookmark root. 176 // Create an update that mimics the bookmark root.
173 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); 177 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz");
174 std::string root = syncable::GetNullId().GetServerId(); 178 std::string root = syncable::GetNullId().GetServerId();
175 scoped_ptr<sync_pb::SyncEntity> e = 179 scoped_ptr<sync_pb::SyncEntity> e =
176 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); 180 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS);
177 e->set_server_defined_unique_tag("google_chrome_bookmarks"); 181 e->set_server_defined_unique_tag("google_chrome_bookmarks");
(...skipping 14 matching lines...) Expand all
192 ASSERT_TRUE(entry.good()); 196 ASSERT_TRUE(entry.good());
193 197
194 EXPECT_FALSE(entry.ShouldMaintainPosition()); 198 EXPECT_FALSE(entry.ShouldMaintainPosition());
195 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); 199 EXPECT_FALSE(entry.GetUniquePosition().IsValid());
196 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); 200 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid());
197 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); 201 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty());
198 } 202 }
199 203
200 // Test the receipt of a non-bookmark item. 204 // Test the receipt of a non-bookmark item.
201 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { 205 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) {
202 DirectoryTypeDebugInfoEmitter emitter; 206 DirectoryTypeDebugInfoEmitter emitter(AUTOFILL, &type_observers_);
203 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter); 207 DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker(), &emitter);
204 sync_pb::GetUpdatesResponse gu_response; 208 sync_pb::GetUpdatesResponse gu_response;
205 sessions::StatusController status; 209 sessions::StatusController status;
206 210
207 std::string root = syncable::GetNullId().GetServerId(); 211 std::string root = syncable::GetNullId().GetServerId();
208 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); 212 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz");
209 scoped_ptr<sync_pb::SyncEntity> e = 213 scoped_ptr<sync_pb::SyncEntity> e =
210 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); 214 CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL);
211 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); 215 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I=");
212 216
(...skipping 11 matching lines...) Expand all
224 ASSERT_TRUE(entry.good()); 228 ASSERT_TRUE(entry.good());
225 229
226 EXPECT_FALSE(entry.ShouldMaintainPosition()); 230 EXPECT_FALSE(entry.ShouldMaintainPosition());
227 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); 231 EXPECT_FALSE(entry.GetUniquePosition().IsValid());
228 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); 232 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid());
229 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); 233 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty());
230 } 234 }
231 235
232 // Tests the setting of progress markers. 236 // Tests the setting of progress markers.
233 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ProcessNewProgressMarkers) { 237 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ProcessNewProgressMarkers) {
234 DirectoryTypeDebugInfoEmitter emitter; 238 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
235 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter); 239 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker(), &emitter);
236 240
237 sync_pb::DataTypeProgressMarker progress; 241 sync_pb::DataTypeProgressMarker progress;
238 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(BOOKMARKS)); 242 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(BOOKMARKS));
239 progress.set_token("token"); 243 progress.set_token("token");
240 244
241 UpdateProgressMarkers(&handler, progress); 245 UpdateProgressMarkers(&handler, progress);
242 246
243 sync_pb::DataTypeProgressMarker saved; 247 sync_pb::DataTypeProgressMarker saved;
244 dir()->GetDownloadProgress(BOOKMARKS, &saved); 248 dir()->GetDownloadProgress(BOOKMARKS, &saved);
245 249
246 EXPECT_EQ(progress.token(), saved.token()); 250 EXPECT_EQ(progress.token(), saved.token());
247 EXPECT_EQ(progress.data_type_id(), saved.data_type_id()); 251 EXPECT_EQ(progress.data_type_id(), saved.data_type_id());
248 } 252 }
249 253
250 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { 254 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) {
251 DirectoryTypeDebugInfoEmitter emitter; 255 DirectoryTypeDebugInfoEmitter emitter(SYNCED_NOTIFICATIONS, &type_observers_);
252 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, 256 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS,
253 ui_worker(), &emitter); 257 ui_worker(), &emitter);
254 sessions::StatusController status; 258 sessions::StatusController status;
255 259
256 sync_pb::DataTypeProgressMarker progress; 260 sync_pb::DataTypeProgressMarker progress;
257 progress.set_data_type_id( 261 progress.set_data_type_id(
258 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 262 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
259 progress.set_token("token"); 263 progress.set_token("token");
260 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10); 264 progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 10);
261 265
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 EXPECT_EQ(SYNCER_OK, 310 EXPECT_EQ(SYNCER_OK,
307 handler.ProcessGetUpdatesResponse( 311 handler.ProcessGetUpdatesResponse(
308 progress, context, SyncEntityList(), &status)); 312 progress, context, SyncEntityList(), &status));
309 handler.ApplyUpdates(&status); 313 handler.ApplyUpdates(&status);
310 EXPECT_TRUE(EntryExists(type_root->id_string())); 314 EXPECT_TRUE(EntryExists(type_root->id_string()));
311 EXPECT_FALSE(EntryExists(e1->id_string())); 315 EXPECT_FALSE(EntryExists(e1->id_string()));
312 EXPECT_TRUE(EntryExists(e2->id_string())); 316 EXPECT_TRUE(EntryExists(e2->id_string()));
313 } 317 }
314 318
315 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) { 319 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) {
316 DirectoryTypeDebugInfoEmitter emitter; 320 DirectoryTypeDebugInfoEmitter emitter(SYNCED_NOTIFICATIONS, &type_observers_);
317 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, 321 DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS,
318 ui_worker(), &emitter); 322 ui_worker(), &emitter);
319 sessions::StatusController status; 323 sessions::StatusController status;
320 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS); 324 int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS);
321 325
322 sync_pb::DataTypeProgressMarker progress; 326 sync_pb::DataTypeProgressMarker progress;
323 progress.set_data_type_id( 327 progress.set_data_type_id(
324 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); 328 GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS));
325 progress.set_token("token"); 329 progress.set_token("token");
326 330
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // of the time so these tests may end up requiring more infrastructure than the 410 // of the time so these tests may end up requiring more infrastructure than the
407 // update processing tests. Currently, we're bypassing most of those issues by 411 // update processing tests. Currently, we're bypassing most of those issues by
408 // using FakeModelWorkers, so there's not much difference between the two test 412 // using FakeModelWorkers, so there's not much difference between the two test
409 // harnesses. 413 // harnesses.
410 class DirectoryUpdateHandlerApplyUpdateTest : public ::testing::Test { 414 class DirectoryUpdateHandlerApplyUpdateTest : public ::testing::Test {
411 public: 415 public:
412 DirectoryUpdateHandlerApplyUpdateTest() 416 DirectoryUpdateHandlerApplyUpdateTest()
413 : ui_worker_(new FakeModelWorker(GROUP_UI)), 417 : ui_worker_(new FakeModelWorker(GROUP_UI)),
414 password_worker_(new FakeModelWorker(GROUP_PASSWORD)), 418 password_worker_(new FakeModelWorker(GROUP_PASSWORD)),
415 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)), 419 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)),
420 bookmarks_emitter_(BOOKMARKS, &type_observers_),
421 passwords_emitter_(PASSWORDS, &type_observers_),
416 update_handler_map_deleter_(&update_handler_map_) {} 422 update_handler_map_deleter_(&update_handler_map_) {}
417 423
418 virtual void SetUp() OVERRIDE { 424 virtual void SetUp() OVERRIDE {
419 dir_maker_.SetUp(); 425 dir_maker_.SetUp();
420 entry_factory_.reset(new TestEntryFactory(directory())); 426 entry_factory_.reset(new TestEntryFactory(directory()));
421 427
422 update_handler_map_.insert(std::make_pair( 428 update_handler_map_.insert(std::make_pair(
423 BOOKMARKS, 429 BOOKMARKS,
424 new DirectoryUpdateHandler(directory(), BOOKMARKS, 430 new DirectoryUpdateHandler(directory(), BOOKMARKS,
425 ui_worker_, &bookmarks_emitter_))); 431 ui_worker_, &bookmarks_emitter_)));
426 update_handler_map_.insert(std::make_pair( 432 update_handler_map_.insert(std::make_pair(
427 PASSWORDS, 433 PASSWORDS,
428 new DirectoryUpdateHandler(directory(), 434 new DirectoryUpdateHandler(directory(),
429 PASSWORDS, 435 PASSWORDS,
430 password_worker_, 436 password_worker_,
431 &passwords_emitter_))); 437 &passwords_emitter_)));
432 } 438 }
433 439
434 virtual void TearDown() OVERRIDE { 440 virtual void TearDown() OVERRIDE {
435 dir_maker_.TearDown(); 441 dir_maker_.TearDown();
436 } 442 }
437 443
444 const UpdateCounters& GetBookmarksUpdateCounters() {
445 return bookmarks_emitter_.GetUpdateCounters();
446 }
447
448 const UpdateCounters& GetPasswordsUpdateCounters() {
449 return passwords_emitter_.GetUpdateCounters();
450 }
451
438 protected: 452 protected:
439 void ApplyBookmarkUpdates(sessions::StatusController* status) { 453 void ApplyBookmarkUpdates(sessions::StatusController* status) {
440 update_handler_map_[BOOKMARKS]->ApplyUpdates(status); 454 update_handler_map_[BOOKMARKS]->ApplyUpdates(status);
441 } 455 }
442 456
443 void ApplyPasswordUpdates(sessions::StatusController* status) { 457 void ApplyPasswordUpdates(sessions::StatusController* status) {
444 update_handler_map_[PASSWORDS]->ApplyUpdates(status); 458 update_handler_map_[PASSWORDS]->ApplyUpdates(status);
445 } 459 }
446 460
447 TestEntryFactory* entry_factory() { 461 TestEntryFactory* entry_factory() {
448 return entry_factory_.get(); 462 return entry_factory_.get();
449 } 463 }
450 464
451 syncable::Directory* directory() { 465 syncable::Directory* directory() {
452 return dir_maker_.directory(); 466 return dir_maker_.directory();
453 } 467 }
454 468
455 private: 469 private:
456 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; 470 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
457 471
458 base::MessageLoop loop_; // Needed to initialize the directory. 472 base::MessageLoop loop_; // Needed to initialize the directory.
459 TestDirectorySetterUpper dir_maker_; 473 TestDirectorySetterUpper dir_maker_;
460 scoped_ptr<TestEntryFactory> entry_factory_; 474 scoped_ptr<TestEntryFactory> entry_factory_;
461 475
462 scoped_refptr<FakeModelWorker> ui_worker_; 476 scoped_refptr<FakeModelWorker> ui_worker_;
463 scoped_refptr<FakeModelWorker> password_worker_; 477 scoped_refptr<FakeModelWorker> password_worker_;
464 scoped_refptr<FakeModelWorker> passive_worker_; 478 scoped_refptr<FakeModelWorker> passive_worker_;
465 479
480 ObserverList<TypeDebugInfoObserver> type_observers_;
466 DirectoryTypeDebugInfoEmitter bookmarks_emitter_; 481 DirectoryTypeDebugInfoEmitter bookmarks_emitter_;
467 DirectoryTypeDebugInfoEmitter passwords_emitter_; 482 DirectoryTypeDebugInfoEmitter passwords_emitter_;
468 483
469 UpdateHandlerMap update_handler_map_; 484 UpdateHandlerMap update_handler_map_;
470 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; 485 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_;
471 }; 486 };
472 487
473 namespace { 488 namespace {
474 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { 489 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
475 sync_pb::EntitySpecifics result; 490 sync_pb::EntitySpecifics result;
476 AddDefaultFieldValue(BOOKMARKS, &result); 491 AddDefaultFieldValue(BOOKMARKS, &result);
477 return result; 492 return result;
478 } 493 }
479 } // namespace 494 } // namespace
480 495
481 // Test update application for a few bookmark items. 496 // Test update application for a few bookmark items.
482 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) { 497 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) {
483 sessions::StatusController status; 498 sessions::StatusController status;
484 499
485 std::string root_server_id = syncable::GetNullId().GetServerId(); 500 std::string root_server_id = syncable::GetNullId().GetServerId();
486 int64 parent_handle = 501 int64 parent_handle =
487 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 502 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
488 "parent", DefaultBookmarkSpecifics(), root_server_id); 503 "parent", DefaultBookmarkSpecifics(), root_server_id);
489 int64 child_handle = 504 int64 child_handle =
490 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( 505 entry_factory()->CreateUnappliedNewBookmarkItemWithParent(
491 "child", DefaultBookmarkSpecifics(), "parent"); 506 "child", DefaultBookmarkSpecifics(), "parent");
492 507
493 ApplyBookmarkUpdates(&status); 508 ApplyBookmarkUpdates(&status);
494 509
495 EXPECT_EQ(0, status.num_encryption_conflicts()) 510 const UpdateCounters& counter = GetBookmarksUpdateCounters();
511 EXPECT_EQ(0, counter.num_encryption_conflict_application_failures)
496 << "Simple update shouldn't result in conflicts"; 512 << "Simple update shouldn't result in conflicts";
497 EXPECT_EQ(0, status.num_hierarchy_conflicts()) 513 EXPECT_EQ(0, counter.num_hierarchy_conflict_application_failures)
498 << "Simple update shouldn't result in conflicts"; 514 << "Simple update shouldn't result in conflicts";
499 EXPECT_EQ(2, status.num_updates_applied()) 515 EXPECT_EQ(2, counter.num_updates_applied)
500 << "All items should have been successfully applied"; 516 << "All items should have been successfully applied";
501 517
502 { 518 {
503 syncable::ReadTransaction trans(FROM_HERE, directory()); 519 syncable::ReadTransaction trans(FROM_HERE, directory());
504 520
505 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle); 521 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle);
506 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle); 522 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle);
507 523
508 ASSERT_TRUE(parent.good()); 524 ASSERT_TRUE(parent.good());
509 ASSERT_TRUE(child.good()); 525 ASSERT_TRUE(child.good());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 { 597 {
582 syncable::ReadTransaction trans(FROM_HERE, directory()); 598 syncable::ReadTransaction trans(FROM_HERE, directory());
583 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 599 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
584 original_server_version = e.GetServerVersion(); 600 original_server_version = e.GetServerVersion();
585 ASSERT_NE(original_server_version, e.GetBaseVersion()); 601 ASSERT_NE(original_server_version, e.GetBaseVersion());
586 EXPECT_TRUE(e.GetIsUnsynced()); 602 EXPECT_TRUE(e.GetIsUnsynced());
587 } 603 }
588 604
589 sessions::StatusController status; 605 sessions::StatusController status;
590 ApplyBookmarkUpdates(&status); 606 ApplyBookmarkUpdates(&status);
591 EXPECT_EQ(1, status.num_server_overwrites()) 607
608 const UpdateCounters& counters = GetBookmarksUpdateCounters();
609 EXPECT_EQ(1, counters.num_server_overwrites)
592 << "Unsynced and unapplied item conflict should be resolved"; 610 << "Unsynced and unapplied item conflict should be resolved";
593 EXPECT_EQ(0, status.num_updates_applied()) 611 EXPECT_EQ(0, counters.num_updates_applied)
594 << "Update should not be applied; we should override the server."; 612 << "Update should not be applied; we should override the server.";
595 613
596 { 614 {
597 syncable::ReadTransaction trans(FROM_HERE, directory()); 615 syncable::ReadTransaction trans(FROM_HERE, directory());
598 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 616 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
599 ASSERT_TRUE(e.good()); 617 ASSERT_TRUE(e.good());
600 EXPECT_EQ(original_server_version, e.GetServerVersion()); 618 EXPECT_EQ(original_server_version, e.GetServerVersion());
601 EXPECT_EQ(original_server_version, e.GetBaseVersion()); 619 EXPECT_EQ(original_server_version, e.GetBaseVersion());
602 EXPECT_FALSE(e.GetIsUnappliedUpdate()); 620 EXPECT_FALSE(e.GetIsUnappliedUpdate());
603 621
(...skipping 15 matching lines...) Expand all
619 // A bad parent indicates a hierarchy conflict. 637 // A bad parent indicates a hierarchy conflict.
620 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 638 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
621 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); 639 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle);
622 ASSERT_TRUE(entry.good()); 640 ASSERT_TRUE(entry.good());
623 641
624 entry.PutServerParentId(TestIdFactory::MakeServer("bogus_parent")); 642 entry.PutServerParentId(TestIdFactory::MakeServer("bogus_parent"));
625 } 643 }
626 644
627 sessions::StatusController status; 645 sessions::StatusController status;
628 ApplyBookmarkUpdates(&status); 646 ApplyBookmarkUpdates(&status);
629 EXPECT_EQ(0, status.num_updates_applied()); 647
630 EXPECT_EQ(0, status.num_server_overwrites()); 648 const UpdateCounters& counters = GetBookmarksUpdateCounters();
631 EXPECT_EQ(1, status.num_hierarchy_conflicts()); 649 EXPECT_EQ(0, counters.num_updates_applied);
650 EXPECT_EQ(0, counters.num_server_overwrites);
651 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
632 652
633 { 653 {
634 syncable::ReadTransaction trans(FROM_HERE, directory()); 654 syncable::ReadTransaction trans(FROM_HERE, directory());
635 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 655 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
636 ASSERT_TRUE(e.good()); 656 ASSERT_TRUE(e.good());
637 EXPECT_TRUE(e.GetIsUnappliedUpdate()); 657 EXPECT_TRUE(e.GetIsUnappliedUpdate());
638 EXPECT_TRUE(e.GetIsUnsynced()); 658 EXPECT_TRUE(e.GetIsUnsynced());
639 } 659 }
640 } 660 }
641 661
(...skipping 24 matching lines...) Expand all
666 686
667 // If the server's update were applied, we would have X be a child of Y, and Y 687 // If the server's update were applied, we would have X be a child of Y, and Y
668 // as a child of X. That's a directory loop. The UpdateApplicator should 688 // as a child of X. That's a directory loop. The UpdateApplicator should
669 // prevent the update from being applied and note that this is a hierarchy 689 // prevent the update from being applied and note that this is a hierarchy
670 // conflict. 690 // conflict.
671 691
672 sessions::StatusController status; 692 sessions::StatusController status;
673 ApplyBookmarkUpdates(&status); 693 ApplyBookmarkUpdates(&status);
674 694
675 // This should count as a hierarchy conflict. 695 // This should count as a hierarchy conflict.
676 EXPECT_EQ(1, status.num_hierarchy_conflicts()); 696 const UpdateCounters& counters = GetBookmarksUpdateCounters();
697 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
677 698
678 { 699 {
679 syncable::ReadTransaction trans(FROM_HERE, directory()); 700 syncable::ReadTransaction trans(FROM_HERE, directory());
680 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 701 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
681 ASSERT_TRUE(e.good()); 702 ASSERT_TRUE(e.good());
682 EXPECT_TRUE(e.GetIsUnappliedUpdate()); 703 EXPECT_TRUE(e.GetIsUnappliedUpdate());
683 EXPECT_FALSE(e.GetIsUnsynced()); 704 EXPECT_FALSE(e.GetIsUnsynced());
684 } 705 }
685 } 706 }
686 707
(...skipping 17 matching lines...) Expand all
704 // Create an incoming child from the server. 725 // Create an incoming child from the server.
705 int64 child_handle = entry_factory()->CreateUnappliedNewItemWithParent( 726 int64 child_handle = entry_factory()->CreateUnappliedNewItemWithParent(
706 "child", DefaultBookmarkSpecifics(), "parent"); 727 "child", DefaultBookmarkSpecifics(), "parent");
707 728
708 // The server's update may seem valid to some other client, but on this client 729 // The server's update may seem valid to some other client, but on this client
709 // that new item's parent no longer exists. The update should not be applied 730 // that new item's parent no longer exists. The update should not be applied
710 // and the update applicator should indicate this is a hierarchy conflict. 731 // and the update applicator should indicate this is a hierarchy conflict.
711 732
712 sessions::StatusController status; 733 sessions::StatusController status;
713 ApplyBookmarkUpdates(&status); 734 ApplyBookmarkUpdates(&status);
714 EXPECT_EQ(1, status.num_hierarchy_conflicts()); 735 const UpdateCounters& counters = GetBookmarksUpdateCounters();
736 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
715 737
716 { 738 {
717 syncable::ReadTransaction trans(FROM_HERE, directory()); 739 syncable::ReadTransaction trans(FROM_HERE, directory());
718 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle); 740 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle);
719 ASSERT_TRUE(child.good()); 741 ASSERT_TRUE(child.good());
720 EXPECT_TRUE(child.GetIsUnappliedUpdate()); 742 EXPECT_TRUE(child.GetIsUnappliedUpdate());
721 EXPECT_FALSE(child.GetIsUnsynced()); 743 EXPECT_FALSE(child.GetIsUnsynced());
722 } 744 }
723 } 745 }
724 746
(...skipping 23 matching lines...) Expand all
748 TestIdFactory::MakeServer("child"), TestIdFactory::MakeServer("parent"), 770 TestIdFactory::MakeServer("child"), TestIdFactory::MakeServer("parent"),
749 "child", false, BOOKMARKS, NULL); 771 "child", false, BOOKMARKS, NULL);
750 772
751 // The server's request to delete the directory must be ignored, otherwise our 773 // The server's request to delete the directory must be ignored, otherwise our
752 // unsynced new child would be orphaned. This is a hierarchy conflict. 774 // unsynced new child would be orphaned. This is a hierarchy conflict.
753 775
754 sessions::StatusController status; 776 sessions::StatusController status;
755 ApplyBookmarkUpdates(&status); 777 ApplyBookmarkUpdates(&status);
756 778
757 // This should count as a hierarchy conflict. 779 // This should count as a hierarchy conflict.
758 EXPECT_EQ(1, status.num_hierarchy_conflicts()); 780 const UpdateCounters& counters = GetBookmarksUpdateCounters();
781 EXPECT_EQ(1, counters.num_hierarchy_conflict_application_failures);
759 782
760 { 783 {
761 syncable::ReadTransaction trans(FROM_HERE, directory()); 784 syncable::ReadTransaction trans(FROM_HERE, directory());
762 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle); 785 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle);
763 ASSERT_TRUE(parent.good()); 786 ASSERT_TRUE(parent.good());
764 EXPECT_TRUE(parent.GetIsUnappliedUpdate()); 787 EXPECT_TRUE(parent.GetIsUnappliedUpdate());
765 EXPECT_FALSE(parent.GetIsUnsynced()); 788 EXPECT_FALSE(parent.GetIsUnsynced());
766 } 789 }
767 } 790 }
768 791
769 // Attempt to apply updates where the updated item's parent is not known to this 792 // Attempt to apply updates where the updated item's parent is not known to this
770 // client. The update application attempt should fail. 793 // client. The update application attempt should fail.
771 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, 794 TEST_F(DirectoryUpdateHandlerApplyUpdateTest,
772 HierarchyConflictUnknownParent) { 795 HierarchyConflictUnknownParent) {
773 // We shouldn't be able to do anything with either of these items. 796 // We shouldn't be able to do anything with either of these items.
774 int64 x_handle = entry_factory()->CreateUnappliedNewItemWithParent( 797 int64 x_handle = entry_factory()->CreateUnappliedNewItemWithParent(
775 "some_item", DefaultBookmarkSpecifics(), "unknown_parent"); 798 "some_item", DefaultBookmarkSpecifics(), "unknown_parent");
776 int64 y_handle = entry_factory()->CreateUnappliedNewItemWithParent( 799 int64 y_handle = entry_factory()->CreateUnappliedNewItemWithParent(
777 "some_other_item", DefaultBookmarkSpecifics(), "some_item"); 800 "some_other_item", DefaultBookmarkSpecifics(), "some_item");
778 801
779 sessions::StatusController status; 802 sessions::StatusController status;
780 ApplyBookmarkUpdates(&status); 803 ApplyBookmarkUpdates(&status);
781 804
782 EXPECT_EQ(2, status.num_hierarchy_conflicts()) 805 const UpdateCounters& counters = GetBookmarksUpdateCounters();
806 EXPECT_EQ(2, counters.num_hierarchy_conflict_application_failures)
783 << "All updates with an unknown ancestors should be in conflict"; 807 << "All updates with an unknown ancestors should be in conflict";
784 EXPECT_EQ(0, status.num_updates_applied()) 808 EXPECT_EQ(0, counters.num_updates_applied)
785 << "No item with an unknown ancestor should be applied"; 809 << "No item with an unknown ancestor should be applied";
786 810
787 { 811 {
788 syncable::ReadTransaction trans(FROM_HERE, directory()); 812 syncable::ReadTransaction trans(FROM_HERE, directory());
789 syncable::Entry x(&trans, syncable::GET_BY_HANDLE, x_handle); 813 syncable::Entry x(&trans, syncable::GET_BY_HANDLE, x_handle);
790 syncable::Entry y(&trans, syncable::GET_BY_HANDLE, y_handle); 814 syncable::Entry y(&trans, syncable::GET_BY_HANDLE, y_handle);
791 ASSERT_TRUE(x.good()); 815 ASSERT_TRUE(x.good());
792 ASSERT_TRUE(y.good()); 816 ASSERT_TRUE(y.good());
793 EXPECT_TRUE(x.GetIsUnappliedUpdate()); 817 EXPECT_TRUE(x.GetIsUnappliedUpdate());
794 EXPECT_TRUE(y.GetIsUnappliedUpdate()); 818 EXPECT_TRUE(y.GetIsUnappliedUpdate());
(...skipping 16 matching lines...) Expand all
811 int64 k2_handle = entry_factory()->CreateUnappliedNewItemWithParent( 835 int64 k2_handle = entry_factory()->CreateUnappliedNewItemWithParent(
812 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); 836 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item");
813 int64 k3_handle = entry_factory()->CreateUnappliedNewItemWithParent( 837 int64 k3_handle = entry_factory()->CreateUnappliedNewItemWithParent(
814 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item"); 838 "third_known_item", DefaultBookmarkSpecifics(), "fourth_known_item");
815 int64 k4_handle = entry_factory()->CreateUnappliedNewItemWithParent( 839 int64 k4_handle = entry_factory()->CreateUnappliedNewItemWithParent(
816 "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id); 840 "fourth_known_item", DefaultBookmarkSpecifics(), root_server_id);
817 841
818 sessions::StatusController status; 842 sessions::StatusController status;
819 ApplyBookmarkUpdates(&status); 843 ApplyBookmarkUpdates(&status);
820 844
821 EXPECT_EQ(2, status.num_hierarchy_conflicts()) 845 const UpdateCounters& counters = GetBookmarksUpdateCounters();
846 EXPECT_EQ(2, counters.num_hierarchy_conflict_application_failures)
822 << "The updates with unknown ancestors should be in conflict"; 847 << "The updates with unknown ancestors should be in conflict";
823 EXPECT_EQ(4, status.num_updates_applied()) 848 EXPECT_EQ(4, counters.num_updates_applied)
824 << "The updates with known ancestors should be successfully applied"; 849 << "The updates with known ancestors should be successfully applied";
825 850
826 { 851 {
827 syncable::ReadTransaction trans(FROM_HERE, directory()); 852 syncable::ReadTransaction trans(FROM_HERE, directory());
828 syncable::Entry u1(&trans, syncable::GET_BY_HANDLE, u1_handle); 853 syncable::Entry u1(&trans, syncable::GET_BY_HANDLE, u1_handle);
829 syncable::Entry u2(&trans, syncable::GET_BY_HANDLE, u2_handle); 854 syncable::Entry u2(&trans, syncable::GET_BY_HANDLE, u2_handle);
830 syncable::Entry k1(&trans, syncable::GET_BY_HANDLE, k1_handle); 855 syncable::Entry k1(&trans, syncable::GET_BY_HANDLE, k1_handle);
831 syncable::Entry k2(&trans, syncable::GET_BY_HANDLE, k2_handle); 856 syncable::Entry k2(&trans, syncable::GET_BY_HANDLE, k2_handle);
832 syncable::Entry k3(&trans, syncable::GET_BY_HANDLE, k3_handle); 857 syncable::Entry k3(&trans, syncable::GET_BY_HANDLE, k3_handle);
833 syncable::Entry k4(&trans, syncable::GET_BY_HANDLE, k4_handle); 858 syncable::Entry k4(&trans, syncable::GET_BY_HANDLE, k4_handle);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 data.set_origin("http://example.com"); 890 data.set_origin("http://example.com");
866 891
867 cryptographer->Encrypt(data, 892 cryptographer->Encrypt(data,
868 specifics.mutable_password()->mutable_encrypted()); 893 specifics.mutable_password()->mutable_encrypted());
869 int64 handle = 894 int64 handle =
870 entry_factory()->CreateUnappliedNewItem("item", specifics, false); 895 entry_factory()->CreateUnappliedNewItem("item", specifics, false);
871 896
872 sessions::StatusController status; 897 sessions::StatusController status;
873 ApplyPasswordUpdates(&status); 898 ApplyPasswordUpdates(&status);
874 899
875 EXPECT_EQ(1, status.num_updates_applied()) 900 const UpdateCounters& counters = GetPasswordsUpdateCounters();
901 EXPECT_EQ(1, counters.num_updates_applied)
876 << "The updates that can be decrypted should be applied"; 902 << "The updates that can be decrypted should be applied";
877 903
878 { 904 {
879 syncable::ReadTransaction trans(FROM_HERE, directory()); 905 syncable::ReadTransaction trans(FROM_HERE, directory());
880 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); 906 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle);
881 ASSERT_TRUE(e.good()); 907 ASSERT_TRUE(e.good());
882 EXPECT_FALSE(e.GetIsUnappliedUpdate()); 908 EXPECT_FALSE(e.GetIsUnappliedUpdate());
883 EXPECT_FALSE(e.GetIsUnsynced()); 909 EXPECT_FALSE(e.GetIsUnsynced());
884 } 910 }
885 } 911 }
(...skipping 17 matching lines...) Expand all
903 encrypted_password.mutable_password(); 929 encrypted_password.mutable_password();
904 int64 password_handle = entry_factory()->CreateUnappliedNewItem( 930 int64 password_handle = entry_factory()->CreateUnappliedNewItem(
905 "item3", 931 "item3",
906 encrypted_password, 932 encrypted_password,
907 false); 933 false);
908 934
909 sessions::StatusController status; 935 sessions::StatusController status;
910 ApplyBookmarkUpdates(&status); 936 ApplyBookmarkUpdates(&status);
911 ApplyPasswordUpdates(&status); 937 ApplyPasswordUpdates(&status);
912 938
913 EXPECT_EQ(3, status.num_encryption_conflicts()) 939 const UpdateCounters& bm_counters = GetBookmarksUpdateCounters();
940 EXPECT_EQ(2, bm_counters.num_encryption_conflict_application_failures)
914 << "Updates that can't be decrypted should be in encryption conflict"; 941 << "Updates that can't be decrypted should be in encryption conflict";
915 EXPECT_EQ(0, status.num_updates_applied()) 942 EXPECT_EQ(0, bm_counters.num_updates_applied)
943 << "No update that can't be decrypted should be applied";
944
945 const UpdateCounters& pw_counters = GetPasswordsUpdateCounters();
946 EXPECT_EQ(1, pw_counters.num_encryption_conflict_application_failures)
947 << "Updates that can't be decrypted should be in encryption conflict";
948 EXPECT_EQ(0, pw_counters.num_updates_applied)
916 << "No update that can't be decrypted should be applied"; 949 << "No update that can't be decrypted should be applied";
917 950
918 { 951 {
919 syncable::ReadTransaction trans(FROM_HERE, directory()); 952 syncable::ReadTransaction trans(FROM_HERE, directory());
920 syncable::Entry folder(&trans, syncable::GET_BY_HANDLE, folder_handle); 953 syncable::Entry folder(&trans, syncable::GET_BY_HANDLE, folder_handle);
921 syncable::Entry bm(&trans, syncable::GET_BY_HANDLE, bookmark_handle); 954 syncable::Entry bm(&trans, syncable::GET_BY_HANDLE, bookmark_handle);
922 syncable::Entry pw(&trans, syncable::GET_BY_HANDLE, password_handle); 955 syncable::Entry pw(&trans, syncable::GET_BY_HANDLE, password_handle);
923 ASSERT_TRUE(folder.good()); 956 ASSERT_TRUE(folder.good());
924 ASSERT_TRUE(bm.good()); 957 ASSERT_TRUE(bm.good());
925 ASSERT_TRUE(pw.good()); 958 ASSERT_TRUE(pw.good());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 999
967 other_cryptographer.Encrypt(data, 1000 other_cryptographer.Encrypt(data,
968 specifics.mutable_password()->mutable_encrypted()); 1001 specifics.mutable_password()->mutable_encrypted());
969 undecryptable_handle = 1002 undecryptable_handle =
970 entry_factory()->CreateUnappliedNewItem("item2", specifics, false); 1003 entry_factory()->CreateUnappliedNewItem("item2", specifics, false);
971 } 1004 }
972 1005
973 sessions::StatusController status; 1006 sessions::StatusController status;
974 ApplyPasswordUpdates(&status); 1007 ApplyPasswordUpdates(&status);
975 1008
976 EXPECT_EQ(1, status.num_encryption_conflicts()) 1009 const UpdateCounters& counters = GetPasswordsUpdateCounters();
1010 EXPECT_EQ(1, counters.num_encryption_conflict_application_failures)
977 << "The updates that can't be decrypted should be in encryption " 1011 << "The updates that can't be decrypted should be in encryption "
978 << "conflict"; 1012 << "conflict";
979 EXPECT_EQ(1, status.num_updates_applied()) 1013 EXPECT_EQ(1, counters.num_updates_applied)
980 << "The undecryptable password update shouldn't be applied"; 1014 << "The undecryptable password update shouldn't be applied";
981 1015
982 { 1016 {
983 syncable::ReadTransaction trans(FROM_HERE, directory()); 1017 syncable::ReadTransaction trans(FROM_HERE, directory());
984 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); 1018 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle);
985 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); 1019 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle);
986 ASSERT_TRUE(e1.good()); 1020 ASSERT_TRUE(e1.good());
987 ASSERT_TRUE(e2.good()); 1021 ASSERT_TRUE(e2.good());
988 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); 1022 EXPECT_FALSE(e1.GetIsUnappliedUpdate());
989 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); 1023 EXPECT_TRUE(e2.GetIsUnappliedUpdate());
990 } 1024 }
991 } 1025 }
992 1026
993 } // namespace syncer 1027 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698