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

Side by Side Diff: sync/test/engine/mock_model_type_worker.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
OLDNEW
(Empty)
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.
4
5 #ifndef SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_WORKER_H_
6 #define SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_WORKER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <deque>
12 #include <map>
13 #include <string>
14 #include <vector>
15
16 #include "base/macros.h"
17 #include "sync/engine/commit_queue.h"
18 #include "sync/internal_api/public/model_type_processor.h"
19 #include "sync/internal_api/public/non_blocking_sync_common.h"
20 #include "sync/protocol/data_type_state.pb.h"
21
22 namespace syncer_v2 {
23
24 // Receives and records commit requests sent through the ModelTypeWorker.
25 //
26 // This class also includes features intended to help mock out server behavior.
27 // It has some basic functionality to keep track of server state and generate
28 // plausible UpdateResponseData and CommitResponseData messages.
29 class MockModelTypeWorker : public CommitQueue {
30 public:
31 MockModelTypeWorker(const sync_pb::DataTypeState& data_type_state,
32 ModelTypeProcessor* processor);
33 ~MockModelTypeWorker() override;
34
35 // Implementation of ModelTypeWorker.
36 void EnqueueForCommit(const CommitRequestDataList& list) override;
37
38 // Getters to inspect the requests sent to this object.
39 size_t GetNumPendingCommits() const;
40 CommitRequestDataList GetNthPendingCommit(size_t n) const;
41 bool HasPendingCommitForTag(const std::string& tag) const;
42 CommitRequestData GetLatestPendingCommitForTag(const std::string& tag) const;
43
44 // Expect that the |n|th commit request list has one commit request for |tag|
45 // with |value| set.
46 void ExpectNthPendingCommit(size_t n,
47 const std::string& tag,
48 const std::string& value);
49
50 // For each tag in |tags|, expect a corresponding request list of length one.
51 void ExpectPendingCommits(const std::vector<std::string>& tags);
52
53 // Trigger an update from the server containing a single entity. See
54 // GenerateUpdateData for parameter descriptions. |version_offset| defaults to
55 // 1 and |ekn| defaults to the current encryption key name the worker has.
56 void UpdateFromServer(const std::string& tag, const std::string& value);
57 void UpdateFromServer(const std::string& tag,
58 const std::string& value,
59 int64_t version_offset);
60 void UpdateFromServer(const std::string& tag,
61 const std::string& value,
62 int64_t version_offset,
63 const std::string& ekn);
64
65 // Returns an UpdateResponseData representing an update received from
66 // the server. Updates server state accordingly. |tag| is used to generate the
67 // tag hash and the specifics along with |value|.
68 //
69 // The |version_offset| field can be used to emulate stale data (ie. versions
70 // going backwards), reflections and redeliveries (ie. several instances of
71 // the same version) or new updates.
72 //
73 // |ekn| is the encryption key name this item will fake having.
74 UpdateResponseData GenerateUpdateData(const std::string& tag,
75 const std::string& value,
76 int64_t version_offset,
77 const std::string& ekn);
78
79 // Triggers a server-side deletion of the entity with |tag|; updates server
80 // state accordingly.
81 void TombstoneFromServer(const std::string& tag);
82
83 // Pops one pending commit from the front of the queue and send a commit
84 // response to the processor for it.
85 void AckOnePendingCommit();
86
87 // Set the encryption key to |ekn| and inform the processor with an update
88 // containing the data in |update|, which defaults to an empty list.
89 void UpdateWithEncryptionKey(const std::string& ekn);
90 void UpdateWithEncryptionKey(const std::string& ekn,
91 const UpdateResponseDataList& update);
92
93 private:
94 // Generate an ID string.
95 static std::string GenerateId(const std::string& tag_hash);
96
97 // Returns a commit response that indicates a successful commit of the
98 // given |request_data|. Updates server state accordingly.
99 CommitResponseData SuccessfulCommitResponse(
100 const CommitRequestData& request_data);
101
102 // Retrieve or set the server version.
103 int64_t GetServerVersion(const std::string& tag_hash);
104 void SetServerVersion(const std::string& tag_hash, int64_t version);
105
106 sync_pb::DataTypeState data_type_state_;
107
108 // A pointer to the processor for this mock worker.
109 ModelTypeProcessor* processor_;
110
111 // A record of past commits requests.
112 std::deque<CommitRequestDataList> pending_commits_;
113
114 // Map of versions by client tag.
115 // This is an essential part of the mocked server state.
116 std::map<const std::string, int64_t> server_versions_;
117
118 DISALLOW_COPY_AND_ASSIGN(MockModelTypeWorker);
119 };
120
121 } // namespace syncer_v2
122
123 #endif // SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_WORKER_H_
OLDNEW
« no previous file with comments | « sync/test/engine/mock_model_type_processor.cc ('k') | sync/test/engine/mock_model_type_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698