| 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_FAKE_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_FAKE_SESSION_H_ |
| 6 #define REMOTING_PROTOCOL_FAKE_SESSION_H_ | 6 #define REMOTING_PROTOCOL_FAKE_SESSION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/protocol/fake_stream_socket.h" | 14 #include "remoting/protocol/fake_stream_socket.h" |
| 15 #include "remoting/protocol/session.h" | 15 #include "remoting/protocol/session.h" |
| 16 #include "remoting/protocol/transport.h" | 16 #include "remoting/protocol/transport.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 namespace protocol { | 19 namespace protocol { |
| 20 | 20 |
| 21 extern const char kTestJid[]; | 21 extern const char kTestJid[]; |
| 22 | 22 |
| 23 class FakeTransport : public Transport { | 23 class FakeAuthenticator; |
| 24 public: | |
| 25 FakeTransport(); | |
| 26 ~FakeTransport() override; | |
| 27 | 24 |
| 28 // Transport interface. | |
| 29 void Start(EventHandler* event_handler, | |
| 30 Authenticator* authenticator) override; | |
| 31 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; | |
| 32 FakeStreamChannelFactory* GetStreamChannelFactory() override; | |
| 33 FakeStreamChannelFactory* GetMultiplexedChannelFactory() override; | |
| 34 | |
| 35 private: | |
| 36 FakeStreamChannelFactory channel_factory_; | |
| 37 }; | |
| 38 | |
| 39 // FakeSession is a dummy protocol::Session that uses FakeStreamSocket for all | |
| 40 // channels. | |
| 41 class FakeSession : public Session { | 25 class FakeSession : public Session { |
| 42 public: | 26 public: |
| 43 FakeSession(); | 27 FakeSession(); |
| 44 ~FakeSession() override; | 28 ~FakeSession() override; |
| 45 | 29 |
| 46 void SimulateConnection(FakeSession* peer); | 30 void SimulateConnection(FakeSession* peer); |
| 47 | 31 |
| 48 EventHandler* event_handler() { return event_handler_; } | 32 EventHandler* event_handler() { return event_handler_; } |
| 49 void set_error(ErrorCode error) { error_ = error; } | 33 void set_error(ErrorCode error) { error_ = error; } |
| 50 bool is_closed() const { return closed_; } | 34 bool is_closed() const { return closed_; } |
| 51 | 35 |
| 52 // Session interface. | 36 // Session interface. |
| 53 void SetEventHandler(EventHandler* event_handler) override; | 37 void SetEventHandler(EventHandler* event_handler) override; |
| 54 ErrorCode error() override; | 38 ErrorCode error() override; |
| 55 const std::string& jid() override; | 39 const std::string& jid() override; |
| 56 const SessionConfig& config() override; | 40 const SessionConfig& config() override; |
| 57 FakeTransport* GetTransport() override; | 41 void SetTransport(Transport* transport) override; |
| 58 void Close(ErrorCode error) override; | 42 void Close(ErrorCode error) override; |
| 59 | 43 |
| 60 private: | 44 private: |
| 45 // Callback provided to the |transport_|. |
| 46 void SendTransportInfo(scoped_ptr<buzz::XmlElement> transport_info); |
| 47 |
| 61 EventHandler* event_handler_ = nullptr; | 48 EventHandler* event_handler_ = nullptr; |
| 62 scoped_ptr<SessionConfig> config_; | 49 scoped_ptr<SessionConfig> config_; |
| 63 | 50 |
| 64 std::string jid_; | 51 std::string jid_; |
| 65 | 52 |
| 66 FakeTransport transport_; | 53 scoped_ptr<FakeAuthenticator> authenticator_; |
| 54 Transport* transport_; |
| 67 | 55 |
| 68 ErrorCode error_ = OK; | 56 ErrorCode error_ = OK; |
| 69 bool closed_ = false; | 57 bool closed_ = false; |
| 70 | 58 |
| 71 base::WeakPtr<FakeSession> peer_; | 59 base::WeakPtr<FakeSession> peer_; |
| 72 | 60 |
| 73 base::WeakPtrFactory<FakeSession> weak_factory_; | 61 base::WeakPtrFactory<FakeSession> weak_factory_; |
| 74 | 62 |
| 75 DISALLOW_COPY_AND_ASSIGN(FakeSession); | 63 DISALLOW_COPY_AND_ASSIGN(FakeSession); |
| 76 }; | 64 }; |
| 77 | 65 |
| 78 } // namespace protocol | 66 } // namespace protocol |
| 79 } // namespace remoting | 67 } // namespace remoting |
| 80 | 68 |
| 81 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ | 69 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ |
| OLD | NEW |