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

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

Issue 9699057: [Sync] Move 'sync' target to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Tim's comments Created 8 years, 9 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/syncable/syncable_mock.cc ('k') | sync/syncable/transaction_observer.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 "chrome/browser/sync/syncable/syncable.h" 5 #include "sync/syncable/syncable.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/scoped_temp_dir.h" 16 #include "base/scoped_temp_dir.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/synchronization/condition_variable.h" 18 #include "base/synchronization/condition_variable.h"
19 #include "base/test/values_test_util.h" 19 #include "base/test/values_test_util.h"
20 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/sync/engine/syncproto.h" 22 #include "sync/engine/syncproto.h"
23 #include "chrome/browser/sync/internal_api/includes/test_unrecoverable_error_han dler.h" 23 #include "sync/util/test_unrecoverable_error_handler.h"
24 #include "chrome/browser/sync/syncable/directory_backing_store.h" 24 #include "sync/syncable/directory_backing_store.h"
25 #include "chrome/browser/sync/syncable/directory_change_delegate.h" 25 #include "sync/syncable/directory_change_delegate.h"
26 #include "chrome/browser/sync/syncable/on_disk_directory_backing_store.h" 26 #include "sync/syncable/on_disk_directory_backing_store.h"
27 #include "chrome/browser/sync/test/engine/test_id_factory.h" 27 #include "sync/test/engine/test_id_factory.h"
28 #include "chrome/browser/sync/test/engine/test_syncable_utils.h" 28 #include "sync/test/engine/test_syncable_utils.h"
29 #include "chrome/browser/sync/test/fake_encryptor.h" 29 #include "sync/test/fake_encryptor.h"
30 #include "chrome/browser/sync/test/null_directory_change_delegate.h" 30 #include "sync/test/null_directory_change_delegate.h"
31 #include "chrome/browser/sync/test/null_transaction_observer.h" 31 #include "sync/test/null_transaction_observer.h"
32 #include "sync/protocol/bookmark_specifics.pb.h" 32 #include "sync/protocol/bookmark_specifics.pb.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/sqlite/sqlite3.h"
35 34
36 using base::ExpectDictBooleanValue; 35 using base::ExpectDictBooleanValue;
37 using base::ExpectDictStringValue; 36 using base::ExpectDictStringValue;
38 using browser_sync::FakeEncryptor; 37 using browser_sync::FakeEncryptor;
39 using browser_sync::TestIdFactory; 38 using browser_sync::TestIdFactory;
40 using browser_sync::TestUnrecoverableErrorHandler; 39 using browser_sync::TestUnrecoverableErrorHandler;
41 40
42 namespace syncable { 41 namespace syncable {
43 42
44 class SyncableKernelTest : public testing::Test {}; 43 class SyncableKernelTest : public testing::Test {};
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 FakeEncryptor encryptor_; 412 FakeEncryptor encryptor_;
414 TestUnrecoverableErrorHandler handler_; 413 TestUnrecoverableErrorHandler handler_;
415 }; 414 };
416 415
417 // A test fixture for syncable::Directory. Uses an in-memory database to keep 416 // A test fixture for syncable::Directory. Uses an in-memory database to keep
418 // the unit tests fast. 417 // the unit tests fast.
419 class SyncableDirectoryTest : public testing::Test { 418 class SyncableDirectoryTest : public testing::Test {
420 protected: 419 protected:
421 MessageLoop message_loop_; 420 MessageLoop message_loop_;
422 static const char kName[]; 421 static const char kName[];
423 static const Id kId;
424 422
425 virtual void SetUp() { 423 virtual void SetUp() {
426 dir_.reset(new Directory(&encryptor_, &handler_, NULL)); 424 dir_.reset(new Directory(&encryptor_, &handler_, NULL));
427 ASSERT_TRUE(dir_.get()); 425 ASSERT_TRUE(dir_.get());
428 ASSERT_EQ(OPENED, dir_->OpenInMemoryForTest(kName, &delegate_, 426 ASSERT_EQ(OPENED, dir_->OpenInMemoryForTest(kName, &delegate_,
429 NullTransactionObserver())); 427 NullTransactionObserver()));
430 ASSERT_TRUE(dir_->good()); 428 ASSERT_TRUE(dir_->good());
431 } 429 }
432 430
433 virtual void TearDown() { 431 virtual void TearDown() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 477 }
480 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS)); 478 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS));
481 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); 479 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS));
482 } 480 }
483 481
484 FakeEncryptor encryptor_; 482 FakeEncryptor encryptor_;
485 TestUnrecoverableErrorHandler handler_; 483 TestUnrecoverableErrorHandler handler_;
486 scoped_ptr<Directory> dir_; 484 scoped_ptr<Directory> dir_;
487 NullDirectoryChangeDelegate delegate_; 485 NullDirectoryChangeDelegate delegate_;
488 486
489 // Creates an empty entry and sets the ID field to the default kId. 487 // Creates an empty entry and sets the ID field to a default one.
490 void CreateEntry(const std::string& entryname) { 488 void CreateEntry(const std::string& entryname) {
491 CreateEntry(entryname, kId); 489 CreateEntry(entryname, TestIdFactory::FromNumber(-99));
492 } 490 }
493 491
494 // Creates an empty entry and sets the ID field to id. 492 // Creates an empty entry and sets the ID field to id.
495 void CreateEntry(const std::string& entryname, const int id) { 493 void CreateEntry(const std::string& entryname, const int id) {
496 CreateEntry(entryname, TestIdFactory::FromNumber(id)); 494 CreateEntry(entryname, TestIdFactory::FromNumber(id));
497 } 495 }
498 void CreateEntry(const std::string& entryname, Id id) { 496 void CreateEntry(const std::string& entryname, Id id) {
499 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); 497 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get());
500 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname); 498 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname);
501 ASSERT_TRUE(me.good()); 499 ASSERT_TRUE(me.good());
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 EXPECT_EQ(number_changed, snapshot.dirty_metas.size()); 695 EXPECT_EQ(number_changed, snapshot.dirty_metas.size());
698 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); 696 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin();
699 i != snapshot.dirty_metas.end(); ++i) { 697 i != snapshot.dirty_metas.end(); ++i) {
700 EXPECT_TRUE(i->is_dirty()); 698 EXPECT_TRUE(i->is_dirty());
701 } 699 }
702 dir_->VacuumAfterSaveChanges(snapshot); 700 dir_->VacuumAfterSaveChanges(snapshot);
703 } 701 }
704 } 702 }
705 703
706 const char SyncableDirectoryTest::kName[] = "Foo"; 704 const char SyncableDirectoryTest::kName[] = "Foo";
707 const Id SyncableDirectoryTest::kId(TestIdFactory::FromNumber(-99));
708 705
709 namespace { 706 namespace {
707
710 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) { 708 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) {
711 ReadTransaction rtrans(FROM_HERE, dir_.get()); 709 ReadTransaction rtrans(FROM_HERE, dir_.get());
712 Entry e(&rtrans, GET_BY_ID, kId); 710 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99));
713 ASSERT_FALSE(e.good()); 711 ASSERT_FALSE(e.good());
714 } 712 }
715 713
716 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { 714 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) {
717 CreateEntry("rtc"); 715 CreateEntry("rtc");
718 ReadTransaction rtrans(FROM_HERE, dir_.get()); 716 ReadTransaction rtrans(FROM_HERE, dir_.get());
719 Entry e(&rtrans, GET_BY_ID, kId); 717 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99));
720 ASSERT_TRUE(e.good()); 718 ASSERT_TRUE(e.good());
721 } 719 }
722 720
723 TEST_F(SyncableDirectoryTest, TestDelete) { 721 TEST_F(SyncableDirectoryTest, TestDelete) {
724 std::string name = "peanut butter jelly time"; 722 std::string name = "peanut butter jelly time";
725 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 723 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
726 MutableEntry e1(&trans, CREATE, trans.root_id(), name); 724 MutableEntry e1(&trans, CREATE, trans.root_id(), name);
727 ASSERT_TRUE(e1.good()); 725 ASSERT_TRUE(e1.good());
728 ASSERT_TRUE(e1.Put(IS_DEL, true)); 726 ASSERT_TRUE(e1.Put(IS_DEL, true));
729 MutableEntry e2(&trans, CREATE, trans.root_id(), name); 727 MutableEntry e2(&trans, CREATE, trans.root_id(), name);
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1732 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1735 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1733 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1736 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1734 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1737 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1735 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1738 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1736 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1739 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1737 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1740 } 1738 }
1741 1739
1742 } // namespace 1740 } // namespace
1743 } // namespace syncable 1741 } // namespace syncable
OLDNEW
« no previous file with comments | « sync/syncable/syncable_mock.cc ('k') | sync/syncable/transaction_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698