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_CONNECTED_CLIENT_FIXTURE_H_
6 #define REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_
10 #include "base/callback_forward.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"
17 class MessageLoopForIO
;
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 AppRemotingConnectedClientFixture
35 : public testing::TestWithParam
<const char*>,
36 public RemoteConnectionObserver
{
38 AppRemotingConnectedClientFixture();
39 ~AppRemotingConnectedClientFixture() override
;
42 // Sends the request to the host and waits for a reply up to |max_wait_time|.
43 // Returns true if we received a response within the maximum time limit.
44 bool VerifyResponseForSimpleHostMessage(
45 const std::string
& message_request_title
,
46 const std::string
& message_response_title
,
47 const std::string
& message_payload
,
48 const base::TimeDelta
& max_wait_time
);
51 // testing::Test interface.
52 void SetUp() override
;
53 void TearDown() override
;
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 // Starts a connection with the remote host.
62 void StartConnection();
64 // Sends client details to the host in order to complete the connection.
65 void SendClientConnectionDetailsToHost();
67 // Handles onWindowAdded messages from the host.
68 void HandleOnWindowAddedMessage(
69 const remoting::protocol::ExtensionMessage
& message
);
71 // Contains the details for the application being tested.
72 const RemoteApplicationDetails
& application_details_
;
74 // Called when an ExtensionMessage is received from the host. Used to
75 // override default message handling.
76 HostMessageReceivedCallback host_message_received_callback_
;
78 // Indicates whether the remote connection is ready to be used for testing.
79 // True when a chromoting connection to the remote host has been established
80 // and the main application window is visible.
81 bool connection_is_ready_for_tests_
;
83 // Used to post tasks by |client_| and tests.
84 scoped_ptr
<base::MessageLoopForIO
> message_loop_
;
86 // Used to run the thread's message loop.
87 scoped_ptr
<base::RunLoop
> run_loop_
;
89 // Used for setting timeouts and delays.
90 scoped_ptr
<base::Timer
> timer_
;
92 // Used to ensure RemoteConnectionObserver methods are called on the same
94 base::ThreadChecker thread_checker_
;
96 // Creates and manages the connection to the remote host.
97 scoped_ptr
<TestChromotingClient
> client_
;
99 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture
);
103 } // namespace remoting
105 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_