OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ | 5 #ifndef REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ |
6 #define REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ | 6 #define REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "remoting/test/remote_connection_observer.h" | 14 #include "remoting/test/remote_connection_observer.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class RunLoop; | 18 class RunLoop; |
18 class Timer; | 19 class Timer; |
19 } | 20 } |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 namespace test { | 23 namespace test { |
23 | 24 |
24 struct RemoteApplicationDetails; | 25 struct RemoteApplicationDetails; |
25 class AppRemotingConnectionHelper; | 26 class AppRemotingConnectionHelper; |
26 | 27 |
| 28 // Allows for custom handling of ExtensionMessage messages. |
| 29 typedef base::Callback<void(const protocol::ExtensionMessage& message)> |
| 30 HostMessageReceivedCallback; |
| 31 |
27 // Creates a connection to a remote host which is available for tests to use. | 32 // Creates a connection to a remote host which is available for tests to use. |
28 // All callbacks must occur on the same thread the object was created on. | 33 // All callbacks must occur on the same thread the object was created on. |
29 class AppRemotingConnectedClientFixture | 34 class AppRemotingConnectedClientFixture |
30 : public testing::TestWithParam<const char*> { | 35 : public testing::TestWithParam<const char*>, |
| 36 public RemoteConnectionObserver { |
31 public: | 37 public: |
32 AppRemotingConnectedClientFixture(); | 38 AppRemotingConnectedClientFixture(); |
33 ~AppRemotingConnectedClientFixture() override; | 39 ~AppRemotingConnectedClientFixture() override; |
34 | 40 |
35 protected: | 41 protected: |
36 // Sends the request to the host and waits for a reply up to |max_wait_time|. | 42 // Sends the request to the host and waits for a reply up to |max_wait_time|. |
37 // Returns true if we received a response within the maximum time limit. | 43 // Returns true if we received a response within the maximum time limit. |
38 bool VerifyResponseForSimpleHostMessage( | 44 bool VerifyResponseForSimpleHostMessage( |
39 const std::string& message_request_title, | 45 const std::string& message_request_title, |
40 const std::string& message_response_title, | 46 const std::string& message_response_title, |
41 const std::string& message_payload, | 47 const std::string& message_payload, |
42 const base::TimeDelta& max_wait_time); | 48 const base::TimeDelta& max_wait_time); |
43 | 49 |
44 private: | 50 private: |
45 // testing::Test interface. | 51 // testing::Test interface. |
46 void SetUp() override; | 52 void SetUp() override; |
47 void TearDown() override; | 53 void TearDown() override; |
48 | 54 |
| 55 // RemoteConnectionObserver interface. |
| 56 void HostMessageReceived(const protocol::ExtensionMessage& message) override; |
| 57 |
| 58 // Handles messages from the host. |
| 59 void HandleOnHostMessage(const remoting::protocol::ExtensionMessage& message); |
| 60 |
49 // Contains the details for the application being tested. | 61 // Contains the details for the application being tested. |
50 const RemoteApplicationDetails& application_details_; | 62 const RemoteApplicationDetails& application_details_; |
51 | 63 |
52 // Used to run the thread's message loop. | 64 // Used to run the thread's message loop. |
53 scoped_ptr<base::RunLoop> run_loop_; | 65 scoped_ptr<base::RunLoop> run_loop_; |
54 | 66 |
55 // Used for setting timeouts and delays. | 67 // Used for setting timeouts and delays. |
56 scoped_ptr<base::Timer> timer_; | 68 scoped_ptr<base::Timer> timer_; |
57 | 69 |
58 // Used to ensure RemoteConnectionObserver methods are called on the same | 70 // Used to ensure RemoteConnectionObserver methods are called on the same |
59 // thread. | 71 // thread. |
60 base::ThreadChecker thread_checker_; | 72 base::ThreadChecker thread_checker_; |
61 | 73 |
62 // Creates and manages the connection to the remote host. | 74 // Creates and manages the connection to the remote host. |
63 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; | 75 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; |
64 | 76 |
| 77 // Called when an ExtensionMessage is received from the host. |
| 78 HostMessageReceivedCallback host_message_received_callback_; |
| 79 |
65 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture); | 80 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture); |
66 }; | 81 }; |
67 | 82 |
68 } // namespace test | 83 } // namespace test |
69 } // namespace remoting | 84 } // namespace remoting |
70 | 85 |
71 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ | 86 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ |
OLD | NEW |