| OLD | NEW |
| 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 // A handy class that takes care of setting up and destroying a | 5 // A handy class that takes care of setting up and destroying a |
| 6 // syncable::Directory instance for unit tests that require one. | 6 // syncable::Directory instance for unit tests that require one. |
| 7 // | 7 // |
| 8 // The expected usage is to make this a component of your test fixture: | 8 // The expected usage is to make this a component of your test fixture: |
| 9 // | 9 // |
| 10 // class AwesomenessTest : public testing::Test { | 10 // class AwesomenessTest : public testing::Test { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // } | 27 // } |
| 28 // | 28 // |
| 29 | 29 |
| 30 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 30 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| 31 #define CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 31 #define CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| 32 | 32 |
| 33 #include <string> | 33 #include <string> |
| 34 | 34 |
| 35 #include "base/scoped_ptr.h" | 35 #include "base/scoped_ptr.h" |
| 36 #include "base/scoped_temp_dir.h" | 36 #include "base/scoped_temp_dir.h" |
| 37 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 37 #include "chrome/browser/sync/syncable/syncable.h" | 38 #include "chrome/browser/sync/syncable/syncable.h" |
| 38 #include "chrome/browser/sync/util/sync_types.h" | 39 #include "chrome/browser/sync/util/sync_types.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" |
| 39 | 41 |
| 40 namespace syncable { | 42 namespace syncable { |
| 41 class DirectoryManager; | 43 class DirectoryManager; |
| 42 class ScopedDirLookup; | 44 class ScopedDirLookup; |
| 43 } // namespace syncable | 45 } // namespace syncable |
| 44 | 46 |
| 45 namespace browser_sync { | 47 namespace browser_sync { |
| 46 | 48 |
| 47 class TestDirectorySetterUpper { | 49 class TestDirectorySetterUpper { |
| 48 public: | 50 public: |
| 49 TestDirectorySetterUpper(); | 51 TestDirectorySetterUpper(); |
| 50 virtual ~TestDirectorySetterUpper(); | 52 virtual ~TestDirectorySetterUpper(); |
| 51 | 53 |
| 52 // Create a DirectoryManager instance and use it to open the directory. | 54 // Create a DirectoryManager instance and use it to open the directory. |
| 53 // Clears any existing database backing files that might exist on disk. | 55 // Clears any existing database backing files that might exist on disk. |
| 54 virtual void SetUp(); | 56 virtual void SetUp(); |
| 55 | 57 |
| 56 // Undo everything done by SetUp(): close the directory and delete the | 58 // Undo everything done by SetUp(): close the directory and delete the |
| 57 // backing files. Before closing the directory, this will run the directory | 59 // backing files. Before closing the directory, this will run the directory |
| 58 // invariant checks and perform the SaveChanges action on the directory. | 60 // invariant checks and perform the SaveChanges action on the directory. |
| 59 virtual void TearDown(); | 61 virtual void TearDown(); |
| 60 | 62 |
| 61 syncable::DirectoryManager* manager() const { return manager_.get(); } | 63 syncable::DirectoryManager* manager() const { return manager_.get(); } |
| 62 const std::string& name() const { return name_; } | 64 const std::string& name() const { return name_; } |
| 63 | 65 |
| 64 protected: | 66 protected: |
| 65 // Subclasses may want to use a different directory name. | 67 // Subclasses may want to use a different directory name. |
| 66 explicit TestDirectorySetterUpper(const std::string& name); | 68 explicit TestDirectorySetterUpper(const std::string& name); |
| 67 virtual void Init(); | 69 virtual void Init(); |
| 70 void reset_directory_manager(syncable::DirectoryManager* d); |
| 68 | 71 |
| 69 private: | 72 private: |
| 70 void RunInvariantCheck(const syncable::ScopedDirLookup& dir); | 73 void RunInvariantCheck(const syncable::ScopedDirLookup& dir); |
| 71 | 74 |
| 72 scoped_ptr<syncable::DirectoryManager> manager_; | 75 scoped_ptr<syncable::DirectoryManager> manager_; |
| 73 const std::string name_; | 76 const std::string name_; |
| 74 FilePath file_path_; | 77 FilePath file_path_; |
| 75 ScopedTempDir temp_dir_; | 78 ScopedTempDir temp_dir_; |
| 76 }; | 79 }; |
| 77 | 80 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 93 class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper { | 96 class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper { |
| 94 public: | 97 public: |
| 95 // A triggered open is typically in response to a successful auth event just | 98 // A triggered open is typically in response to a successful auth event just |
| 96 // as in "real life". In this case, the name that will be used should be | 99 // as in "real life". In this case, the name that will be used should be |
| 97 // deterministically known at construction, and is passed in |name|. | 100 // deterministically known at construction, and is passed in |name|. |
| 98 explicit TriggeredOpenTestDirectorySetterUpper(const std::string& name); | 101 explicit TriggeredOpenTestDirectorySetterUpper(const std::string& name); |
| 99 virtual void SetUp(); | 102 virtual void SetUp(); |
| 100 virtual void TearDown(); | 103 virtual void TearDown(); |
| 101 }; | 104 }; |
| 102 | 105 |
| 106 // Use this when you don't want to test the whole stack down to the Directory |
| 107 // level, as it installs a google mock Directory implementation. |
| 108 class MockDirectorySetterUpper : public TestDirectorySetterUpper { |
| 109 public: |
| 110 class Manager : public syncable::DirectoryManager { |
| 111 public: |
| 112 Manager(const FilePath& root_path, syncable::Directory* dir); |
| 113 virtual ~Manager() { managed_directory_ = NULL; } |
| 114 }; |
| 115 |
| 116 class MockDirectory : public syncable::Directory { |
| 117 public: |
| 118 explicit MockDirectory(const std::string& name); |
| 119 virtual ~MockDirectory() {} |
| 120 MOCK_METHOD1(PurgeEntriesWithTypeIn, void(const syncable::ModelTypeSet&)); |
| 121 }; |
| 122 |
| 123 MockDirectorySetterUpper(); |
| 124 |
| 125 virtual void SetUp(); |
| 126 virtual void TearDown(); |
| 127 MockDirectory* directory() { return directory_.get(); } |
| 128 |
| 129 private: |
| 130 scoped_ptr<MockDirectory> directory_; |
| 131 }; |
| 132 |
| 103 } // namespace browser_sync | 133 } // namespace browser_sync |
| 104 | 134 |
| 105 #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 135 #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| OLD | NEW |