| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_ | 5 #ifndef SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_ |
| 6 #define SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_ | 6 #define SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "sync/internal_api/public/base_node.h" |
| 13 #include "sync/internal_api/public/user_share.h" |
| 12 #include "sync/syncable/in_memory_directory_backing_store.h" | 14 #include "sync/syncable/in_memory_directory_backing_store.h" |
| 13 #include "sync/syncable/mutable_entry.h" | 15 #include "sync/syncable/mutable_entry.h" |
| 14 #include "sync/syncable/syncable_read_transaction.h" | 16 #include "sync/syncable/syncable_read_transaction.h" |
| 15 #include "sync/syncable/syncable_write_transaction.h" | 17 #include "sync/syncable/syncable_write_transaction.h" |
| 16 #include "sync/test/engine/test_id_factory.h" | 18 #include "sync/test/engine/test_id_factory.h" |
| 17 #include "sync/test/fake_encryptor.h" | 19 #include "sync/test/fake_encryptor.h" |
| 18 #include "sync/test/null_directory_change_delegate.h" | 20 #include "sync/test/null_directory_change_delegate.h" |
| 19 #include "sync/test/null_transaction_observer.h" | 21 #include "sync/test/null_transaction_observer.h" |
| 20 #include "sync/util/test_unrecoverable_error_handler.h" | 22 #include "sync/util/test_unrecoverable_error_handler.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 DirOpenResult ReopenDirectory(); | 49 DirOpenResult ReopenDirectory(); |
| 48 | 50 |
| 49 // Creates an empty entry and sets the ID field to a default one. | 51 // Creates an empty entry and sets the ID field to a default one. |
| 50 void CreateEntry(const std::string& entryname); | 52 void CreateEntry(const std::string& entryname); |
| 51 | 53 |
| 52 // Creates an empty entry and sets the ID field to id. | 54 // Creates an empty entry and sets the ID field to id. |
| 53 void CreateEntry(const std::string& entryname, const int id); | 55 void CreateEntry(const std::string& entryname, const int id); |
| 54 | 56 |
| 55 void CreateEntry(const std::string& entryname, Id id); | 57 void CreateEntry(const std::string& entryname, Id id); |
| 56 | 58 |
| 59 // Create an entry with the given |model_type|, |client_tag| and |
| 60 // |attachment_metadata|. |
| 61 void CreateEntryWithAttachmentMetadata( |
| 62 const ModelType& model_type, |
| 63 const std::string& client_tag, |
| 64 const sync_pb::AttachmentMetadata& attachment_metadata); |
| 65 |
| 57 // When a directory is saved then loaded from disk, it will pass through | 66 // When a directory is saved then loaded from disk, it will pass through |
| 58 // DropDeletedEntries(). This will remove some entries from the directory. | 67 // DropDeletedEntries(). This will remove some entries from the directory. |
| 59 // This function is intended to simulate that process. | 68 // This function is intended to simulate that process. |
| 60 // | 69 // |
| 61 // WARNING: The directory will be deleted by this operation. You should | 70 // WARNING: The directory will be deleted by this operation. You should |
| 62 // not have any pointers to the directory (open transactions included) | 71 // not have any pointers to the directory (open transactions included) |
| 63 // when you call this. | 72 // when you call this. |
| 64 DirOpenResult SimulateSaveAndReloadDir(); | 73 DirOpenResult SimulateSaveAndReloadDir(); |
| 65 | 74 |
| 66 // This function will close and re-open the directory without saving any | 75 // This function will close and re-open the directory without saving any |
| 67 // pending changes. This is intended to simulate the recovery from a crash | 76 // pending changes. This is intended to simulate the recovery from a crash |
| 68 // scenario. The same warnings for SimulateSaveAndReloadDir apply here. | 77 // scenario. The same warnings for SimulateSaveAndReloadDir apply here. |
| 69 DirOpenResult SimulateCrashAndReloadDir(); | 78 DirOpenResult SimulateCrashAndReloadDir(); |
| 70 | 79 |
| 71 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); | 80 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); |
| 72 void CheckPurgeEntriesWithTypeInSucceeded(ModelTypeSet types_to_purge, | 81 void CheckPurgeEntriesWithTypeInSucceeded(ModelTypeSet types_to_purge, |
| 73 bool before_reload); | 82 bool before_reload); |
| 74 bool IsInDirtyMetahandles(int64 metahandle); | 83 bool IsInDirtyMetahandles(int64 metahandle); |
| 75 bool IsInMetahandlesToPurge(int64 metahandle); | 84 bool IsInMetahandlesToPurge(int64 metahandle); |
| 76 | 85 |
| 86 // Attempts to load the entry specified by |model_type| and |client_tag| and |
| 87 // returns the lookup result code. |
| 88 BaseNode::InitByLookupResult LookupEntryByClientTag( |
| 89 const ModelType& model_type, |
| 90 const std::string& client_tag); |
| 91 |
| 92 // Replace the entry specified by |model_type| and |client_tag| with a |
| 93 // tombstone. |
| 94 void ReplaceWithTombstone(const ModelType& model_type, |
| 95 const std::string& client_tag); |
| 96 |
| 77 scoped_ptr<Directory>& dir(); | 97 scoped_ptr<Directory>& dir(); |
| 98 UserShare* user_share(); |
| 78 DirectoryChangeDelegate* directory_change_delegate(); | 99 DirectoryChangeDelegate* directory_change_delegate(); |
| 79 Encryptor* encryptor(); | 100 Encryptor* encryptor(); |
| 80 UnrecoverableErrorHandler* unrecoverable_error_handler(); | 101 UnrecoverableErrorHandler* unrecoverable_error_handler(); |
| 81 | 102 |
| 82 private: | 103 private: |
| 83 void ValidateEntry(BaseTransaction* trans, | 104 void ValidateEntry(BaseTransaction* trans, |
| 84 int64 id, | 105 int64 id, |
| 85 bool check_name, | 106 bool check_name, |
| 86 const std::string& name, | 107 const std::string& name, |
| 87 int64 base_version, | 108 int64 base_version, |
| 88 int64 server_version, | 109 int64 server_version, |
| 89 bool is_del); | 110 bool is_del); |
| 90 | 111 |
| 91 base::MessageLoop message_loop_; | 112 base::MessageLoop message_loop_; |
| 92 scoped_ptr<Directory> dir_; | 113 syncer::UserShare user_share_; |
| 93 NullDirectoryChangeDelegate delegate_; | 114 NullDirectoryChangeDelegate delegate_; |
| 94 FakeEncryptor encryptor_; | 115 FakeEncryptor encryptor_; |
| 95 TestUnrecoverableErrorHandler handler_; | 116 TestUnrecoverableErrorHandler handler_; |
| 96 sql::Connection connection_; | 117 sql::Connection connection_; |
| 97 }; | 118 }; |
| 98 | 119 |
| 99 } // namespace syncable | 120 } // namespace syncable |
| 100 | 121 |
| 101 } // namespace syncer | 122 } // namespace syncer |
| 102 | 123 |
| 103 #endif // SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_ | 124 #endif // SYNC_SYNCABLE_DIRECTORY_UNITTEST_H_ |
| OLD | NEW |