diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 04:17:38 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 04:17:38 +0000 |
commit | 3d807d391319ce5b97e75c77a131c802fe184ccc (patch) | |
tree | a77da2bde1330e94e1b9e165f3d2ea32b8f84e63 /chrome/test/sync | |
parent | 2f6d64de8b337131d31aa488eed54a353e241e16 (diff) | |
download | chromium_src-3d807d391319ce5b97e75c77a131c802fe184ccc.zip chromium_src-3d807d391319ce5b97e75c77a131c802fe184ccc.tar.gz chromium_src-3d807d391319ce5b97e75c77a131c802fe184ccc.tar.bz2 |
sync: add CleanupDisabledTypesCommand to purge data pertaining to previously
synced data types that the user has disabled.
Despite my attempt at simplifying the purge code in Directory[BackingStore], I had to go back to my first attempt with DeleteEntries (which was previously reviewed separately), with a few extra gotchas in Directory::PurgeEntriesWithTypeIn.
BUG=40252
TEST=CleanupDisabledTypesCommandTest, SyncableDirectoryTest, DirectoryBackingStoreTest
Review URL: http://codereview.chromium.org/2865022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/sync')
-rw-r--r-- | chrome/test/sync/engine/syncer_command_test.h | 35 | ||||
-rw-r--r-- | chrome/test/sync/engine/test_directory_setter_upper.cc | 29 | ||||
-rw-r--r-- | chrome/test/sync/engine/test_directory_setter_upper.h | 30 |
3 files changed, 85 insertions, 9 deletions
diff --git a/chrome/test/sync/engine/syncer_command_test.h b/chrome/test/sync/engine/syncer_command_test.h index 14e4da5..9a3c87c 100644 --- a/chrome/test/sync/engine/syncer_command_test.h +++ b/chrome/test/sync/engine/syncer_command_test.h @@ -24,6 +24,10 @@ class SyncerCommandTestWithParam : public testing::TestWithParam<T>, public sessions::SyncSession::Delegate, public ModelSafeWorkerRegistrar { public: + enum UseMockDirectory { + USE_MOCK_DIRECTORY + }; + // SyncSession::Delegate implementation. virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) { FAIL() << "Should not get silenced."; @@ -53,17 +57,21 @@ class SyncerCommandTestWithParam : public testing::TestWithParam<T>, } protected: - SyncerCommandTestWithParam() {} + SyncerCommandTestWithParam() : syncdb_(new TestDirectorySetterUpper()) {} + + explicit SyncerCommandTestWithParam(UseMockDirectory use_mock) + : syncdb_(new MockDirectorySetterUpper()) {} + virtual ~SyncerCommandTestWithParam() {} virtual void SetUp() { - syncdb_.SetUp(); + syncdb_->SetUp(); ResetContext(); } virtual void TearDown() { - syncdb_.TearDown(); + syncdb_->TearDown(); } - const TestDirectorySetterUpper& syncdb() const { return syncdb_; } + TestDirectorySetterUpper* syncdb() { return syncdb_.get(); } sessions::SyncSessionContext* context() const { return context_.get(); } sessions::SyncSession::Delegate* delegate() { return this; } ModelSafeWorkerRegistrar* registrar() { return this; } @@ -79,8 +87,8 @@ class SyncerCommandTestWithParam : public testing::TestWithParam<T>, void ResetContext() { context_.reset(new sessions::SyncSessionContext( - mock_server_.get(), NULL, syncdb_.manager(), registrar())); - context_->set_account_name(syncdb_.name()); + mock_server_.get(), NULL, syncdb_->manager(), registrar())); + context_->set_account_name(syncdb_->name()); ClearSession(); } @@ -88,7 +96,7 @@ class SyncerCommandTestWithParam : public testing::TestWithParam<T>, // the context does not have a MockServerConnection attached. void ConfigureMockServerConnection() { mock_server_.reset( - new MockConnectionManager(syncdb_.manager(), syncdb_.name())); + new MockConnectionManager(syncdb_->manager(), syncdb_->name())); ResetContext(); } @@ -104,7 +112,7 @@ class SyncerCommandTestWithParam : public testing::TestWithParam<T>, } private: - TestDirectorySetterUpper syncdb_; + scoped_ptr<TestDirectorySetterUpper> syncdb_; scoped_ptr<sessions::SyncSessionContext> context_; scoped_ptr<MockConnectionManager> mock_server_; scoped_ptr<sessions::SyncSession> session_; @@ -115,6 +123,17 @@ class SyncerCommandTestWithParam : public testing::TestWithParam<T>, class SyncerCommandTest : public SyncerCommandTestWithParam<void*> {}; +class MockDirectorySyncerCommandTest + : public SyncerCommandTestWithParam<void*> { + public: + MockDirectorySyncerCommandTest() + : SyncerCommandTestWithParam<void*>( + SyncerCommandTestWithParam<void*>::USE_MOCK_DIRECTORY) {} + MockDirectorySetterUpper::MockDirectory* mock_directory() { + return static_cast<MockDirectorySetterUpper*>(syncdb())->directory(); + } +}; + } // namespace browser_sync #endif // CHROME_TEST_SYNC_ENGINE_SYNCER_COMMAND_TEST_H_ diff --git a/chrome/test/sync/engine/test_directory_setter_upper.cc b/chrome/test/sync/engine/test_directory_setter_upper.cc index 5d861d9..4818280 100644 --- a/chrome/test/sync/engine/test_directory_setter_upper.cc +++ b/chrome/test/sync/engine/test_directory_setter_upper.cc @@ -25,11 +25,15 @@ TestDirectorySetterUpper::~TestDirectorySetterUpper() {} void TestDirectorySetterUpper::Init() { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - manager_.reset(new DirectoryManager(temp_dir_.path())); + reset_directory_manager(new DirectoryManager(temp_dir_.path())); file_path_ = manager_->GetSyncDataDatabasePath(); file_util::Delete(file_path_, false); } +void TestDirectorySetterUpper::reset_directory_manager(DirectoryManager* d) { + manager_.reset(d); +} + void TestDirectorySetterUpper::SetUp() { Init(); ASSERT_TRUE(manager()->Open(name())); @@ -104,4 +108,27 @@ void TriggeredOpenTestDirectorySetterUpper::TearDown() { } } +MockDirectorySetterUpper::MockDirectory::MockDirectory( + const std::string& name) { + init_kernel(name); +} + +MockDirectorySetterUpper::Manager::Manager( + const FilePath& root_path, syncable::Directory* dir) : + syncable::DirectoryManager(root_path) { + managed_directory_ = dir; +} + +MockDirectorySetterUpper::MockDirectorySetterUpper() + : directory_(new MockDirectory(name())) { +} + +void MockDirectorySetterUpper::SetUp() { + reset_directory_manager(new Manager(FilePath(), directory_.get())); +} + +void MockDirectorySetterUpper::TearDown() { + // Nothing to do here. +} + } // namespace browser_sync diff --git a/chrome/test/sync/engine/test_directory_setter_upper.h b/chrome/test/sync/engine/test_directory_setter_upper.h index 0cb3bd6a..b5d5be1 100644 --- a/chrome/test/sync/engine/test_directory_setter_upper.h +++ b/chrome/test/sync/engine/test_directory_setter_upper.h @@ -34,8 +34,10 @@ #include "base/scoped_ptr.h" #include "base/scoped_temp_dir.h" +#include "chrome/browser/sync/syncable/directory_manager.h" #include "chrome/browser/sync/syncable/syncable.h" #include "chrome/browser/sync/util/sync_types.h" +#include "testing/gmock/include/gmock/gmock.h" namespace syncable { class DirectoryManager; @@ -65,6 +67,7 @@ class TestDirectorySetterUpper { // Subclasses may want to use a different directory name. explicit TestDirectorySetterUpper(const std::string& name); virtual void Init(); + void reset_directory_manager(syncable::DirectoryManager* d); private: void RunInvariantCheck(const syncable::ScopedDirLookup& dir); @@ -100,6 +103,33 @@ class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper { virtual void TearDown(); }; +// Use this when you don't want to test the whole stack down to the Directory +// level, as it installs a google mock Directory implementation. +class MockDirectorySetterUpper : public TestDirectorySetterUpper { + public: + class Manager : public syncable::DirectoryManager { + public: + Manager(const FilePath& root_path, syncable::Directory* dir); + virtual ~Manager() { managed_directory_ = NULL; } + }; + + class MockDirectory : public syncable::Directory { + public: + explicit MockDirectory(const std::string& name); + virtual ~MockDirectory() {} + MOCK_METHOD1(PurgeEntriesWithTypeIn, void(const syncable::ModelTypeSet&)); + }; + + MockDirectorySetterUpper(); + + virtual void SetUp(); + virtual void TearDown(); + MockDirectory* directory() { return directory_.get(); } + + private: + scoped_ptr<MockDirectory> directory_; +}; + } // namespace browser_sync #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |