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; |
27 class TestChromotingClient; | |
28 | |
29 // Allows for custom handling of ExtensionMessage messages. | |
30 typedef base::Callback<void(const protocol::ExtensionMessage& message)> | |
31 HostMessageReceivedCallback; | |
26 | 32 |
27 // Creates a connection to a remote host which is available for tests to use. | 33 // 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. | 34 // All callbacks must occur on the same thread the object was created on. |
29 class AppRemotingConnectedClientFixture | 35 class AppRemotingConnectedClientFixture |
30 : public testing::TestWithParam<const char*> { | 36 : public testing::TestWithParam<const char*>, |
37 public RemoteConnectionObserver { | |
31 public: | 38 public: |
32 AppRemotingConnectedClientFixture(); | 39 AppRemotingConnectedClientFixture(); |
33 ~AppRemotingConnectedClientFixture() override; | 40 ~AppRemotingConnectedClientFixture() override; |
34 | 41 |
35 protected: | 42 protected: |
36 // Sends the request to the host and waits for a reply up to |max_wait_time|. | 43 // 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. | 44 // Returns true if we received a response within the maximum time limit. |
38 bool VerifyResponseForSimpleHostMessage( | 45 bool VerifyResponseForSimpleHostMessage( |
39 const std::string& message_request_title, | 46 const std::string& message_request_title, |
40 const std::string& message_response_title, | 47 const std::string& message_response_title, |
41 const std::string& message_payload, | 48 const std::string& message_payload, |
42 const base::TimeDelta& max_wait_time); | 49 const base::TimeDelta& max_wait_time); |
43 | 50 |
44 private: | 51 private: |
45 // testing::Test interface. | 52 // testing::Test interface. |
46 void SetUp() override; | 53 void SetUp() override; |
47 void TearDown() override; | 54 void TearDown() override; |
48 | 55 |
56 // RemoteConnectionObserver interface. | |
57 void HostMessageReceived(const protocol::ExtensionMessage& message) override; | |
58 | |
59 // Handles messages from the host. | |
60 void HandleOnHostMessage(const remoting::protocol::ExtensionMessage& message); | |
61 | |
49 // Contains the details for the application being tested. | 62 // Contains the details for the application being tested. |
50 const RemoteApplicationDetails& application_details_; | 63 const RemoteApplicationDetails& application_details_; |
51 | 64 |
52 // Used to run the thread's message loop. | 65 // Used to run the thread's message loop. |
53 scoped_ptr<base::RunLoop> run_loop_; | 66 scoped_ptr<base::RunLoop> run_loop_; |
54 | 67 |
55 // Used for setting timeouts and delays. | 68 // Used for setting timeouts and delays. |
56 scoped_ptr<base::Timer> timer_; | 69 scoped_ptr<base::Timer> timer_; |
57 | 70 |
58 // Used to ensure RemoteConnectionObserver methods are called on the same | 71 // Used to ensure RemoteConnectionObserver methods are called on the same |
59 // thread. | 72 // thread. |
60 base::ThreadChecker thread_checker_; | 73 base::ThreadChecker thread_checker_; |
61 | 74 |
62 // Creates and manages the connection to the remote host. | 75 // Creates and manages the connection to the remote host. |
63 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; | 76 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; |
64 | 77 |
78 // Using WeakPtr to keep a reference to TestChromotingClient while let the | |
79 // AppRemotingConnectionHelper own its lifetime. | |
80 base::WeakPtr<TestChromotingClient> test_chromoting_client_; | |
Sergey Ulanov
2015/07/23 19:36:55
I don't think you really need this to be a weak po
liaoyuke
2015/07/24 02:07:28
Done.
| |
81 | |
82 // Called when an ExtensionMessage is received from the host. | |
83 HostMessageReceivedCallback host_message_received_callback_; | |
84 | |
65 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture); | 85 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture); |
66 }; | 86 }; |
67 | 87 |
68 } // namespace test | 88 } // namespace test |
69 } // namespace remoting | 89 } // namespace remoting |
70 | 90 |
71 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ | 91 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ |
OLD | NEW |