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.
5 #ifndef SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_
6 #define SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_
10 #include "base/macros.h"
11 #include "sync/engine/non_blocking_sync_common.h"
12 #include "sync/engine/non_blocking_type_processor_core_interface.h"
16 // Receives and records commit requests sent through the
17 // NonBlockingTypeProcessorCoreInterface.
19 // This class also includes features intended to help mock out server behavior.
20 // It has some basic functionality to keep track of server state and generate
21 // plausible UpdateResponseData and CommitResponseData messages.
22 class MockNonBlockingTypeProcessorCore
23 : public NonBlockingTypeProcessorCoreInterface {
25 MockNonBlockingTypeProcessorCore();
26 virtual ~MockNonBlockingTypeProcessorCore();
28 // Implementation of NonBlockingTypeProcessorCoreInterface.
29 virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE;
31 // Getters to inspect the requests sent to this object.
32 size_t GetNumCommitRequestLists() const;
33 CommitRequestDataList GetNthCommitRequestList(size_t n) const;
34 bool HasCommitRequestForTagHash(const std::string& tag_hash) const;
35 CommitRequestData GetLatestCommitRequestForTagHash(
36 const std::string& tag_hash) const;
38 // Functions to produce state as though it came from a real server and had
39 // been filtered through a real NonBlockinTypeProcessorCore.
41 // Returns an UpdateResponseData representing an update received from
42 // the server. Updates server state accordingly.
44 // The |version_offset| field can be used to emulate stale data (ie. versions
45 // going backwards), reflections and redeliveries (ie. several instances of
46 // the same version) or new updates.
47 UpdateResponseData UpdateFromServer(
49 const std::string& tag_hash,
50 const sync_pb::EntitySpecifics& specifics);
52 // Returns an UpdateResponseData representing a tombstone update from the
53 // server. Updates server state accordingly.
54 UpdateResponseData TombstoneFromServer(int64 version_offset,
55 const std::string& tag_hash);
57 // Returns a commit response that indicates a successful commit of the
58 // given |request_data|. Updates server state accordingly.
59 CommitResponseData SuccessfulCommitResponse(
60 const CommitRequestData& request_data);
63 // Generate an ID string.
64 static std::string GenerateId(const std::string& tag_hash);
66 // Retrieve or set the server version.
67 int64 GetServerVersion(const std::string& tag_hash);
68 void SetServerVersion(const std::string& tag_hash, int64 version);
70 // A record of past commits requests.
71 std::vector<CommitRequestDataList> commit_request_lists_;
73 // Map of versions by client tag.
74 // This is an essential part of the mocked server state.
75 std::map<const std::string, int64> server_versions_;
77 DISALLOW_COPY_AND_ASSIGN(MockNonBlockingTypeProcessorCore);
82 #endif // SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_