OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Mock ServerConnectionManager class for use in client unit tests. | 5 // Mock ServerConnectionManager class for use in client unit tests. |
6 | 6 |
7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 7 #ifndef COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 8 #define COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <bitset> | 12 #include <bitset> |
13 #include <list> | 13 #include <list> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
22 #include "sync/engine/net/server_connection_manager.h" | 22 #include "components/sync/base/model_type.h" |
23 #include "sync/internal_api/public/base/model_type.h" | 23 #include "components/sync/base/unique_position.h" |
24 #include "sync/internal_api/public/base/unique_position.h" | 24 #include "components/sync/engine_impl/net/server_connection_manager.h" |
25 #include "sync/protocol/sync.pb.h" | 25 #include "components/sync/protocol/sync.pb.h" |
26 | 26 |
27 namespace syncer { | 27 namespace syncer { |
28 | 28 |
29 class MockConnectionManager : public ServerConnectionManager { | 29 class MockConnectionManager : public ServerConnectionManager { |
30 public: | 30 public: |
31 class MidCommitObserver { | 31 class MidCommitObserver { |
32 public: | 32 public: |
33 virtual void Observe() = 0; | 33 virtual void Observe() = 0; |
34 | 34 |
35 protected: | 35 protected: |
36 virtual ~MidCommitObserver() {} | 36 virtual ~MidCommitObserver() {} |
37 }; | 37 }; |
38 | 38 |
39 MockConnectionManager(syncable::Directory*, | 39 MockConnectionManager(syncable::Directory*, CancelationSignal* signal); |
40 CancelationSignal* signal); | |
41 ~MockConnectionManager() override; | 40 ~MockConnectionManager() override; |
42 | 41 |
43 // Overridden ServerConnectionManager functions. | 42 // Overridden ServerConnectionManager functions. |
44 bool PostBufferToPath(PostBufferParams*, | 43 bool PostBufferToPath(PostBufferParams*, |
45 const std::string& path, | 44 const std::string& path, |
46 const std::string& auth_token) override; | 45 const std::string& auth_token) override; |
47 | 46 |
48 // Control of commit response. | 47 // Control of commit response. |
49 // NOTE: Commit callback is invoked only once then reset. | 48 // NOTE: Commit callback is invoked only once then reset. |
50 void SetMidCommitCallback(const base::Closure& callback); | 49 void SetMidCommitCallback(const base::Closure& callback); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 194 |
196 // Retrieve the last returned commit response. | 195 // Retrieve the last returned commit response. |
197 const sync_pb::CommitResponse& last_commit_response() const; | 196 const sync_pb::CommitResponse& last_commit_response() const; |
198 | 197 |
199 // Retrieve the last request submitted to the server (regardless of type). | 198 // Retrieve the last request submitted to the server (regardless of type). |
200 const sync_pb::ClientToServerMessage& last_request() const; | 199 const sync_pb::ClientToServerMessage& last_request() const; |
201 | 200 |
202 // Retrieve the cumulative collection of all requests sent by clients. | 201 // Retrieve the cumulative collection of all requests sent by clients. |
203 const std::vector<sync_pb::ClientToServerMessage>& requests() const; | 202 const std::vector<sync_pb::ClientToServerMessage>& requests() const; |
204 | 203 |
205 void set_conflict_all_commits(bool value) { | 204 void set_conflict_all_commits(bool value) { conflict_all_commits_ = value; } |
206 conflict_all_commits_ = value; | 205 void set_next_new_id(int value) { next_new_id_ = value; } |
207 } | 206 void set_conflict_n_commits(int value) { conflict_n_commits_ = value; } |
208 void set_next_new_id(int value) { | |
209 next_new_id_ = value; | |
210 } | |
211 void set_conflict_n_commits(int value) { | |
212 conflict_n_commits_ = value; | |
213 } | |
214 | 207 |
215 void set_use_legacy_bookmarks_protocol(bool value) { | 208 void set_use_legacy_bookmarks_protocol(bool value) { |
216 use_legacy_bookmarks_protocol_ = value; | 209 use_legacy_bookmarks_protocol_ = value; |
217 } | 210 } |
218 | 211 |
219 void set_store_birthday(const std::string& new_birthday) { | 212 void set_store_birthday(const std::string& new_birthday) { |
220 // Multiple threads can set store_birthday_ in our tests, need to lock it to | 213 // Multiple threads can set store_birthday_ in our tests, need to lock it to |
221 // ensure atomic read/writes and avoid race conditions. | 214 // ensure atomic read/writes and avoid race conditions. |
222 base::AutoLock lock(store_birthday_lock_); | 215 base::AutoLock lock(store_birthday_lock_); |
223 store_birthday_ = new_birthday; | 216 store_birthday_ = new_birthday; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 249 |
257 void SetServerStatus(HttpResponse::ServerConnectionCode server_status); | 250 void SetServerStatus(HttpResponse::ServerConnectionCode server_status); |
258 | 251 |
259 // Return by copy to be thread-safe. | 252 // Return by copy to be thread-safe. |
260 const std::string store_birthday() { | 253 const std::string store_birthday() { |
261 base::AutoLock lock(store_birthday_lock_); | 254 base::AutoLock lock(store_birthday_lock_); |
262 return store_birthday_; | 255 return store_birthday_; |
263 } | 256 } |
264 | 257 |
265 // Explicitly indicate that we will not be fetching some updates. | 258 // Explicitly indicate that we will not be fetching some updates. |
266 void ClearUpdatesQueue() { | 259 void ClearUpdatesQueue() { update_queue_.clear(); } |
267 update_queue_.clear(); | |
268 } | |
269 | 260 |
270 // Locate the most recent update message for purpose of alteration. | 261 // Locate the most recent update message for purpose of alteration. |
271 sync_pb::SyncEntity* GetMutableLastUpdate(); | 262 sync_pb::SyncEntity* GetMutableLastUpdate(); |
272 | 263 |
273 // Adds a new progress marker to the last update. | 264 // Adds a new progress marker to the last update. |
274 sync_pb::DataTypeProgressMarker* AddUpdateProgressMarker(); | 265 sync_pb::DataTypeProgressMarker* AddUpdateProgressMarker(); |
275 | 266 |
276 private: | 267 private: |
277 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, | 268 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, |
278 syncable::Id parentid, | 269 syncable::Id parentid, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 306 |
316 // Get a mutable update response which will eventually be returned to the | 307 // Get a mutable update response which will eventually be returned to the |
317 // client. | 308 // client. |
318 sync_pb::GetUpdatesResponse* GetUpdateResponse(); | 309 sync_pb::GetUpdatesResponse* GetUpdateResponse(); |
319 void ApplyToken(); | 310 void ApplyToken(); |
320 | 311 |
321 // Determine whether an progress marker array (like that sent in | 312 // Determine whether an progress marker array (like that sent in |
322 // GetUpdates.from_progress_marker) indicates that a particular ModelType | 313 // GetUpdates.from_progress_marker) indicates that a particular ModelType |
323 // should be included. | 314 // should be included. |
324 bool IsModelTypePresentInSpecifics( | 315 bool IsModelTypePresentInSpecifics( |
325 const google::protobuf::RepeatedPtrField< | 316 const google::protobuf::RepeatedPtrField<sync_pb::DataTypeProgressMarker>& |
326 sync_pb::DataTypeProgressMarker>& filter, | 317 filter, |
327 ModelType value); | 318 ModelType value); |
328 | 319 |
329 sync_pb::DataTypeProgressMarker const* GetProgressMarkerForType( | 320 sync_pb::DataTypeProgressMarker const* GetProgressMarkerForType( |
330 const google::protobuf::RepeatedPtrField< | 321 const google::protobuf::RepeatedPtrField<sync_pb::DataTypeProgressMarker>& |
331 sync_pb::DataTypeProgressMarker>& filter, | 322 filter, |
332 ModelType value); | 323 ModelType value); |
333 | 324 |
334 // When false, we pretend to have network connectivity issues. | 325 // When false, we pretend to have network connectivity issues. |
335 bool server_reachable_; | 326 bool server_reachable_; |
336 | 327 |
337 // All IDs that have been committed. | 328 // All IDs that have been committed. |
338 std::vector<syncable::Id> committed_ids_; | 329 std::vector<syncable::Id> committed_ids_; |
339 | 330 |
340 // List of IDs which should return a transient error. | 331 // List of IDs which should return a transient error. |
341 std::vector<syncable::Id> transient_error_ids_; | 332 std::vector<syncable::Id> transient_error_ids_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 404 |
414 std::string next_token_; | 405 std::string next_token_; |
415 | 406 |
416 std::vector<sync_pb::ClientToServerMessage> requests_; | 407 std::vector<sync_pb::ClientToServerMessage> requests_; |
417 | 408 |
418 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); | 409 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); |
419 }; | 410 }; |
420 | 411 |
421 } // namespace syncer | 412 } // namespace syncer |
422 | 413 |
423 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 414 #endif // COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
OLD | NEW |