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_LATENCY_TEST_FIXTURE_H_
6 #define REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "remoting/test/remote_connection_observer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
30 struct RemoteApplicationDetails
;
32 class AppRemotingConnectionHelper
;
33 class TestVideoRenderer
;
35 // Allows for custom handling of ExtensionMessage messages.
36 typedef base::Callback
<void(const protocol::ExtensionMessage
& message
)>
37 HostMessageReceivedCallback
;
39 // Called to wait for expected image pattern to be matched within up to a max
41 typedef base::Callback
<bool(const base::TimeDelta
& max_wait_time
)>
42 WaitForImagePatternMatchCallback
;
44 // Creates a connection to a remote host which is available for tests to use.
45 // Provides convenient methods to create test cases to measure the input and
46 // rendering latency between client and the remote host.
47 // NOTE: This is an abstract class. To use it, please derive from this class
48 // and implement GetApplicationDetails to specify the application details.
49 class AppRemotingLatencyTestFixture
: public testing::Test
,
50 public RemoteConnectionObserver
{
52 AppRemotingLatencyTestFixture();
53 ~AppRemotingLatencyTestFixture() override
;
56 // Set expected image pattern for comparison.
57 // A WaitForImagePatternMatchCallback is returned to allow waiting for the
58 // expected image pattern to be matched.
59 WaitForImagePatternMatchCallback
SetExpectedImagePattern(
60 const webrtc::DesktopRect
& expected_rect
,
61 const RGBValue
& expected_avg_color
);
63 // Turn on/off saving video frames to disk.
64 void SaveFrameDataToDisk(bool save_frame_data_to_disk
);
66 // Inject press & release key event.
67 void PressAndReleaseKey(uint32_t usb_keycode
);
69 // Inject press & release a combination of key events.
70 void PressAndReleaseKeyCombination(const std::vector
<uint32_t>& usb_keycodes
);
72 // Setter for |host_message_received_callback_|.
73 void SetHostMessageReceivedCallback(
74 const HostMessageReceivedCallback
& host_message_received_callback
);
76 // Reset |host_message_received_callback_| to null.
77 void ResetHostMessageReceivedCallback();
79 // Get the details of the application to be run.
80 virtual const RemoteApplicationDetails
& GetApplicationDetails() = 0;
82 // Used to ensure the application under test is ready for testing.
83 virtual bool PrepareApplicationForTesting() = 0;
85 // Clean up the running application to initial state.
86 virtual void ResetApplicationState();
88 // Creates and manages the connection to the remote host.
89 scoped_ptr
<AppRemotingConnectionHelper
> connection_helper_
;
92 // testing::Test interface.
93 void SetUp() override
;
94 void TearDown() override
;
96 // RemoteConnectionObserver interface.
97 void HostMessageReceived(const protocol::ExtensionMessage
& message
) override
;
99 // Inject press key event.
100 void PressKey(uint32_t usb_keycode
, bool pressed
);
102 // Waits for an image pattern matched reply up to |max_wait_time|. Returns
103 // true if we received a response within the maximum time limit.
104 // NOTE: This method should only be run when as a returned callback by
105 // SetExpectedImagePattern.
106 bool WaitForImagePatternMatch(scoped_ptr
<base::RunLoop
> run_loop
,
107 const base::TimeDelta
& max_wait_time
);
109 // Used to run the thread's message loop.
110 scoped_ptr
<base::RunLoop
> run_loop_
;
112 // Used for setting timeouts and delays.
113 scoped_ptr
<base::Timer
> timer_
;
115 // Used to maintain a reference to the TestVideoRenderer instance while it
117 base::WeakPtr
<TestVideoRenderer
> test_video_renderer_
;
119 // Called when an ExtensionMessage is received from the host. Used to
120 // override default message handling.
121 HostMessageReceivedCallback host_message_received_callback_
;
123 DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture
);
127 } // namespace remoting
129 #endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_