Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: sync/api/mock_model_type_store.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/api/metadata_change_list.h ('k') | sync/api/mock_model_type_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 #ifndef SYNC_API_MOCK_MODEL_TYPE_STORE_H_
6 #define SYNC_API_MOCK_MODEL_TYPE_STORE_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "sync/api/model_type_store.h"
12
13 namespace syncer_v2 {
14
15 // MockModelTypeStore is implementation of ModelTypeStore that does nothing.
16 // Use it when testing components that depend on ModelTypeStore.
17 //
18 // By default all methods return SUCCESS and empty results. It is possible to
19 // register custom handlers for certain functions to override behavior. It is
20 // responsibility of handler to post callback with result.
21 // Here is an example:
22 // ===
23 // void OnReadData(const ModelTypeStore::IdList& id_list,
24 // const ModelTypeStore::ReadAllDataCallback& callback) {
25 // // Verify id_list here.
26 // // Prepare fake response.
27 // std::unique_ptr<ModelTypeStore::RecordList> record_list(
28 // new ModelTypeStore::RecordList);
29 // record_list->push_back(ModelTypeStore::Record("id1", "value1"));
30 // base::ThreadTaskRunnerHandle::Get()->PostTask(
31 // FROM_HERE, base::Bind(callback, Result::SUCCESS,
32 // base::Passed(record_list)));
33 // }
34 //
35 // MockModelTypeStore mock_model_type_store;
36 // mock_model_type_store.RegisterReadDataHandler(base::Bind(&OnReadData));
37 // ModelTypeStore::IdList id_list;
38 // id_list.push_back("id1");
39 // mock_model_type_store.ReadData(id_list, base::Bind(&ReadDone));
40 // ===
41 // TODO(pavel): When in-memory store is available this class should delegate all
42 // calls to it instead of returning empty successful results.
43 class MockModelTypeStore : public ModelTypeStore {
44 public:
45 // Signatures for all ModelTypeStore virtual functions.
46 typedef base::Callback<void(const ReadAllDataCallback&)> ReadAllDataSignature;
47 typedef base::Callback<void(const IdList&, const ReadDataCallback&)>
48 ReadDataSignature;
49 typedef base::Callback<void(const ReadMetadataCallback& callback)>
50 ReadAllMetadataSignature;
51 typedef base::Callback<void(std::unique_ptr<WriteBatch>, CallbackWithResult)>
52 CommitWriteBatchSignature;
53 typedef base::Callback<void(WriteBatch*,
54 const std::string&,
55 const std::string&)> WriteRecordSignature;
56 typedef base::Callback<void(WriteBatch*, const std::string&)>
57 WriteGlobalMetadataSignature;
58 typedef base::Callback<void(WriteBatch*, const std::string&)>
59 DeleteRecordSignature;
60 typedef base::Callback<void(WriteBatch*)> DeleteGlobalMetadataSignature;
61
62 MockModelTypeStore();
63 ~MockModelTypeStore() override;
64
65 // ModelTypeStore implementation.
66 void ReadData(const IdList& id_list,
67 const ReadDataCallback& callback) override;
68 void ReadAllData(const ReadAllDataCallback& callback) override;
69 void ReadAllMetadata(const ReadMetadataCallback& callback) override;
70
71 std::unique_ptr<WriteBatch> CreateWriteBatch() override;
72 void CommitWriteBatch(std::unique_ptr<WriteBatch> write_batch,
73 const CallbackWithResult& callback) override;
74
75 void WriteData(WriteBatch* write_batch,
76 const std::string& id,
77 const std::string& value) override;
78 void WriteMetadata(WriteBatch* write_batch,
79 const std::string& id,
80 const std::string& value) override;
81 void WriteGlobalMetadata(WriteBatch* write_batch,
82 const std::string& value) override;
83 void DeleteData(WriteBatch* write_batch, const std::string& id) override;
84 void DeleteMetadata(WriteBatch* write_batch, const std::string& id) override;
85 void DeleteGlobalMetadata(WriteBatch* write_batch) override;
86
87 // Register handler functions.
88 void RegisterReadDataHandler(const ReadDataSignature& handler);
89 void RegisterReadAllDataHandler(const ReadAllDataSignature& handler);
90 void RegisterReadAllMetadataHandler(const ReadAllMetadataSignature& handler);
91 void RegisterCommitWriteBatchHandler(
92 const CommitWriteBatchSignature& handler);
93 void RegisterWriteDataHandler(const WriteRecordSignature& handler);
94 void RegisterWriteMetadataHandler(const WriteRecordSignature& handler);
95 void RegisterWriteGlobalMetadataHandler(
96 const WriteGlobalMetadataSignature& handler);
97 void RegisterDeleteDataHandler(const DeleteRecordSignature& handler);
98 void RegisterDeleteMetadataHandler(const DeleteRecordSignature& handler);
99 void RegisterDeleteGlobalMetadataHandler(
100 const DeleteGlobalMetadataSignature& handler);
101
102 private:
103 ReadDataSignature read_data_handler_;
104 ReadAllDataSignature read_all_data_handler_;
105 ReadAllMetadataSignature read_all_metadata_handler_;
106 CommitWriteBatchSignature commit_write_batch_handler_;
107 WriteRecordSignature write_data_handler_;
108 WriteRecordSignature write_metadata_handler_;
109 WriteGlobalMetadataSignature write_global_metadata_handler_;
110 DeleteRecordSignature delete_data_handler_;
111 DeleteRecordSignature delete_metadata_handler_;
112 DeleteGlobalMetadataSignature delete_global_metadata_handler_;
113 };
114
115 } // namespace syncer_v2
116
117 #endif // SYNC_API_MOCK_MODEL_TYPE_STORE_H_
OLDNEW
« no previous file with comments | « sync/api/metadata_change_list.h ('k') | sync/api/mock_model_type_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698