Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / sync / test / engine / mock_non_blocking_type_processor_core.h
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_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_
6 #define SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_
7
8 #include <vector>
9
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"
13
14 namespace syncer {
15
16 // Receives and records commit requests sent through the
17 // NonBlockingTypeProcessorCoreInterface.
18 //
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 {
24  public:
25   MockNonBlockingTypeProcessorCore();
26   virtual ~MockNonBlockingTypeProcessorCore();
27
28   // Implementation of NonBlockingTypeProcessorCoreInterface.
29   virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE;
30
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;
37
38   // Functions to produce state as though it came from a real server and had
39   // been filtered through a real NonBlockinTypeProcessorCore.
40
41   // Returns an UpdateResponseData representing an update received from
42   // the server.  Updates server state accordingly.
43   //
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(
48       int64 version_offset,
49       const std::string& tag_hash,
50       const sync_pb::EntitySpecifics& specifics);
51
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);
56
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);
61
62  private:
63   // Generate an ID string.
64   static std::string GenerateId(const std::string& tag_hash);
65
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);
69
70   // A record of past commits requests.
71   std::vector<CommitRequestDataList> commit_request_lists_;
72
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_;
76
77   DISALLOW_COPY_AND_ASSIGN(MockNonBlockingTypeProcessorCore);
78 };
79
80 }  // namespace syncer
81
82 #endif  // SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_