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 // Creates a connection to a remote host which is available for tests to use.
29 // A TestChromotingClient is required from caller.
30 class AppRemotingConnectionHelper
31 : public RemoteConnectionObserver
{
33 explicit AppRemotingConnectionHelper(
34 const RemoteApplicationDetails
& application_details
);
35 ~AppRemotingConnectionHelper() override
;
37 // Initialize internal structures.
38 void Initialize(scoped_ptr
<TestChromotingClient
> test_chromoting_client
);
40 // Starts a connection with the remote host.
41 // NOTE: Initialize() must be called before calling this method.
42 bool StartConnection();
44 // Stubs used to send messages to the remote host.
45 protocol::ClipboardStub
* clipboard_forwarder();
46 protocol::HostStub
* host_stub();
47 protocol::InputStub
* input_stub();
49 TestChromotingClient
* test_chromoting_client() { return client_
.get(); }
51 // Returns true if connection is ready for tests.
52 bool ConnectionIsReadyForTest() { return connection_is_ready_for_tests_
; }
55 // RemoteConnectionObserver interface.
56 void ConnectionStateChanged(protocol::ConnectionToHost::State state
,
57 protocol::ErrorCode error_code
) override
;
58 void ConnectionReady(bool ready
) override
;
59 void HostMessageReceived(const protocol::ExtensionMessage
& message
) override
;
61 // Sends client details to the host in order to complete the connection.
62 void SendClientConnectionDetailsToHost();
64 // Handles onWindowAdded messages from the host.
65 void HandleOnWindowAddedMessage(
66 const remoting::protocol::ExtensionMessage
& message
);
68 // Contains the details for the application being tested.
69 const RemoteApplicationDetails
& application_details_
;
71 // Indicates whether the remote connection is ready to be used for testing.
72 // True when a chromoting connection to the remote host has been established
73 // and the main application window is visible.
74 bool connection_is_ready_for_tests_
;
76 // Used to run the thread's message loop.
77 scoped_ptr
<base::RunLoop
> run_loop_
;
79 // Used for setting timeouts and delays.
80 scoped_ptr
<base::Timer
> timer_
;
82 // Used to ensure RemoteConnectionObserver methods are called on the same
84 base::ThreadChecker thread_checker_
;
86 // Creates and manages the connection to the remote host.
87 scoped_ptr
<TestChromotingClient
> client_
;
89 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectionHelper
);
93 } // namespace remoting
95 #endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_