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

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

Issue 12217101: Replace FilePath with base::FilePath in some more top level directories. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/on_disk_directory_backing_store.cc ('k') | sync/test/local_sync_test_server.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 virtual void TearDown() { 98 virtual void TearDown() {
99 } 99 }
100 protected: 100 protected:
101 MessageLoop message_loop_; 101 MessageLoop message_loop_;
102 base::ScopedTempDir temp_dir_; 102 base::ScopedTempDir temp_dir_;
103 NullDirectoryChangeDelegate delegate_; 103 NullDirectoryChangeDelegate delegate_;
104 FakeEncryptor encryptor_; 104 FakeEncryptor encryptor_;
105 TestUnrecoverableErrorHandler handler_; 105 TestUnrecoverableErrorHandler handler_;
106 FilePath db_path_; 106 base::FilePath db_path_;
107 }; 107 };
108 108
109 const char SyncableGeneralTest::kIndexTestName[] = "IndexTest"; 109 const char SyncableGeneralTest::kIndexTestName[] = "IndexTest";
110 110
111 TEST_F(SyncableGeneralTest, General) { 111 TEST_F(SyncableGeneralTest, General) {
112 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"), 112 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"),
113 &handler_, 113 &handler_,
114 NULL, 114 NULL,
115 NULL, 115 NULL,
116 NULL); 116 NULL);
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 EXPECT_TRUE( 1526 EXPECT_TRUE(
1527 null_ord.Equals(null_ordinal_child.Get(SERVER_ORDINAL_IN_PARENT))); 1527 null_ord.Equals(null_ordinal_child.Get(SERVER_ORDINAL_IN_PARENT)));
1528 } 1528 }
1529 1529
1530 } 1530 }
1531 1531
1532 // An OnDirectoryBackingStore that can be set to always fail SaveChanges. 1532 // An OnDirectoryBackingStore that can be set to always fail SaveChanges.
1533 class TestBackingStore : public OnDiskDirectoryBackingStore { 1533 class TestBackingStore : public OnDiskDirectoryBackingStore {
1534 public: 1534 public:
1535 TestBackingStore(const std::string& dir_name, 1535 TestBackingStore(const std::string& dir_name,
1536 const FilePath& backing_filepath); 1536 const base::FilePath& backing_filepath);
1537 1537
1538 virtual ~TestBackingStore(); 1538 virtual ~TestBackingStore();
1539 1539
1540 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) 1540 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot)
1541 OVERRIDE; 1541 OVERRIDE;
1542 1542
1543 void StartFailingSaveChanges() { 1543 void StartFailingSaveChanges() {
1544 fail_save_changes_ = true; 1544 fail_save_changes_ = true;
1545 } 1545 }
1546 1546
1547 private: 1547 private:
1548 bool fail_save_changes_; 1548 bool fail_save_changes_;
1549 }; 1549 };
1550 1550
1551 TestBackingStore::TestBackingStore(const std::string& dir_name, 1551 TestBackingStore::TestBackingStore(const std::string& dir_name,
1552 const FilePath& backing_filepath) 1552 const base::FilePath& backing_filepath)
1553 : OnDiskDirectoryBackingStore(dir_name, backing_filepath), 1553 : OnDiskDirectoryBackingStore(dir_name, backing_filepath),
1554 fail_save_changes_(false) { 1554 fail_save_changes_(false) {
1555 } 1555 }
1556 1556
1557 TestBackingStore::~TestBackingStore() { } 1557 TestBackingStore::~TestBackingStore() { }
1558 1558
1559 bool TestBackingStore::SaveChanges( 1559 bool TestBackingStore::SaveChanges(
1560 const Directory::SaveChangesSnapshot& snapshot){ 1560 const Directory::SaveChangesSnapshot& snapshot){
1561 if (fail_save_changes_) { 1561 if (fail_save_changes_) {
1562 return false; 1562 return false;
1563 } else { 1563 } else {
1564 return OnDiskDirectoryBackingStore::SaveChanges(snapshot); 1564 return OnDiskDirectoryBackingStore::SaveChanges(snapshot);
1565 } 1565 }
1566 } 1566 }
1567 1567
1568 // A directory whose Save() function can be set to always fail. 1568 // A directory whose Save() function can be set to always fail.
1569 class TestDirectory : public Directory { 1569 class TestDirectory : public Directory {
1570 public: 1570 public:
1571 // A factory function used to work around some initialization order issues. 1571 // A factory function used to work around some initialization order issues.
1572 static TestDirectory* Create( 1572 static TestDirectory* Create(
1573 Encryptor *encryptor, 1573 Encryptor *encryptor,
1574 UnrecoverableErrorHandler *handler, 1574 UnrecoverableErrorHandler *handler,
1575 const std::string& dir_name, 1575 const std::string& dir_name,
1576 const FilePath& backing_filepath); 1576 const base::FilePath& backing_filepath);
1577 1577
1578 virtual ~TestDirectory(); 1578 virtual ~TestDirectory();
1579 1579
1580 void StartFailingSaveChanges() { 1580 void StartFailingSaveChanges() {
1581 backing_store_->StartFailingSaveChanges(); 1581 backing_store_->StartFailingSaveChanges();
1582 } 1582 }
1583 1583
1584 private: 1584 private:
1585 TestDirectory(Encryptor* encryptor, 1585 TestDirectory(Encryptor* encryptor,
1586 UnrecoverableErrorHandler* handler, 1586 UnrecoverableErrorHandler* handler,
1587 TestBackingStore* backing_store); 1587 TestBackingStore* backing_store);
1588 1588
1589 TestBackingStore* backing_store_; 1589 TestBackingStore* backing_store_;
1590 }; 1590 };
1591 1591
1592 TestDirectory* TestDirectory::Create( 1592 TestDirectory* TestDirectory::Create(
1593 Encryptor *encryptor, 1593 Encryptor *encryptor,
1594 UnrecoverableErrorHandler *handler, 1594 UnrecoverableErrorHandler *handler,
1595 const std::string& dir_name, 1595 const std::string& dir_name,
1596 const FilePath& backing_filepath) { 1596 const base::FilePath& backing_filepath) {
1597 TestBackingStore* backing_store = 1597 TestBackingStore* backing_store =
1598 new TestBackingStore(dir_name, backing_filepath); 1598 new TestBackingStore(dir_name, backing_filepath);
1599 return new TestDirectory(encryptor, handler, backing_store); 1599 return new TestDirectory(encryptor, handler, backing_store);
1600 } 1600 }
1601 1601
1602 TestDirectory::TestDirectory(Encryptor* encryptor, 1602 TestDirectory::TestDirectory(Encryptor* encryptor,
1603 UnrecoverableErrorHandler* handler, 1603 UnrecoverableErrorHandler* handler,
1604 TestBackingStore* backing_store) 1604 TestBackingStore* backing_store)
1605 : Directory(backing_store, handler, NULL, NULL, NULL), 1605 : Directory(backing_store, handler, NULL, NULL, NULL),
1606 backing_store_(backing_store) { 1606 backing_store_(backing_store) {
1607 } 1607 }
1608 1608
1609 TestDirectory::~TestDirectory() { } 1609 TestDirectory::~TestDirectory() { }
1610 1610
1611 TEST(OnDiskSyncableDirectory, FailInitialWrite) { 1611 TEST(OnDiskSyncableDirectory, FailInitialWrite) {
1612 FakeEncryptor encryptor; 1612 FakeEncryptor encryptor;
1613 TestUnrecoverableErrorHandler handler; 1613 TestUnrecoverableErrorHandler handler;
1614 base::ScopedTempDir temp_dir; 1614 base::ScopedTempDir temp_dir;
1615 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1615 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1616 FilePath file_path = temp_dir.path().Append( 1616 base::FilePath file_path = temp_dir.path().Append(
1617 FILE_PATH_LITERAL("Test.sqlite3")); 1617 FILE_PATH_LITERAL("Test.sqlite3"));
1618 std::string name = "user@x.com"; 1618 std::string name = "user@x.com";
1619 NullDirectoryChangeDelegate delegate; 1619 NullDirectoryChangeDelegate delegate;
1620 1620
1621 scoped_ptr<TestDirectory> test_dir( 1621 scoped_ptr<TestDirectory> test_dir(
1622 TestDirectory::Create(&encryptor, &handler, name, file_path)); 1622 TestDirectory::Create(&encryptor, &handler, name, file_path));
1623 1623
1624 test_dir->StartFailingSaveChanges(); 1624 test_dir->StartFailingSaveChanges();
1625 ASSERT_EQ(FAILED_INITIAL_WRITE, test_dir->Open(name, &delegate, 1625 ASSERT_EQ(FAILED_INITIAL_WRITE, test_dir->Open(name, &delegate,
1626 NullTransactionObserver())); 1626 NullTransactionObserver()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 dir_->SaveChanges(); 1661 dir_->SaveChanges();
1662 CreateDirectory(); 1662 CreateDirectory();
1663 } 1663 }
1664 1664
1665 void StartFailingSaveChanges() { 1665 void StartFailingSaveChanges() {
1666 test_directory_->StartFailingSaveChanges(); 1666 test_directory_->StartFailingSaveChanges();
1667 } 1667 }
1668 1668
1669 TestDirectory *test_directory_; // mirrors scoped_ptr<Directory> dir_ 1669 TestDirectory *test_directory_; // mirrors scoped_ptr<Directory> dir_
1670 base::ScopedTempDir temp_dir_; 1670 base::ScopedTempDir temp_dir_;
1671 FilePath file_path_; 1671 base::FilePath file_path_;
1672 }; 1672 };
1673 1673
1674 TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { 1674 TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) {
1675 sync_pb::EntitySpecifics bookmark_specs; 1675 sync_pb::EntitySpecifics bookmark_specs;
1676 sync_pb::EntitySpecifics autofill_specs; 1676 sync_pb::EntitySpecifics autofill_specs;
1677 sync_pb::EntitySpecifics preference_specs; 1677 sync_pb::EntitySpecifics preference_specs;
1678 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); 1678 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs);
1679 AddDefaultFieldValue(PREFERENCES, &preference_specs); 1679 AddDefaultFieldValue(PREFERENCES, &preference_specs);
1680 AddDefaultFieldValue(AUTOFILL, &autofill_specs); 1680 AddDefaultFieldValue(AUTOFILL, &autofill_specs);
1681 1681
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 } 2070 }
2071 protected: 2071 protected:
2072 MessageLoop message_loop_; 2072 MessageLoop message_loop_;
2073 base::ScopedTempDir temp_dir_; 2073 base::ScopedTempDir temp_dir_;
2074 FakeEncryptor encryptor_; 2074 FakeEncryptor encryptor_;
2075 TestUnrecoverableErrorHandler handler_; 2075 TestUnrecoverableErrorHandler handler_;
2076 NullDirectoryChangeDelegate delegate_; 2076 NullDirectoryChangeDelegate delegate_;
2077 }; 2077 };
2078 2078
2079 TEST_F(SyncableDirectoryManagement, TestFileRelease) { 2079 TEST_F(SyncableDirectoryManagement, TestFileRelease) {
2080 FilePath path = temp_dir_.path().Append( 2080 base::FilePath path = temp_dir_.path().Append(
2081 Directory::kSyncDatabaseFilename); 2081 Directory::kSyncDatabaseFilename);
2082 2082
2083 syncable::Directory dir(new OnDiskDirectoryBackingStore("ScopeTest", path), 2083 syncable::Directory dir(new OnDiskDirectoryBackingStore("ScopeTest", path),
2084 &handler_, 2084 &handler_,
2085 NULL, 2085 NULL,
2086 NULL, 2086 NULL,
2087 NULL); 2087 NULL);
2088 DirOpenResult result = 2088 DirOpenResult result =
2089 dir.Open("ScopeTest", &delegate_, NullTransactionObserver()); 2089 dir.Open("ScopeTest", &delegate_, NullTransactionObserver());
2090 ASSERT_EQ(result, OPENED); 2090 ASSERT_EQ(result, OPENED);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 2260 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
2261 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 2261 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
2262 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 2262 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
2263 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 2263 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
2264 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 2264 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
2265 } 2265 }
2266 2266
2267 } // namespace 2267 } // namespace
2268 } // namespace syncable 2268 } // namespace syncable
2269 } // namespace syncer 2269 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/on_disk_directory_backing_store.cc ('k') | sync/test/local_sync_test_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698