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_APP_REMOTING_CONNECTION_HELPER_H_
6 #define REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "remoting/test/remote_connection_observer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
25 struct RemoteApplicationDetails
;
26 class TestChromotingClient
;
28 // Allows for custom handling of ExtensionMessage messages.
29 typedef base::Callback
<void(const protocol::ExtensionMessage
& message
)>
30 HostMessageReceivedCallback
;
32 // Creates a connection to a remote host which is available for tests to use.
33 // All callbacks must occur on the same thread the object was created on.
34 class AppRemotingConnectionHelper
35 : public RemoteConnectionObserver
{
37 AppRemotingConnectionHelper(
38 const RemoteApplicationDetails
& application_details
);
39 ~AppRemotingConnectionHelper() override
;
41 // Initialize internal structures.
44 // Starts a connection with the remote host.
45 bool StartConnection();
47 // Stubs used to send messages to the remote host.
48 protocol::ClipboardStub
* clipboard_forwarder();
49 protocol::HostStub
* host_stub();
50 protocol::InputStub
* input_stub();
52 // Setter for |host_message_received_callback_|.
53 void SetHostMessageReceivedCallback(
54 HostMessageReceivedCallback host_message_received_callback
);
56 // Reset |host_message_received_callback_ to null|.
57 void ResetHostMessageReceivedCallback();
60 // RemoteConnectionObserver interface.
61 void ConnectionStateChanged(protocol::ConnectionToHost::State state
,
62 protocol::ErrorCode error_code
) override
;
63 void ConnectionReady(bool ready
) override
;
64 void HostMessageReceived(const protocol::ExtensionMessage
& message
) override
;
66 // Sends client details to the host in order to complete the connection.
67 void SendClientConnectionDetailsToHost();
69 // Handles onWindowAdded messages from the host.
70 void HandleOnWindowAddedMessage(
71 const remoting::protocol::ExtensionMessage
& message
);
73 // Contains the details for the application being tested.
74 const RemoteApplicationDetails
& application_details_
;
76 // Called when an ExtensionMessage is received from the host. Used to
77 // override default message handling.
78 HostMessageReceivedCallback host_message_received_callback_
;
80 // Indicates whether the remote connection is ready to be used for testing.
81 // True when a chromoting connection to the remote host has been established
82 // and the main application window is visible.
83 bool connection_is_ready_for_tests_
;
85 // Used to run the thread's message loop.
86 scoped_ptr
<base::RunLoop
> run_loop_
;
88 // Used for setting timeouts and delays.
89 scoped_ptr
<base::Timer
> timer_
;
91 // Used to ensure RemoteConnectionObserver methods are called on the same
93 base::ThreadChecker thread_checker_
;
95 // Creates and manages the connection to the remote host.
96 scoped_ptr
<TestChromotingClient
> client_
;
98 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectionHelper
);
102 } // namespace remoting
104 #endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_