| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_TEST_SYNC_ENGINE_MOCK_SERVER_CONNECTION_H_ | 7 #ifndef CHROME_TEST_SYNC_ENGINE_MOCK_SERVER_CONNECTION_H_ |
| 8 #define CHROME_TEST_SYNC_ENGINE_MOCK_SERVER_CONNECTION_H_ | 8 #define CHROME_TEST_SYNC_ENGINE_MOCK_SERVER_CONNECTION_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 13 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 14 #include "chrome/browser/sync/protocol/sync.pb.h" | 14 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 15 #include "chrome/browser/sync/syncable/directory_manager.h" | 15 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 16 #include "chrome/browser/sync/util/closure.h" |
| 16 | 17 |
| 17 using std::string; | 18 using std::string; |
| 18 using std::vector; | 19 using std::vector; |
| 19 | 20 |
| 20 namespace syncable { | 21 namespace syncable { |
| 21 class DirectoryManager; | 22 class DirectoryManager; |
| 22 class ScopedDirLookup; | 23 class ScopedDirLookup; |
| 23 } | 24 } |
| 24 namespace browser_sync { | 25 namespace browser_sync { |
| 25 struct HttpResponse; | 26 struct HttpResponse; |
| 26 } | 27 } |
| 27 | 28 |
| 28 class MockConnectionManager : public browser_sync::ServerConnectionManager { | 29 class MockConnectionManager : public browser_sync::ServerConnectionManager { |
| 29 public: | 30 public: |
| 30 // A callback function type. These can be set to be called when server | |
| 31 // activity would normally take place. This aids simulation of race | |
| 32 // conditions. | |
| 33 typedef bool (*TestCallbackFunction)(syncable::Directory* dir); | |
| 34 class MidCommitObserver { | 31 class MidCommitObserver { |
| 35 public: | 32 public: |
| 36 virtual void Observe() = 0; | 33 virtual void Observe() = 0; |
| 37 }; | 34 }; |
| 38 | 35 |
| 39 MockConnectionManager(syncable::DirectoryManager* dirmgr, | 36 MockConnectionManager(syncable::DirectoryManager* dirmgr, |
| 40 const std::string& name); | 37 const std::string& name); |
| 41 virtual ~MockConnectionManager(); | 38 virtual ~MockConnectionManager(); |
| 42 | 39 |
| 43 // Overridden ServerConnectionManager functions. | 40 // Overridden ServerConnectionManager functions. |
| 44 virtual bool PostBufferToPath(const PostBufferParams*, | 41 virtual bool PostBufferToPath(const PostBufferParams*, |
| 45 const string& path, | 42 const string& path, |
| 46 const string& auth_token); | 43 const string& auth_token); |
| 47 | 44 |
| 48 virtual bool IsServerReachable(); | 45 virtual bool IsServerReachable(); |
| 49 virtual bool IsUserAuthenticated(); | 46 virtual bool IsUserAuthenticated(); |
| 50 | 47 |
| 51 // Control of commit response. | 48 // Control of commit response. |
| 52 void SetMidCommitCallbackFunction(TestCallbackFunction callback); | 49 void SetMidCommitCallback(Closure* callback); |
| 53 void SetMidCommitObserver(MidCommitObserver* observer); | 50 void SetMidCommitObserver(MidCommitObserver* observer); |
| 54 | 51 |
| 55 // Set this if you want commit to perform commit time rename. Will request | 52 // Set this if you want commit to perform commit time rename. Will request |
| 56 // that the client renames all commited entries, prepending this string. | 53 // that the client renames all commited entries, prepending this string. |
| 57 void SetCommitTimeRename(string prepend); | 54 void SetCommitTimeRename(string prepend); |
| 58 | 55 |
| 59 // Control of get updates response. All updates set will only be returned | 56 // Control of get updates response. All updates set will only be returned |
| 60 // once. This mock object doesn't simulate a changelist, it simulates server | 57 // once. This mock object doesn't simulate a changelist, it simulates server |
| 61 // responses. | 58 // responses. |
| 62 void ResetUpdates(); | 59 void ResetUpdates(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 199 |
| 203 // Fail on the next call to PostBufferToPath(). | 200 // Fail on the next call to PostBufferToPath(). |
| 204 bool fail_next_postbuffer_; | 201 bool fail_next_postbuffer_; |
| 205 | 202 |
| 206 // Our directory. | 203 // Our directory. |
| 207 syncable::DirectoryManager* directory_manager_; | 204 syncable::DirectoryManager* directory_manager_; |
| 208 std::string directory_name_; | 205 std::string directory_name_; |
| 209 | 206 |
| 210 // The updates we'll return to the next request. | 207 // The updates we'll return to the next request. |
| 211 sync_pb::GetUpdatesResponse updates_; | 208 sync_pb::GetUpdatesResponse updates_; |
| 212 TestCallbackFunction mid_commit_callback_function_; | 209 Closure* mid_commit_callback_; |
| 213 MidCommitObserver* mid_commit_observer_; | 210 MidCommitObserver* mid_commit_observer_; |
| 214 | 211 |
| 215 // The AUTHENTICATE response we'll return for auth requests. | 212 // The AUTHENTICATE response we'll return for auth requests. |
| 216 sync_pb::AuthenticateResponse auth_response_; | 213 sync_pb::AuthenticateResponse auth_response_; |
| 217 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. | 214 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. |
| 218 std::string valid_auth_token_; | 215 std::string valid_auth_token_; |
| 219 | 216 |
| 220 // Whether we are faking a server mandating clients to throttle requests. | 217 // Whether we are faking a server mandating clients to throttle requests. |
| 221 // Protected by |throttle_lock_|. | 218 // Protected by |throttle_lock_|. |
| 222 bool throttling_; | 219 bool throttling_; |
| 223 Lock throttle_lock_; | 220 Lock throttle_lock_; |
| 224 | 221 |
| 225 // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests. | 222 // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests. |
| 226 bool fail_non_periodic_get_updates_; | 223 bool fail_non_periodic_get_updates_; |
| 227 | 224 |
| 228 scoped_ptr<sync_pb::ClientCommand> client_command_; | 225 scoped_ptr<sync_pb::ClientCommand> client_command_; |
| 229 | 226 |
| 230 // The next value to use for the position_in_parent property. | 227 // The next value to use for the position_in_parent property. |
| 231 int64 next_position_in_parent_; | 228 int64 next_position_in_parent_; |
| 232 | 229 |
| 233 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); | 230 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); |
| 234 }; | 231 }; |
| 235 | 232 |
| 236 #endif // CHROME_TEST_SYNC_ENGINE_MOCK_SERVER_CONNECTION_H_ | 233 #endif // CHROME_TEST_SYNC_ENGINE_MOCK_SERVER_CONNECTION_H_ |
| OLD | NEW |