1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_TEST_TEST_CHROMOTING_CLIENT_H_
6 #define REMOTING_TEST_TEST_CHROMOTING_CLIENT_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "remoting/client/chromoting_client.h"
14 #include "remoting/client/client_user_interface.h"
15 #include "remoting/protocol/clipboard_filter.h"
16 #include "remoting/protocol/cursor_shape_stub.h"
17 #include "remoting/test/remote_connection_observer.h"
18 #include "remoting/test/remote_host_info.h"
23 class XmppSignalStrategy
;
34 // Manages a chromoting connection to a remote host. Destroying a
35 // TestChromotingClient object with an active connection will close it.
36 // Must be used from a thread running an IO message loop.
37 // RemoteConnectionObserver objects must not destroy this class within a
39 class TestChromotingClient
: public ClientUserInterface
,
40 public protocol::ClipboardStub
,
41 public protocol::CursorShapeStub
{
43 TestChromotingClient();
44 ~TestChromotingClient() override
;
46 // Starts a chromoting connection with the specified remote host.
47 void StartConnection(const std::string
& user_name
,
48 const std::string
& access_token
,
49 const RemoteHostInfo
& remote_host_info
);
51 // Ends the current remote connection and updates the connection state.
54 // Stubs used to send messages to the remote host.
55 protocol::ClipboardStub
* clipboard_forwarder() {
56 return chromoting_client_
->clipboard_forwarder();
58 protocol::HostStub
* host_stub() { return chromoting_client_
->host_stub(); }
59 protocol::InputStub
* input_stub() { return chromoting_client_
->input_stub(); }
61 // Registers an observer which will be notfied when remote connection events
62 // occur. Registered Observers must not tear-down this object on receipt of
63 // these callbacks. The callbacks should be used for informational purposes.
64 void AddRemoteConnectionObserver(RemoteConnectionObserver
* observer
);
66 // Unregisters an observerer from notifications for remote connection events.
67 void RemoveRemoteConnectionObserver(RemoteConnectionObserver
* observer
);
69 // Used to set a fake/mock connection object for TestChromotingClient tests.
70 void SetConnectionToHostForTests(
71 scoped_ptr
<protocol::ConnectionToHost
> connection_to_host
);
74 // ClientUserInterface interface.
75 void OnConnectionState(protocol::ConnectionToHost::State state
,
76 protocol::ErrorCode error_code
) override
;
77 void OnConnectionReady(bool ready
) override
;
78 void OnRouteChanged(const std::string
& channel_name
,
79 const protocol::TransportRoute
& route
) override
;
80 void SetCapabilities(const std::string
& capabilities
) override
;
81 void SetPairingResponse(
82 const protocol::PairingResponse
& pairing_response
) override
;
83 void DeliverHostMessage(const protocol::ExtensionMessage
& message
) override
;
84 protocol::ClipboardStub
* GetClipboardStub() override
;
85 protocol::CursorShapeStub
* GetCursorShapeStub() override
;
87 // protocol::ClipboardStub interface.
88 void InjectClipboardEvent(const protocol::ClipboardEvent
& event
) override
;
90 // protocol::CursorShapeStub interface.
91 void SetCursorShape(const protocol::CursorShapeInfo
& cursor_shape
) override
;
93 // Tracks the current connection state.
94 protocol::ConnectionToHost::State connection_to_host_state_
;
96 // Tracks the most recent connection error code seen.
97 protocol::ErrorCode connection_error_code_
;
99 // List of observers which are notified when remote connection events occur.
100 // We specify true below for the 'check_empty' flag so the list will check to
101 // see if all observers have been unregistered when it is destroyed.
102 ObserverList
<RemoteConnectionObserver
, true> connection_observers_
;
104 // ConnectionToHost used by TestChromotingClient tests.
105 scoped_ptr
<protocol::ConnectionToHost
> test_connection_to_host_
;
107 // Creates and manages the connection to the remote host.
108 scoped_ptr
<ChromotingClient
> chromoting_client_
;
110 // Manages the threads and task runners for |chromoting_client_|.
111 scoped_ptr
<ClientContext
> client_context_
;
113 // Processes video packets from the host.
114 scoped_ptr
<VideoRenderer
> video_renderer_
;
116 // Used to establish an XMPP connection with the google talk service.
117 scoped_ptr
<XmppSignalStrategy
> signal_strategy_
;
119 DISALLOW_COPY_AND_ASSIGN(TestChromotingClient
);
123 } // namespace remoting
125 #endif // REMOTING_TEST_TEST_CHROMOTING_CLIENT_H_