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

Side by Side Diff: chrome/browser/sync/test/engine/mock_connection_manager.h

Issue 9348036: Trim code from sync's ServerConnectionManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Delete some more code Created 8 years, 10 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
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 CHROME_BROWSER_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 7 #ifndef CHROME_BROWSER_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
8 #define CHROME_BROWSER_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 8 #define CHROME_BROWSER_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
9 #pragma once 9 #pragma once
10 10
(...skipping 29 matching lines...) Expand all
40 const std::string& name); 40 const std::string& name);
41 virtual ~MockConnectionManager(); 41 virtual ~MockConnectionManager();
42 42
43 // Overridden ServerConnectionManager functions. 43 // Overridden ServerConnectionManager functions.
44 virtual bool PostBufferToPath( 44 virtual bool PostBufferToPath(
45 PostBufferParams*, 45 PostBufferParams*,
46 const std::string& path, 46 const std::string& path,
47 const std::string& auth_token, 47 const std::string& auth_token,
48 browser_sync::ScopedServerStatusWatcher* watcher) OVERRIDE; 48 browser_sync::ScopedServerStatusWatcher* watcher) OVERRIDE;
49 49
50 virtual bool IsServerReachable() OVERRIDE;
51 virtual bool IsUserAuthenticated() OVERRIDE;
52
53 // Control of commit response. 50 // Control of commit response.
54 void SetMidCommitCallback(const base::Closure& callback); 51 void SetMidCommitCallback(const base::Closure& callback);
55 void SetMidCommitObserver(MidCommitObserver* observer); 52 void SetMidCommitObserver(MidCommitObserver* observer);
56 53
57 // Set this if you want commit to perform commit time rename. Will request 54 // Set this if you want commit to perform commit time rename. Will request
58 // that the client renames all commited entries, prepending this string. 55 // that the client renames all commited entries, prepending this string.
59 void SetCommitTimeRename(std::string prepend); 56 void SetCommitTimeRename(std::string prepend);
60 57
61 // Generic versions of AddUpdate functions. Tests using these function should 58 // Generic versions of AddUpdate functions. Tests using these function should
62 // compile for both the int64 and string id based versions of the server. 59 // compile for both the int64 and string id based versions of the server.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 const std::string& entry_id); 116 const std::string& entry_id);
120 void SetLastUpdatePosition(int64 position_in_parent); 117 void SetLastUpdatePosition(int64 position_in_parent);
121 void SetNewTimestamp(int ts); 118 void SetNewTimestamp(int ts);
122 void SetChangesRemaining(int64 count); 119 void SetChangesRemaining(int64 count);
123 120
124 // Add a new batch of updates after the current one. Allows multiple 121 // Add a new batch of updates after the current one. Allows multiple
125 // GetUpdates responses to be buffered up, since the syncer may 122 // GetUpdates responses to be buffered up, since the syncer may
126 // issue multiple requests during a sync cycle. 123 // issue multiple requests during a sync cycle.
127 void NextUpdateBatch(); 124 void NextUpdateBatch();
128 125
129 // For AUTHENTICATE responses.
130 void SetAuthenticationResponseInfo(const std::string& valid_auth_token,
131 const std::string& user_display_name,
132 const std::string& user_display_email,
133 const std::string& user_obfuscated_id);
134
135 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } 126 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; }
136 127
137 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype); 128 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype);
138 129
139 // A visitor class to allow a test to change some monitoring state atomically 130 // A visitor class to allow a test to change some monitoring state atomically
140 // with the action of overriding the response codes sent back to the Syncer 131 // with the action of overriding the response codes sent back to the Syncer
141 // (for example, so you can say "ThrottleNextRequest, and assert no more 132 // (for example, so you can say "ThrottleNextRequest, and assert no more
142 // requests are made once throttling is in effect" in one step. 133 // requests are made once throttling is in effect" in one step.
143 class ResponseCodeOverrideRequestor { 134 class ResponseCodeOverrideRequestor {
144 public: 135 public:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 209
219 void ExpectGetUpdatesRequestPayloads( 210 void ExpectGetUpdatesRequestPayloads(
220 const syncable::ModelTypePayloadMap& payloads) { 211 const syncable::ModelTypePayloadMap& payloads) {
221 expected_payloads_ = payloads; 212 expected_payloads_ = payloads;
222 } 213 }
223 214
224 void SetServerReachable(); 215 void SetServerReachable();
225 216
226 void SetServerNotReachable(); 217 void SetServerNotReachable();
227 218
219 // Updates our internal state as if we had attempted a connection. Does not
220 // send notifications as a real connection attempt would. This is useful in
221 // cases where we're mocking out most of the code that performs network
222 // requests.
223 void UpdateConnectionStatus();
224
228 // Return by copy to be thread-safe. 225 // Return by copy to be thread-safe.
229 const std::string store_birthday() { 226 const std::string store_birthday() {
230 base::AutoLock lock(store_birthday_lock_); 227 base::AutoLock lock(store_birthday_lock_);
231 return store_birthday_; 228 return store_birthday_;
232 } 229 }
233 230
234 // Locate the most recent update message for purpose of alteration. 231 // Locate the most recent update message for purpose of alteration.
235 sync_pb::SyncEntity* GetMutableLastUpdate(); 232 sync_pb::SyncEntity* GetMutableLastUpdate();
236 233
237 private: 234 private:
238 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, 235 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid,
239 std::string name, int64 version, 236 std::string name, int64 version,
240 int64 sync_ts, 237 int64 sync_ts,
241 bool is_dir); 238 bool is_dir);
242 sync_pb::SyncEntity* AddUpdateFull(std::string id, 239 sync_pb::SyncEntity* AddUpdateFull(std::string id,
243 std::string parentid, std::string name, 240 std::string parentid, std::string name,
244 int64 version, int64 sync_ts, 241 int64 version, int64 sync_ts,
245 bool is_dir); 242 bool is_dir);
246 sync_pb::SyncEntity* AddUpdateMeta(std::string id, std::string parentid, 243 sync_pb::SyncEntity* AddUpdateMeta(std::string id, std::string parentid,
247 std::string name, int64 version, 244 std::string name, int64 version,
248 int64 sync_ts); 245 int64 sync_ts);
249 246
250 // Functions to handle the various types of server request. 247 // Functions to handle the various types of server request.
251 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm, 248 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm,
252 sync_pb::ClientToServerResponse* response); 249 sync_pb::ClientToServerResponse* response);
253 void ProcessAuthenticate(sync_pb::ClientToServerMessage* csm,
254 sync_pb::ClientToServerResponse* response,
255 const std::string& auth_token);
256 void ProcessCommit(sync_pb::ClientToServerMessage* csm, 250 void ProcessCommit(sync_pb::ClientToServerMessage* csm,
257 sync_pb::ClientToServerResponse* response_buffer); 251 sync_pb::ClientToServerResponse* response_buffer);
258 void ProcessClearData(sync_pb::ClientToServerMessage* csm, 252 void ProcessClearData(sync_pb::ClientToServerMessage* csm,
259 sync_pb::ClientToServerResponse* response); 253 sync_pb::ClientToServerResponse* response);
260 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder); 254 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder);
261 255
262 // Determine if one entry in a commit should be rejected with a conflict. 256 // Determine if one entry in a commit should be rejected with a conflict.
263 bool ShouldConflictThisCommit(); 257 bool ShouldConflictThisCommit();
264 258
265 // Generate a numeric position_in_parent value. We use a global counter 259 // Generate a numeric position_in_parent value. We use a global counter
(...skipping 14 matching lines...) Expand all
280 bool IsModelTypePresentInSpecifics( 274 bool IsModelTypePresentInSpecifics(
281 const google::protobuf::RepeatedPtrField< 275 const google::protobuf::RepeatedPtrField<
282 sync_pb::DataTypeProgressMarker>& filter, 276 sync_pb::DataTypeProgressMarker>& filter,
283 syncable::ModelType value); 277 syncable::ModelType value);
284 278
285 sync_pb::DataTypeProgressMarker const* GetProgressMarkerForType( 279 sync_pb::DataTypeProgressMarker const* GetProgressMarkerForType(
286 const google::protobuf::RepeatedPtrField< 280 const google::protobuf::RepeatedPtrField<
287 sync_pb::DataTypeProgressMarker>& filter, 281 sync_pb::DataTypeProgressMarker>& filter,
288 syncable::ModelType value); 282 syncable::ModelType value);
289 283
284 // When false, we pretend to have network connectivity issues.
285 bool server_reachable_;
286
290 // All IDs that have been committed. 287 // All IDs that have been committed.
291 std::vector<syncable::Id> committed_ids_; 288 std::vector<syncable::Id> committed_ids_;
292 289
293 // Control of when/if we return conflicts. 290 // Control of when/if we return conflicts.
294 bool conflict_all_commits_; 291 bool conflict_all_commits_;
295 int conflict_n_commits_; 292 int conflict_n_commits_;
296 293
297 // Commit messages we've sent, and responses we've returned. 294 // Commit messages we've sent, and responses we've returned.
298 ScopedVector<sync_pb::CommitMessage> commit_messages_; 295 ScopedVector<sync_pb::CommitMessage> commit_messages_;
299 ScopedVector<sync_pb::CommitResponse> commit_responses_; 296 ScopedVector<sync_pb::CommitResponse> commit_responses_;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 int num_get_updates_requests_; 356 int num_get_updates_requests_;
360 357
361 std::string next_token_; 358 std::string next_token_;
362 359
363 sync_pb::ClientToServerMessage last_request_; 360 sync_pb::ClientToServerMessage last_request_;
364 361
365 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); 362 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager);
366 }; 363 };
367 364
368 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 365 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698