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

Side by Side Diff: chrome/test/sync/engine/test_directory_setter_upper.h

Issue 7828055: Move sync test code out of chrome/test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // A handy class that takes care of setting up and destroying a
6 // syncable::Directory instance for unit tests that require one.
7 //
8 // The expected usage is to make this a component of your test fixture:
9 //
10 // class AwesomenessTest : public testing::Test {
11 // public:
12 // virtual void SetUp() {
13 // metadb_.SetUp();
14 // }
15 // virtual void TearDown() {
16 // metadb_.TearDown();
17 // }
18 // protected:
19 // TestDirectorySetterUpper metadb_;
20 // };
21 //
22 // Then, in your tests, get at the directory like so:
23 //
24 // TEST_F(AwesomenessTest, IsMaximal) {
25 // ScopedDirLookup dir(metadb_.manager(), metadb_.name());
26 // ... now use |dir| to get at syncable::Entry objects ...
27 // }
28 //
29
30 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_
31 #define CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_
32 #pragma once
33
34 #include <string>
35
36 #include "base/basictypes.h"
37 #include "base/memory/scoped_ptr.h"
38 #include "base/scoped_temp_dir.h"
39 #include "chrome/browser/sync/syncable/directory_manager.h"
40 #include "chrome/browser/sync/syncable/syncable.h"
41 #include "chrome/test/sync/null_directory_change_delegate.h"
42 #include "testing/gmock/include/gmock/gmock.h"
43
44 namespace syncable {
45 class DirectoryManager;
46 class ScopedDirLookup;
47 } // namespace syncable
48
49 namespace browser_sync {
50
51 class TestDirectorySetterUpper {
52 public:
53 TestDirectorySetterUpper();
54 virtual ~TestDirectorySetterUpper();
55
56 // Create a DirectoryManager instance and use it to open the directory.
57 // Clears any existing database backing files that might exist on disk.
58 virtual void SetUp();
59
60 // Undo everything done by SetUp(): close the directory and delete the
61 // backing files. Before closing the directory, this will run the directory
62 // invariant checks and perform the SaveChanges action on the directory.
63 virtual void TearDown();
64
65 syncable::DirectoryManager* manager() const { return manager_.get(); }
66 const std::string& name() const { return name_; }
67
68 protected:
69 // Subclasses may want to use a different directory name.
70 explicit TestDirectorySetterUpper(const std::string& name);
71 virtual void Init();
72 void reset_directory_manager(syncable::DirectoryManager* d);
73
74 syncable::NullDirectoryChangeDelegate delegate_;
75
76 private:
77 void RunInvariantCheck(const syncable::ScopedDirLookup& dir);
78
79 scoped_ptr<syncable::DirectoryManager> manager_;
80 const std::string name_;
81 ScopedTempDir temp_dir_;
82
83 DISALLOW_COPY_AND_ASSIGN(TestDirectorySetterUpper);
84 };
85
86 // 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 // that depends on the DirectoryManager::OPENED event.
89 class ManuallyOpenedTestDirectorySetterUpper : public TestDirectorySetterUpper {
90 public:
91 ManuallyOpenedTestDirectorySetterUpper() : was_opened_(false) {}
92 virtual void SetUp();
93 virtual void TearDown();
94 void Open();
95 private:
96 bool was_opened_;
97 };
98
99 // 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 class TriggeredOpenTestDirectorySetterUpper : public TestDirectorySetterUpper {
102 public:
103 // 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 // deterministically known at construction, and is passed in |name|.
106 explicit TriggeredOpenTestDirectorySetterUpper(const std::string& name);
107 virtual void SetUp();
108 virtual void TearDown();
109 };
110
111 // 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 class MockDirectorySetterUpper : public TestDirectorySetterUpper {
114 public:
115 class Manager : public syncable::DirectoryManager {
116 public:
117 Manager(const FilePath& root_path, syncable::Directory* dir);
118 virtual ~Manager() { managed_directory_ = NULL; }
119 };
120
121 class MockDirectory : public syncable::Directory {
122 public:
123 explicit MockDirectory(const std::string& name);
124 virtual ~MockDirectory();
125 MOCK_METHOD1(PurgeEntriesWithTypeIn, void(const syncable::ModelTypeSet&));
126
127 private:
128 syncable::NullDirectoryChangeDelegate delegate_;
129 };
130
131 MockDirectorySetterUpper();
132 virtual ~MockDirectorySetterUpper();
133
134 virtual void SetUp();
135 virtual void TearDown();
136 MockDirectory* directory() { return directory_.get(); }
137
138 private:
139 scoped_ptr<MockDirectory> directory_;
140 };
141
142 } // namespace browser_sync
143
144 #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_
OLDNEW
« no previous file with comments | « chrome/test/sync/engine/syncer_command_test.h ('k') | chrome/test/sync/engine/test_directory_setter_upper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698