Update V8 to version 4.6.55.
[chromium-blink-merge.git] / remoting / test / app_remoting_connected_client_fixture.h
blob6d8547c6aa6114dd14c0dbf15ce592077de4e0d8
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_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "remoting/test/remote_connection_observer.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace base {
18 class RunLoop;
19 class Timer;
22 namespace remoting {
23 namespace test {
25 struct RemoteApplicationDetails;
26 class AppRemotingConnectionHelper;
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 {
37 public:
38 AppRemotingConnectedClientFixture();
39 ~AppRemotingConnectedClientFixture() override;
41 protected:
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);
50 private:
51 // testing::Test interface.
52 void SetUp() override;
53 void TearDown() override;
55 // RemoteConnectionObserver interface.
56 void HostMessageReceived(const protocol::ExtensionMessage& message) override;
58 // Handles messages from the host.
59 void HandleOnHostMessage(const remoting::protocol::ExtensionMessage& message);
61 // Contains the details for the application being tested.
62 const RemoteApplicationDetails& application_details_;
64 // Used to run the thread's message loop.
65 scoped_ptr<base::RunLoop> run_loop_;
67 // Used for setting timeouts and delays.
68 scoped_ptr<base::Timer> timer_;
70 // Used to ensure RemoteConnectionObserver methods are called on the same
71 // thread.
72 base::ThreadChecker thread_checker_;
74 // Creates and manages the connection to the remote host.
75 scoped_ptr<AppRemotingConnectionHelper> connection_helper_;
77 // Called when an ExtensionMessage is received from the host.
78 HostMessageReceivedCallback host_message_received_callback_;
80 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture);
83 } // namespace test
84 } // namespace remoting
86 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_