Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / test / app_remoting_connection_helper.h
blob04269a31c8a27a681a9f92c8182b3976c6e118a0
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_
8 #include <string>
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"
16 namespace base {
17 class RunLoop;
18 class Timer;
19 class Lock;
22 namespace remoting {
23 namespace test {
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 {
32 public:
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_; }
54 private:
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
83 // thread.
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);
92 } // namespace test
93 } // namespace remoting
95 #endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_