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

Side by Side Diff: sync/test/engine/single_type_mock_server.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/test/engine/mock_update_handler.cc ('k') | sync/test/engine/single_type_mock_server.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 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_SINGLE_TYPE_MOCK_SERVER_H_
6 #define SYNC_TEST_ENGINE_SINGLE_TYPE_MOCK_SERVER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <string>
13 #include <vector>
14
15 #include "base/macros.h"
16 #include "sync/internal_api/public/base/model_type.h"
17 #include "sync/internal_api/public/non_blocking_sync_common.h"
18
19 namespace syncer {
20
21 // A mock server used to test of happy-path update and commit logic.
22 //
23 // This object supports only one ModelType, which must be specified at
24 // initialization time. It does not support GetUpdates messages. It does not
25 // support simulated errors.
26 //
27 // This class is useful for testing UpdateHandlers and CommitContributors.
28 class SingleTypeMockServer {
29 public:
30 explicit SingleTypeMockServer(syncer::ModelType type);
31 ~SingleTypeMockServer();
32
33 // Generates a SyncEntity representing a server-delivered update containing
34 // the root node for this SingleTypeMockServer's type.
35 sync_pb::SyncEntity TypeRootUpdate();
36
37 // Generates a SyncEntity representing a server-delivered update.
38 //
39 // The |version_offset| parameter allows the caller to simulate reflected
40 // updates, redeliveries, and genuine updates.
41 sync_pb::SyncEntity UpdateFromServer(
42 int64_t version_offset,
43 const std::string& tag_hash,
44 const sync_pb::EntitySpecifics& specifics);
45
46 // Generates a SyncEntity representing a server-delivered update to delete
47 // an item.
48 sync_pb::SyncEntity TombstoneFromServer(int64_t version_offset,
49 const std::string& tag_hash);
50
51 // Generates a response to the specified commit message.
52 //
53 // This does not perform any exhausive testing of the sync protocol. Many of
54 // the request's fields may safely be left blank, and much of the returned
55 // response will be empty, too.
56 //
57 // This is useful mainly for testing objects that implement the
58 // CommitContributor interface.
59 sync_pb::ClientToServerResponse DoSuccessfulCommit(
60 const sync_pb::ClientToServerMessage& message);
61
62 // Getters to return the commit messages sent to the server through
63 // DoSuccessfulCommit().
64 size_t GetNumCommitMessages() const;
65 sync_pb::ClientToServerMessage GetNthCommitMessage(size_t n) const;
66
67 // Getters to return the most recently committed entities for a given
68 // unique_client_tag hash.
69 bool HasCommitEntity(const std::string& tag_hash) const;
70 sync_pb::SyncEntity GetLastCommittedEntity(const std::string& tag_hash) const;
71
72 // Getters that create realistic-looking progress markers and data type
73 // context.
74 sync_pb::DataTypeProgressMarker GetProgress() const;
75 sync_pb::DataTypeContext GetContext() const;
76
77 private:
78 static std::string GenerateId(const std::string& tag_hash);
79
80 // Get and set our emulated server state.
81 int64_t GetServerVersion(const std::string& tag_hash) const;
82 void SetServerVersion(const std::string& tag_hash, int64_t version);
83
84 const ModelType type_;
85 const std::string type_root_id_;
86
87 // Server version state maps.
88 std::map<const std::string, int64_t> server_versions_;
89
90 // Log of messages sent to the server.
91 std::vector<sync_pb::ClientToServerMessage> commit_messages_;
92
93 // Map of most recent commits by tag_hash.
94 std::map<const std::string, sync_pb::SyncEntity> committed_items_;
95
96 DISALLOW_COPY_AND_ASSIGN(SingleTypeMockServer);
97 };
98
99 } // namespace syncer
100
101 #endif // SYNC_TEST_ENGINE_SINGLE_TYPE_MOCK_SERVER_H_
OLDNEW
« no previous file with comments | « sync/test/engine/mock_update_handler.cc ('k') | sync/test/engine/single_type_mock_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698