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_LATENCY_TEST_FIXTURE_H_ | 5 #ifndef REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ |
6 #define REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ | 6 #define REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ |
7 | 7 |
8 #include <string> | |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
11 #include "base/callback.h" | |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
13 #include "remoting/test/remote_connection_observer.h" | 15 #include "remoting/test/remote_connection_observer.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 17 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class RunLoop; | 20 class RunLoop; |
19 class Timer; | 21 class Timer; |
20 class TimeDelta; | 22 class TimeDelta; |
21 } | 23 } |
22 | 24 |
23 namespace webrtc { | 25 namespace webrtc { |
24 class DesktopRect; | 26 class DesktopRect; |
25 } | 27 } |
26 | 28 |
27 namespace remoting { | 29 namespace remoting { |
28 namespace test { | 30 namespace test { |
29 | 31 |
30 struct RemoteApplicationDetails; | 32 struct RemoteApplicationDetails; |
33 struct RGBValue; | |
31 class AppRemotingConnectionHelper; | 34 class AppRemotingConnectionHelper; |
32 class TestVideoRenderer; | 35 class TestVideoRenderer; |
33 | 36 |
37 // Allows for custom handling of ExtensionMessage messages. | |
38 typedef base::Callback<void(const protocol::ExtensionMessage& message)> | |
39 HostMessageReceivedCallback; | |
40 | |
34 // Called to wait for expected image pattern to be matched within up to a max | 41 // Called to wait for expected image pattern to be matched within up to a max |
35 // wait time. | 42 // wait time. |
36 typedef base::Callback<bool(const base::TimeDelta& max_wait_time)> | 43 typedef base::Callback<bool(const base::TimeDelta& max_wait_time)> |
37 WaitForImagePatternMatchCallback; | 44 WaitForImagePatternMatchCallback; |
38 | 45 |
39 // Creates a connection to a remote host which is available for tests to use. | 46 // Creates a connection to a remote host which is available for tests to use. |
40 // Provides convenient methods to create test cases to measure the input and | 47 // Provides convenient methods to create test cases to measure the input and |
41 // rendering latency between client and the remote host. | 48 // rendering latency between client and the remote host. |
42 // NOTE: This is an abstract class. To use it, please derive from this class | 49 // NOTE: This is an abstract class. To use it, please derive from this class |
43 // and implement GetApplicationDetails to specify the application details. | 50 // and implement GetApplicationDetails to specify the application details. |
44 class AppRemotingLatencyTestFixture : public testing::Test { | 51 class AppRemotingLatencyTestFixture : public testing::Test, |
52 public RemoteConnectionObserver { | |
45 public: | 53 public: |
46 AppRemotingLatencyTestFixture(); | 54 AppRemotingLatencyTestFixture(); |
47 ~AppRemotingLatencyTestFixture() override; | 55 ~AppRemotingLatencyTestFixture() override; |
48 | 56 |
49 protected: | 57 protected: |
50 // Set expected image pattern for comparison. | 58 // Set expected image pattern for comparison. |
51 // A WaitForImagePatternMatchCallback is returned to allow waiting for the | 59 // A WaitForImagePatternMatchCallback is returned to allow waiting for the |
52 // expected image pattern to be matched. | 60 // expected image pattern to be matched. |
53 WaitForImagePatternMatchCallback SetExpectedImagePattern( | 61 WaitForImagePatternMatchCallback SetExpectedImagePattern( |
54 const webrtc::DesktopRect& expected_rect, | 62 const webrtc::DesktopRect& expected_rect, |
55 uint32_t expected_avg_color); | 63 const RGBValue& expected_avg_color); |
56 | 64 |
57 // Inject press & release key event. | 65 // Inject press & release key event. |
58 void PressAndReleaseKey(uint32_t usb_keycode); | 66 void PressAndReleaseKey(uint32_t usb_keycode); |
59 | 67 |
60 // Inject press & release a combination of key events. | 68 // Inject press & release a combination of key events. |
61 void PressAndReleaseKeyCombination(const std::vector<uint32_t>& usb_keycodes); | 69 void PressAndReleaseKeyCombination(const std::vector<uint32_t>& usb_keycodes); |
62 | 70 |
71 // Setter for |host_message_received_callback_|. | |
72 void SetHostMessageReceivedCallback( | |
73 HostMessageReceivedCallback host_message_received_callback) { | |
74 host_message_received_callback_ = host_message_received_callback; | |
75 } | |
76 | |
77 void ResetHostMessageReceivedCallback() { | |
78 host_message_received_callback_.Reset(); | |
79 } | |
joedow
2015/07/24 13:50:58
This should be defined in the cc file. Trivial se
liaoyuke
2015/07/25 01:43:49
Done.
| |
80 | |
81 // Get the details of the application to be run. | |
82 virtual const RemoteApplicationDetails& GetApplicationDetails() = 0; | |
83 | |
84 // Create a fresh document for test. | |
85 virtual bool PrepareApplicationForTesting() = 0; | |
86 | |
63 // Clean up the running application to initial state. | 87 // Clean up the running application to initial state. |
64 virtual void ResetApplicationState(); | 88 virtual void ResetApplicationState(); |
65 | 89 |
66 // Get the details of the application to be run. | |
67 virtual const RemoteApplicationDetails& GetApplicationDetails() = 0; | |
68 | |
69 // Creates and manages the connection to the remote host. | 90 // Creates and manages the connection to the remote host. |
70 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; | 91 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; |
71 | 92 |
72 private: | 93 private: |
73 // testing::Test interface. | 94 // testing::Test interface. |
74 void SetUp() override; | 95 void SetUp() override; |
75 void TearDown() override; | 96 void TearDown() override; |
76 | 97 |
98 private: | |
99 // RemoteConnectionObserver interface. | |
100 void HostMessageReceived(const protocol::ExtensionMessage& message) override; | |
101 | |
77 // Inject press key event. | 102 // Inject press key event. |
78 void PressKey(uint32_t usb_keycode, bool pressed); | 103 void PressKey(uint32_t usb_keycode, bool pressed); |
79 | 104 |
80 // Waits for an image pattern matched reply up to |max_wait_time|. Returns | 105 // Waits for an image pattern matched reply up to |max_wait_time|. Returns |
81 // true if we received a response within the maximum time limit. | 106 // true if we received a response within the maximum time limit. |
82 // NOTE: This method should only be run when as a returned callback by | 107 // NOTE: This method should only be run when as a returned callback by |
83 // SetExpectedImagePattern. | 108 // SetExpectedImagePattern. |
84 bool WaitForImagePatternMatch(scoped_ptr<base::RunLoop> run_loop, | 109 bool WaitForImagePatternMatch(scoped_ptr<base::RunLoop> run_loop, |
85 const base::TimeDelta& max_wait_time); | 110 const base::TimeDelta& max_wait_time); |
86 | 111 |
87 // Used to run the thread's message loop. | 112 // Used to run the thread's message loop. |
88 scoped_ptr<base::RunLoop> run_loop_; | 113 scoped_ptr<base::RunLoop> run_loop_; |
89 | 114 |
90 // Used for setting timeouts and delays. | 115 // Used for setting timeouts and delays. |
91 scoped_ptr<base::Timer> timer_; | 116 scoped_ptr<base::Timer> timer_; |
92 | 117 |
93 // Used to ensure RemoteConnectionObserver methods are called on the same | 118 // Used to ensure RemoteConnectionObserver methods are called on the same |
94 // thread. | 119 // thread. |
95 base::ThreadChecker thread_checker_; | 120 base::ThreadChecker thread_checker_; |
96 | 121 |
97 // Using WeakPtr to keep a reference to TestVideoRenderer while let the | 122 // Used to maintain a reference to the TestVideoRenderer instance while it |
98 // TestChromotingClient own its lifetime. | 123 // exists |
joedow
2015/07/24 13:50:58
nit: add period to the end of the comment.
liaoyuke
2015/07/25 01:43:49
Done.
| |
99 base::WeakPtr<TestVideoRenderer> test_video_renderer_; | 124 base::WeakPtr<TestVideoRenderer> test_video_renderer_; |
100 | 125 |
126 // Called when an ExtensionMessage is received from the host. Used to | |
127 // override default message handling. | |
128 HostMessageReceivedCallback host_message_received_callback_; | |
129 | |
101 DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture); | 130 DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture); |
102 }; | 131 }; |
103 | 132 |
104 } // namespace test | 133 } // namespace test |
105 } // namespace remoting | 134 } // namespace remoting |
106 | 135 |
107 #endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ | 136 #endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ |
OLD | NEW |