Chromium Code Reviews| 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 // Reset |host_message_received_callback_| to null. | |
| 78 void ResetHostMessageReceivedCallback(); | |
| 79 | |
| 80 // Get the details of the application to be run. | |
| 81 virtual const RemoteApplicationDetails& GetApplicationDetails() = 0; | |
| 82 | |
| 83 // Create a fresh document for test. | |
|
joedow
2015/07/25 02:13:34
Can you fix the comment here, you don't know in th
liaoyuke
2015/07/27 17:22:50
Done.
| |
| 84 virtual bool PrepareApplicationForTesting() = 0; | |
| 85 | |
| 63 // Clean up the running application to initial state. | 86 // Clean up the running application to initial state. |
| 64 virtual void ResetApplicationState(); | 87 virtual void ResetApplicationState(); |
| 65 | 88 |
| 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. | 89 // Creates and manages the connection to the remote host. |
| 70 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; | 90 scoped_ptr<AppRemotingConnectionHelper> connection_helper_; |
| 71 | 91 |
| 72 private: | 92 private: |
| 73 // testing::Test interface. | 93 // testing::Test interface. |
| 74 void SetUp() override; | 94 void SetUp() override; |
| 75 void TearDown() override; | 95 void TearDown() override; |
| 76 | 96 |
| 97 private: | |
| 98 // RemoteConnectionObserver interface. | |
| 99 void HostMessageReceived(const protocol::ExtensionMessage& message) override; | |
| 100 | |
| 77 // Inject press key event. | 101 // Inject press key event. |
| 78 void PressKey(uint32_t usb_keycode, bool pressed); | 102 void PressKey(uint32_t usb_keycode, bool pressed); |
| 79 | 103 |
| 80 // Waits for an image pattern matched reply up to |max_wait_time|. Returns | 104 // 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. | 105 // 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 | 106 // NOTE: This method should only be run when as a returned callback by |
| 83 // SetExpectedImagePattern. | 107 // SetExpectedImagePattern. |
| 84 bool WaitForImagePatternMatch(scoped_ptr<base::RunLoop> run_loop, | 108 bool WaitForImagePatternMatch(scoped_ptr<base::RunLoop> run_loop, |
| 85 const base::TimeDelta& max_wait_time); | 109 const base::TimeDelta& max_wait_time); |
| 86 | 110 |
| 87 // Used to run the thread's message loop. | 111 // Used to run the thread's message loop. |
| 88 scoped_ptr<base::RunLoop> run_loop_; | 112 scoped_ptr<base::RunLoop> run_loop_; |
| 89 | 113 |
| 90 // Used for setting timeouts and delays. | 114 // Used for setting timeouts and delays. |
| 91 scoped_ptr<base::Timer> timer_; | 115 scoped_ptr<base::Timer> timer_; |
| 92 | 116 |
| 93 // Used to ensure RemoteConnectionObserver methods are called on the same | 117 // Used to ensure RemoteConnectionObserver methods are called on the same |
| 94 // thread. | 118 // thread. |
| 95 base::ThreadChecker thread_checker_; | 119 base::ThreadChecker thread_checker_; |
| 96 | 120 |
| 97 // Using WeakPtr to keep a reference to TestVideoRenderer while let the | 121 // Used to maintain a reference to the TestVideoRenderer instance while it |
| 98 // TestChromotingClient own its lifetime. | 122 // exists. |
| 99 base::WeakPtr<TestVideoRenderer> test_video_renderer_; | 123 base::WeakPtr<TestVideoRenderer> test_video_renderer_; |
| 100 | 124 |
| 125 // Called when an ExtensionMessage is received from the host. Used to | |
| 126 // override default message handling. | |
| 127 HostMessageReceivedCallback host_message_received_callback_; | |
| 128 | |
| 101 DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture); | 129 DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture); |
| 102 }; | 130 }; |
| 103 | 131 |
| 104 } // namespace test | 132 } // namespace test |
| 105 } // namespace remoting | 133 } // namespace remoting |
| 106 | 134 |
| 107 #endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ | 135 #endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_ |
| OLD | NEW |