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