1 // Copyright 2014 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.
5 #ifndef SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_
6 #define SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_
10 #include "base/basictypes.h"
11 #include "base/message_loop/message_loop.h"
12 #include "sync/syncable/in_memory_directory_backing_store.h"
13 #include "sync/syncable/mutable_entry.h"
14 #include "sync/syncable/syncable_read_transaction.h"
15 #include "sync/syncable/syncable_write_transaction.h"
16 #include "sync/test/engine/test_id_factory.h"
17 #include "sync/test/fake_encryptor.h"
18 #include "sync/test/null_directory_change_delegate.h"
19 #include "sync/test/null_transaction_observer.h"
20 #include "sync/util/test_unrecoverable_error_handler.h"
21 #include "testing/gtest/include/gtest/gtest.h"
27 class BaseTransaction
;
29 // A test fixture for syncable::Directory. Uses an in-memory database to keep
30 // the unit tests fast.
32 // Serves as base class for several other test fixtures.
33 class SyncableDirectoryTest
: public testing::Test
{
35 static const char kDirectoryName
[];
37 SyncableDirectoryTest();
38 virtual ~SyncableDirectoryTest();
41 virtual void TearDown();
43 // Destroys any currently opened directory, creates and opens a new one.
45 // Returns result of the Open call.
46 DirOpenResult
ReopenDirectory();
48 // Creates an empty entry and sets the ID field to a default one.
49 void CreateEntry(const ModelType
& model_type
, const std::string
& entryname
);
51 // Creates an empty entry and sets the ID field to id.
52 void CreateEntry(const ModelType
& model_type
,
53 const std::string
& entryname
,
56 void CreateEntry(const ModelType
& model_type
,
57 const std::string
& entryname
,
60 void CreateEntryWithAttachmentMetadata(
61 const ModelType
& model_type
,
62 const std::string
& entryname
,
64 const sync_pb::AttachmentMetadata
& attachment_metadata
);
66 void DeleteEntry(const Id
& id
);
68 // When a directory is saved then loaded from disk, it will pass through
69 // DropDeletedEntries(). This will remove some entries from the directory.
70 // This function is intended to simulate that process.
72 // WARNING: The directory will be deleted by this operation. You should
73 // not have any pointers to the directory (open transactions included)
74 // when you call this.
75 DirOpenResult
SimulateSaveAndReloadDir();
77 // This function will close and re-open the directory without saving any
78 // pending changes. This is intended to simulate the recovery from a crash
79 // scenario. The same warnings for SimulateSaveAndReloadDir apply here.
80 DirOpenResult
SimulateCrashAndReloadDir();
82 void GetAllMetaHandles(BaseTransaction
* trans
, MetahandleSet
* result
);
83 void CheckPurgeEntriesWithTypeInSucceeded(ModelTypeSet types_to_purge
,
85 bool IsInDirtyMetahandles(int64 metahandle
);
86 bool IsInMetahandlesToPurge(int64 metahandle
);
88 scoped_ptr
<Directory
>& dir();
89 DirectoryChangeDelegate
* directory_change_delegate();
90 Encryptor
* encryptor();
91 UnrecoverableErrorHandler
* unrecoverable_error_handler();
94 void ValidateEntry(BaseTransaction
* trans
,
97 const std::string
& name
,
102 base::MessageLoop message_loop_
;
103 scoped_ptr
<Directory
> dir_
;
104 NullDirectoryChangeDelegate delegate_
;
105 FakeEncryptor encryptor_
;
106 TestUnrecoverableErrorHandler handler_
;
107 sql::Connection connection_
;
110 } // namespace syncable
112 } // namespace syncer
114 #endif // SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_