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 #ifndef REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ | 5 #ifndef REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ |
6 #define REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ | 6 #define REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
9 | 10 |
| 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/values.h" |
10 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
11 #include "remoting/proto/internal.pb.h" | 15 #include "remoting/proto/internal.pb.h" |
12 #include "remoting/proto/video.pb.h" | 16 #include "remoting/proto/video.pb.h" |
13 #include "remoting/protocol/authenticator.h" | 17 #include "remoting/protocol/authenticator.h" |
14 #include "remoting/protocol/client_stub.h" | 18 #include "remoting/protocol/client_stub.h" |
15 #include "remoting/protocol/clipboard_stub.h" | 19 #include "remoting/protocol/clipboard_stub.h" |
16 #include "remoting/protocol/connection_to_client.h" | 20 #include "remoting/protocol/connection_to_client.h" |
17 #include "remoting/protocol/host_stub.h" | 21 #include "remoting/protocol/host_stub.h" |
18 #include "remoting/protocol/input_stub.h" | 22 #include "remoting/protocol/input_stub.h" |
19 #include "remoting/protocol/pairing_registry.h" | 23 #include "remoting/protocol/pairing_registry.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 private: | 208 private: |
205 DISALLOW_COPY_AND_ASSIGN(MockSessionManager); | 209 DISALLOW_COPY_AND_ASSIGN(MockSessionManager); |
206 }; | 210 }; |
207 | 211 |
208 // Simple delegate that caches information on paired clients in memory. | 212 // Simple delegate that caches information on paired clients in memory. |
209 class MockPairingRegistryDelegate : public PairingRegistry::Delegate { | 213 class MockPairingRegistryDelegate : public PairingRegistry::Delegate { |
210 public: | 214 public: |
211 MockPairingRegistryDelegate(); | 215 MockPairingRegistryDelegate(); |
212 virtual ~MockPairingRegistryDelegate(); | 216 virtual ~MockPairingRegistryDelegate(); |
213 | 217 |
214 const std::string& pairings_json() const { | |
215 return pairings_json_; | |
216 } | |
217 | |
218 // PairingRegistry::Delegate implementation. | 218 // PairingRegistry::Delegate implementation. |
219 virtual void Save( | 219 virtual scoped_ptr<base::ListValue> LoadAll() OVERRIDE; |
220 const std::string& pairings_json, | 220 virtual bool DeleteAll() OVERRIDE; |
221 const PairingRegistry::SaveCallback& callback) OVERRIDE; | 221 virtual protocol::PairingRegistry::Pairing Load( |
222 virtual void Load( | 222 const std::string& client_id) OVERRIDE; |
223 const PairingRegistry::LoadCallback& callback) OVERRIDE; | 223 virtual bool Save(const protocol::PairingRegistry::Pairing& pairing) OVERRIDE; |
224 | 224 virtual bool Delete(const std::string& client_id) OVERRIDE; |
225 // By default, the Save method runs its callback automatically because the | |
226 // negotiating authenticator unit test does not provide any hooks to do it | |
227 // manually. For unit tests that need to verify correct behaviour under | |
228 // asynchronous conditions, use this method to disable this feature and call | |
229 // RunCallback as appropriate. | |
230 void set_run_save_callback_automatically( | |
231 bool run_save_callback_automatically) { | |
232 run_save_callback_automatically_ = run_save_callback_automatically; | |
233 } | |
234 | |
235 bool HasCallback() const { | |
236 return !load_callback_.is_null() || !save_callback_.is_null(); | |
237 } | |
238 | |
239 // Run either the save or the load callback (whichever was set most recently; | |
240 // it is an error for both of these to be set at the same time). | |
241 void RunCallback(); | |
242 | 225 |
243 private: | 226 private: |
244 void SetPairingsJsonAndRunCallback( | 227 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings; |
245 const std::string& pairings_json, | 228 Pairings pairings_; |
246 const PairingRegistry::SaveCallback& callback); | 229 }; |
247 | 230 |
248 base::Closure load_callback_; | 231 class SynchronousPairingRegistry : public PairingRegistry { |
249 base::Closure save_callback_; | 232 public: |
250 std::string pairings_json_; | 233 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate); |
251 bool run_save_callback_automatically_; | 234 |
| 235 protected: |
| 236 virtual ~SynchronousPairingRegistry(); |
| 237 |
| 238 // Runs tasks synchronously instead of posting them to |task_runner|. |
| 239 virtual void PostTask( |
| 240 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 241 const tracked_objects::Location& from_here, |
| 242 const base::Closure& task) OVERRIDE; |
252 }; | 243 }; |
253 | 244 |
254 } // namespace protocol | 245 } // namespace protocol |
255 } // namespace remoting | 246 } // namespace remoting |
256 | 247 |
257 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ | 248 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_ |
OLD | NEW |