Chromium Code Reviews

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 2854018: sync: Add method to Directory to remove all entries for a set of ModelTypes.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix sign issue with last-minute DCHECK I threw in Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/syncable/syncable.cc ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/sync/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
(...skipping 268 matching lines...)
279 ASSERT_TRUE(dir_->good()); 279 ASSERT_TRUE(dir_->good());
280 } 280 }
281 281
282 virtual void TearDown() { 282 virtual void TearDown() {
283 // This also closes file handles. 283 // This also closes file handles.
284 dir_->SaveChanges(); 284 dir_->SaveChanges();
285 dir_.reset(); 285 dir_.reset();
286 file_util::Delete(file_path_, true); 286 file_util::Delete(file_path_, true);
287 } 287 }
288 288
289 void SaveAndReloadDir() { 289 void ReloadDir() {
290 dir_->SaveChanges();
291 dir_.reset(new Directory()); 290 dir_.reset(new Directory());
292 ASSERT_TRUE(dir_.get()); 291 ASSERT_TRUE(dir_.get());
293 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName)); 292 ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName));
294 } 293 }
295 294
295 void SaveAndReloadDir() {
296 dir_->SaveChanges();
297 ReloadDir();
298 }
299
296 bool IsInDirtyMetahandles(int64 metahandle) { 300 bool IsInDirtyMetahandles(int64 metahandle) {
297 return 1 == dir_->kernel_->dirty_metahandles->count(metahandle); 301 return 1 == dir_->kernel_->dirty_metahandles->count(metahandle);
298 } 302 }
299 303
300 scoped_ptr<Directory> dir_; 304 scoped_ptr<Directory> dir_;
301 FilePath file_path_; 305 FilePath file_path_;
302 306
303 // Creates an empty entry and sets the ID field to the default kId. 307 // Creates an empty entry and sets the ID field to the default kId.
304 void CreateEntry(const string& entryname) { 308 void CreateEntry(const string& entryname) {
305 CreateEntry(entryname, kId); 309 CreateEntry(entryname, kId);
(...skipping 71 matching lines...)
377 // entries are marked dirty. 381 // entries are marked dirty.
378 EXPECT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); 382 EXPECT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size());
379 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin(); 383 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin();
380 i != snapshot.dirty_metas.end(); ++i) { 384 i != snapshot.dirty_metas.end(); ++i) {
381 EXPECT_TRUE(i->is_dirty()); 385 EXPECT_TRUE(i->is_dirty());
382 } 386 }
383 dir_->VacuumAfterSaveChanges(snapshot); 387 dir_->VacuumAfterSaveChanges(snapshot);
384 } 388 }
385 } 389 }
386 390
391 TEST_F(SyncableDirectoryTest, TestPurgeEntriesWithTypeIn) {
392 sync_pb::EntitySpecifics bookmark_specs;
393 sync_pb::EntitySpecifics autofill_specs;
394 sync_pb::EntitySpecifics preference_specs;
395 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs);
396 AddDefaultExtensionValue(PREFERENCES, &preference_specs);
397 AddDefaultExtensionValue(AUTOFILL, &autofill_specs);
398
399 std::set<ModelType> types_to_purge;
400 types_to_purge.insert(PREFERENCES);
401 types_to_purge.insert(AUTOFILL);
402
403 TestIdFactory id_factory;
404 // Create some items for each type.
405 {
406 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__);
407 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item");
408 ASSERT_TRUE(item1.good());
409 item1.Put(SPECIFICS, bookmark_specs);
410 item1.Put(SERVER_SPECIFICS, bookmark_specs);
411 item1.Put(IS_UNSYNCED, true);
412
413 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM,
414 id_factory.NewServerId());
415 ASSERT_TRUE(item2.good());
416 item2.Put(SERVER_SPECIFICS, bookmark_specs);
417 item2.Put(IS_UNAPPLIED_UPDATE, true);
418
419 MutableEntry item3(&trans, CREATE, trans.root_id(), "Item");
420 ASSERT_TRUE(item3.good());
421 item3.Put(SPECIFICS, preference_specs);
422 item3.Put(SERVER_SPECIFICS, preference_specs);
423 item3.Put(IS_UNSYNCED, true);
424
425 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM,
426 id_factory.NewServerId());
427 ASSERT_TRUE(item4.good());
428 item4.Put(SERVER_SPECIFICS, preference_specs);
429 item4.Put(IS_UNAPPLIED_UPDATE, true);
430
431 MutableEntry item5(&trans, CREATE, trans.root_id(), "Item");
432 ASSERT_TRUE(item5.good());
433 item5.Put(SPECIFICS, autofill_specs);
434 item5.Put(SERVER_SPECIFICS, autofill_specs);
435 item5.Put(IS_UNSYNCED, true);
436
437 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM,
438 id_factory.NewServerId());
439 ASSERT_TRUE(item6.good());
440 item6.Put(SERVER_SPECIFICS, autofill_specs);
441 item6.Put(IS_UNAPPLIED_UPDATE, true);
442 }
443
444 dir_->SaveChanges();
445 {
446 ReadTransaction trans(dir_.get(), __FILE__, __LINE__);
447 MetahandleSet all_set;
448 dir_->GetAllMetaHandles(&trans, &all_set);
449 ASSERT_EQ(7U, all_set.size());
450 }
451
452 dir_->PurgeEntriesWithTypeIn(types_to_purge);
453
454 // We first query the in-memory data, and then reload the directory (without
455 // saving) to verify that disk does not still have the data.
456 int test_scan_run = 0;
457 do {
458 string message = "Testing ";
459 message += test_scan_run == 0 ? "before " : "after ";
460 message += "directory reload.";
461 SCOPED_TRACE(testing::Message(message.c_str()));
462 {
463 ReadTransaction trans(dir_.get(), __FILE__, __LINE__);
464 MetahandleSet all_set;
465 dir_->GetAllMetaHandles(&trans, &all_set);
466 EXPECT_EQ(3U, all_set.size());
467 for (MetahandleSet::iterator iter = all_set.begin();
468 iter != all_set.end(); ++iter) {
469 Entry e(&trans, GET_BY_HANDLE, *iter);
470 if (types_to_purge.count(e.GetModelType()) ||
471 types_to_purge.count(e.GetServerModelType())) {
472 FAIL() << "Illegal type should have been deleted.";
473 }
474 }
475 }
476 if (test_scan_run == 0)
477 ReloadDir();
478 test_scan_run++;
479 } while (test_scan_run < 2);
480 }
481
387 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { 482 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) {
388 const int metahandles_to_create = 100; 483 const int metahandles_to_create = 100;
389 const unsigned int number_changed = 100u; // half of 2 * metahandles_to_creat e 484
485 // half of 2 * metahandles_to_create
486 const unsigned int number_changed = 100u;
390 std::vector<int64> expected_dirty_metahandles; 487 std::vector<int64> expected_dirty_metahandles;
391 { 488 {
392 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); 489 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__);
393 for (int i = 0; i < metahandles_to_create; i++) { 490 for (int i = 0; i < metahandles_to_create; i++) {
394 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); 491 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
395 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); 492 expected_dirty_metahandles.push_back(e.Get(META_HANDLE));
396 e.Put(IS_UNSYNCED, true); 493 e.Put(IS_UNSYNCED, true);
397 } 494 }
398 } 495 }
399 dir_->SaveChanges(); 496 dir_->SaveChanges();
(...skipping 1172 matching lines...)
1572 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1669 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1573 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1670 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1574 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1671 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1575 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1672 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1576 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1673 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1577 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1674 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1578 } 1675 }
1579 1676
1580 } // namespace 1677 } // namespace
1581 } // namespace syncable 1678 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine