| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 30 #ifndef CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| 31 #define CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 31 #define CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| 32 #pragma once | 32 #pragma once |
| 33 | 33 |
| 34 #include <string> | 34 #include <string> |
| 35 | 35 |
| 36 #include "base/basictypes.h" | 36 #include "base/basictypes.h" |
| 37 #include "base/compiler_specific.h" |
| 37 #include "base/memory/scoped_ptr.h" | 38 #include "base/memory/scoped_ptr.h" |
| 38 #include "base/scoped_temp_dir.h" | 39 #include "base/scoped_temp_dir.h" |
| 39 #include "chrome/browser/sync/syncable/directory_manager.h" | 40 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 40 #include "chrome/browser/sync/syncable/syncable.h" | 41 #include "chrome/browser/sync/syncable/syncable.h" |
| 41 #include "chrome/browser/sync/test/null_directory_change_delegate.h" | 42 #include "chrome/browser/sync/test/null_directory_change_delegate.h" |
| 42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 43 | 44 |
| 44 namespace syncable { | 45 namespace syncable { |
| 45 class DirectoryManager; | 46 class DirectoryManager; |
| 46 class ScopedDirLookup; | 47 class ScopedDirLookup; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 83 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestDirectorySetterUpper); | 84 DISALLOW_COPY_AND_ASSIGN(TestDirectorySetterUpper); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 // A variant of the above where SetUp does not actually open the directory. | 87 // A variant of the above where SetUp does not actually open the directory. |
| 87 // You must manually invoke Open(). This is useful if you are writing a test | 88 // You must manually invoke Open(). This is useful if you are writing a test |
| 88 // that depends on the DirectoryManager::OPENED event. | 89 // that depends on the DirectoryManager::OPENED event. |
| 89 class ManuallyOpenedTestDirectorySetterUpper : public TestDirectorySetterUpper { | 90 class ManuallyOpenedTestDirectorySetterUpper : public TestDirectorySetterUpper { |
| 90 public: | 91 public: |
| 91 ManuallyOpenedTestDirectorySetterUpper() : was_opened_(false) {} | 92 ManuallyOpenedTestDirectorySetterUpper() : was_opened_(false) {} |
| 92 virtual void SetUp(); | 93 virtual void SetUp() OVERRIDE; |
| 93 virtual void TearDown(); | 94 virtual void TearDown() OVERRIDE; |
| 94 void Open(); | 95 void Open(); |
| 95 private: | 96 private: |
| 96 bool was_opened_; | 97 bool was_opened_; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 // Use this flavor if you have a test that will trigger the opening event to | 100 // Use this flavor if you have a test that will trigger the opening event to |
| 100 // happen automagically. It is careful on teardown to close only if needed. | 101 // happen automagically. It is careful on teardown to close only if needed. |
| 101 class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper { | 102 class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper { |
| 102 public: | 103 public: |
| 103 // A triggered open is typically in response to a successful auth event just | 104 // A triggered open is typically in response to a successful auth event just |
| 104 // as in "real life". In this case, the name that will be used should be | 105 // as in "real life". In this case, the name that will be used should be |
| 105 // deterministically known at construction, and is passed in |name|. | 106 // deterministically known at construction, and is passed in |name|. |
| 106 explicit TriggeredOpenTestDirectorySetterUpper(const std::string& name); | 107 explicit TriggeredOpenTestDirectorySetterUpper(const std::string& name); |
| 107 virtual void SetUp(); | 108 virtual void SetUp() OVERRIDE; |
| 108 virtual void TearDown(); | 109 virtual void TearDown() OVERRIDE; |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 // Use this when you don't want to test the whole stack down to the Directory | 112 // Use this when you don't want to test the whole stack down to the Directory |
| 112 // level, as it installs a google mock Directory implementation. | 113 // level, as it installs a google mock Directory implementation. |
| 113 class MockDirectorySetterUpper : public TestDirectorySetterUpper { | 114 class MockDirectorySetterUpper : public TestDirectorySetterUpper { |
| 114 public: | 115 public: |
| 115 class Manager : public syncable::DirectoryManager { | 116 class Manager : public syncable::DirectoryManager { |
| 116 public: | 117 public: |
| 117 Manager(const FilePath& root_path, syncable::Directory* dir); | 118 Manager(const FilePath& root_path, syncable::Directory* dir); |
| 118 virtual ~Manager() { managed_directory_ = NULL; } | 119 virtual ~Manager() { managed_directory_ = NULL; } |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 class MockDirectory : public syncable::Directory { | 122 class MockDirectory : public syncable::Directory { |
| 122 public: | 123 public: |
| 123 explicit MockDirectory(const std::string& name); | 124 explicit MockDirectory(const std::string& name); |
| 124 virtual ~MockDirectory(); | 125 virtual ~MockDirectory(); |
| 125 MOCK_METHOD1(PurgeEntriesWithTypeIn, void(const syncable::ModelTypeSet&)); | 126 MOCK_METHOD1(PurgeEntriesWithTypeIn, void(const syncable::ModelTypeSet&)); |
| 126 | 127 |
| 127 private: | 128 private: |
| 128 syncable::NullDirectoryChangeDelegate delegate_; | 129 syncable::NullDirectoryChangeDelegate delegate_; |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 MockDirectorySetterUpper(); | 132 MockDirectorySetterUpper(); |
| 132 virtual ~MockDirectorySetterUpper(); | 133 virtual ~MockDirectorySetterUpper(); |
| 133 | 134 |
| 134 virtual void SetUp(); | 135 virtual void SetUp() OVERRIDE; |
| 135 virtual void TearDown(); | 136 virtual void TearDown() OVERRIDE; |
| 136 MockDirectory* directory() { return directory_.get(); } | 137 MockDirectory* directory() { return directory_.get(); } |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 scoped_ptr<MockDirectory> directory_; | 140 scoped_ptr<MockDirectory> directory_; |
| 140 }; | 141 }; |
| 141 | 142 |
| 142 } // namespace browser_sync | 143 } // namespace browser_sync |
| 143 | 144 |
| 144 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 145 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| OLD | NEW |