OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 // UserShare 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 // test_user_share_.SetUp(); | |
14 // } | |
15 // virtual void TearDown() { | |
16 // test_user_share_.TearDown(); | |
17 // } | |
18 // protected: | |
19 // TestUserShare test_user_share_; | |
20 // }; | |
21 // | |
22 // Then, in your tests: | |
23 // | |
24 // TEST_F(AwesomenessTest, IsMaximal) { | |
25 // ReadTransaction trans(test_user_share_.user_share()); | |
26 // ... | |
27 // } | |
28 // | |
29 | |
30 #ifndef COMPONENTS_SYNC_CORE_TEST_TEST_USER_SHARE_H_ | |
31 #define COMPONENTS_SYNC_CORE_TEST_TEST_USER_SHARE_H_ | |
32 | |
33 #include <stddef.h> | |
34 | |
35 #include <memory> | |
36 | |
37 #include "base/macros.h" | |
38 #include "components/sync/base/model_type.h" | |
39 #include "components/sync/core/user_share.h" | |
40 | |
41 namespace syncer { | |
42 | |
43 class SyncEncryptionHandler; | |
44 class TestDirectorySetterUpper; | |
45 | |
46 namespace syncable { | |
47 class TestTransactionObserver; | |
48 } | |
49 | |
50 class TestUserShare { | |
51 public: | |
52 TestUserShare(); | |
53 ~TestUserShare(); | |
54 | |
55 // Sets up the UserShare instance. Clears any existing database | |
56 // backing files that might exist on disk. | |
57 void SetUp(); | |
58 | |
59 // Undo everything done by SetUp(): closes the UserShare and deletes | |
60 // the backing files. Before closing the directory, this will run | |
61 // the directory invariant checks and perform the SaveChanges action | |
62 // on the user share's directory. | |
63 void TearDown(); | |
64 | |
65 // Save and reload Directory to clear out temporary data in memory. | |
66 bool Reload(); | |
67 | |
68 // Non-NULL iff called between a call to SetUp() and TearDown(). | |
69 UserShare* user_share(); | |
70 | |
71 // Sync's encryption handler. Used by tests to invoke the sync encryption | |
72 // methods normally handled via the SyncBackendHost | |
73 SyncEncryptionHandler* encryption_handler(); | |
74 | |
75 // Returns the directory's transaction observer. This transaction observer | |
76 // has methods which can be helpful when writing test assertions. | |
77 syncable::TestTransactionObserver* transaction_observer(); | |
78 | |
79 // A helper function to pretend to download this type's root node. | |
80 static bool CreateRoot(ModelType model_type, UserShare* service); | |
81 | |
82 size_t GetDeleteJournalSize() const; | |
83 | |
84 private: | |
85 std::unique_ptr<TestDirectorySetterUpper> dir_maker_; | |
86 std::unique_ptr<UserShare> user_share_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(TestUserShare); | |
89 }; | |
90 | |
91 } // namespace syncer | |
92 | |
93 #endif // COMPONENTS_SYNC_CORE_TEST_TEST_USER_SHARE_H_ | |
OLD | NEW |