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