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.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"
24 struct RemoteApplicationDetails
;
25 class TestChromotingClient
;
27 // Allows for custom handling of ExtensionMessage messages.
28 typedef base::Callback
<void(const protocol::ExtensionMessage
& message
)>
29 HostMessageReceivedCallback
;
31 // Creates a connection to a remote host which is available for tests to use.
32 // All callbacks must occur on the same thread the object was created on.
33 class AppRemotingConnectedClientFixture
34 : public testing::TestWithParam
<const char*>,
35 public RemoteConnectionObserver
{
37 AppRemotingConnectedClientFixture();
38 ~AppRemotingConnectedClientFixture() override
;
41 // Sends the request to the host and waits for a reply up to |max_wait_time|.
42 // Returns true if we received a response within the maximum time limit.
43 bool VerifyResponseForSimpleHostMessage(
44 const std::string
& message_request_title
,
45 const std::string
& message_response_title
,
46 const std::string
& message_payload
,
47 const base::TimeDelta
& max_wait_time
);
50 // testing::Test interface.
51 void SetUp() override
;
52 void TearDown() override
;
54 // RemoteConnectionObserver interface.
55 void ConnectionStateChanged(protocol::ConnectionToHost::State state
,
56 protocol::ErrorCode error_code
) override
;
57 void ConnectionReady(bool ready
) override
;
58 void HostMessageReceived(const protocol::ExtensionMessage
& message
) override
;
60 // Starts a connection with the remote host.
61 void StartConnection();
63 // Sends client details to the host in order to complete the connection.
64 void SendClientConnectionDetailsToHost();
66 // Handles onWindowAdded messages from the host.
67 void HandleOnWindowAddedMessage(
68 const remoting::protocol::ExtensionMessage
& message
);
70 // Contains the details for the application being tested.
71 const RemoteApplicationDetails
& application_details_
;
73 // Called when an ExtensionMessage is received from the host. Used to
74 // override default message handling.
75 HostMessageReceivedCallback host_message_received_callback_
;
77 // Indicates whether the remote connection is ready to be used for testing.
78 // True when a chromoting connection to the remote host has been established
79 // and the main application window is visible.
80 bool connection_is_ready_for_tests_
;
82 // Used to run the thread's message loop.
83 scoped_ptr
<base::RunLoop
> run_loop_
;
85 // Used for setting timeouts and delays.
86 scoped_ptr
<base::Timer
> timer_
;
88 // Used to ensure RemoteConnectionObserver methods are called on the same
90 base::ThreadChecker thread_checker_
;
92 // Creates and manages the connection to the remote host.
93 scoped_ptr
<TestChromotingClient
> client_
;
95 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture
);
99 } // namespace remoting
101 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_