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

Side by Side Diff: sync/test/engine/simple_mock_server.h

Issue 330523002: sync: Refactor NonBlockingTypeProcessorCore tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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.
Nicolas Zea 2014/06/13 21:59:43 no ifdef header guards? I thought the presubmit ch
rlarocque 2014/06/14 00:55:19 I don't know how the presubmit missed it. Fixed.
4
5 #include "sync/engine/non_blocking_sync_common.h"
6
7 #include "sync/internal_api/public/base/model_type.h"
8
9 namespace syncer {
10
11 // A mock server used to test of happy-path update and commit logic.
12 //
13 // This object supports only one ModelType, which must be specified at
14 // initialization time. It does not support GetUpdates messages. It does not
15 // support simulated errors.
16 //
17 // This class is useful for testing UpdateHandlers and CommitContributors.
18 class SimpleMockServer {
Nicolas Zea 2014/06/13 21:59:43 Are there plans to have other kinds of mock server
rlarocque 2014/06/14 00:55:19 There's MockConnectionManager, which probably dese
Nicolas Zea 2014/06/16 21:12:58 I'm good with SingleTypeMockServer
19 public:
20 SimpleMockServer(syncer::ModelType type);
Nicolas Zea 2014/06/13 21:59:43 nit: explicit
rlarocque 2014/06/14 00:55:19 Done.
21 ~SimpleMockServer();
22
23 // Generates a SyncEntity representing a server-delivered update containing
24 // the root node for this SimpleMockServer's type.
25 sync_pb::SyncEntity TypeRootUpdate();
26
27 // Generates a SyncEntity representing a server-delivered update.
28 //
29 // The |version_offset| parameter allows the caller to simulate reflected
30 // updates, redeliveries, and genuine updates.
31 sync_pb::SyncEntity UpdateFromServer(
32 int64 version_offset,
33 const std::string& tag_hash,
34 const sync_pb::EntitySpecifics& specifics);
35
36 // Generates a SyncEntity representing a server-delivered update to delete
37 // an item.
38 sync_pb::SyncEntity TombstoneFromServer(int64 version_offset,
39 const std::string& tag_hash);
40
41 // Generates a response to the specified commit message.
42 //
43 // This does not perform any exhausive testing of the sync protocol. Many of
44 // the request's fields may safely be left blank, and much of the returned
45 // response will be empty, too.
46 //
47 // This is useful mainly for testing objects that implement the
48 // CommitContributor interface.
49 sync_pb::ClientToServerResponse DoSuccessfulCommit(
50 const sync_pb::ClientToServerMessage& message);
51
52 // Getters to return the commit messages sent to the server through
53 // DoSuccessfulCommit().
54 size_t GetNumCommitMessages() const;
55 sync_pb::ClientToServerMessage GetNthCommitMessage(size_t n) const;
56
57 // Getters to return the most recently committed entities for a given
58 // unique_client_tag hash.
59 bool HasCommitEntity(const std::string& tag_hash) const;
60 sync_pb::SyncEntity GetLastCommittedEntity(const std::string& tag_hash) const;
61
62 // Getters that create realistic-looking progress markers and data type
63 // context.
64 sync_pb::DataTypeProgressMarker GetProgress() const;
65 sync_pb::DataTypeContext GetContext() const;
66
67 private:
68 static std::string GenerateId(const std::string& tag_hash);
69
70 // Get and set our emulated server state.
71 int64 GetServerVersion(const std::string& tag_hash) const;
72 void SetServerVersion(const std::string& tag_hash, int64 version);
73
74 const ModelType type_;
75 const std::string type_root_id_;
76
77 // Server version state maps.
78 std::map<const std::string, int64> server_versions_;
79
80 // Log of messages sent to the server.
81 std::vector<sync_pb::ClientToServerMessage> commit_messages_;
82
83 // Map of most recent commits by tag_hash.
84 std::map<const std::string, sync_pb::SyncEntity> committed_items_;
Nicolas Zea 2014/06/13 21:59:42 disallow copy and assign
rlarocque 2014/06/14 00:55:19 Done.
85 };
86
87 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698