Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / test / app_remoting_latency_test_fixture.h
blobb23465ebc516ed27a1c7f13f5dcaabdd1c417dd8
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_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.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"
17 namespace base {
18 class RunLoop;
19 class Timer;
20 class TimeDelta;
23 namespace webrtc {
24 class DesktopRect;
27 namespace remoting {
28 namespace test {
30 struct RemoteApplicationDetails;
31 class AppRemotingConnectionHelper;
32 class TestVideoRenderer;
34 // Called to wait for expected image pattern to be matched within up to a max
35 // wait time.
36 typedef base::Callback<bool(const base::TimeDelta& max_wait_time)>
37 WaitForImagePatternMatchCallback;
39 // 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
41 // rendering latency between client and the remote host.
42 // NOTE: This is an abstract class. To use it, please derive from this class
43 // and implement GetApplicationDetails to specify the application details.
44 class AppRemotingLatencyTestFixture : public testing::Test {
45 public:
46 AppRemotingLatencyTestFixture();
47 ~AppRemotingLatencyTestFixture() override;
49 protected:
50 // Set expected image pattern for comparison.
51 // A WaitForImagePatternMatchCallback is returned to allow waiting for the
52 // expected image pattern to be matched.
53 WaitForImagePatternMatchCallback SetExpectedImagePattern(
54 const webrtc::DesktopRect& expected_rect,
55 uint32_t expected_avg_color);
57 // Inject press & release key event.
58 void PressAndReleaseKey(uint32_t usb_keycode);
60 // Inject press & release a combination of key events.
61 void PressAndReleaseKeyCombination(const std::vector<uint32_t>& usb_keycodes);
63 // Clean up the running application to initial state.
64 virtual void ResetApplicationState();
66 // Get the details of the application to be run.
67 virtual const RemoteApplicationDetails& GetApplicationDetails() = 0;
69 // Creates and manages the connection to the remote host.
70 scoped_ptr<AppRemotingConnectionHelper> connection_helper_;
72 private:
73 // testing::Test interface.
74 void SetUp() override;
75 void TearDown() override;
77 // Inject press key event.
78 void PressKey(uint32_t usb_keycode, bool pressed);
80 // 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.
82 // NOTE: This method should only be run when as a returned callback by
83 // SetExpectedImagePattern.
84 bool WaitForImagePatternMatch(scoped_ptr<base::RunLoop> run_loop,
85 const base::TimeDelta& max_wait_time);
87 // Used to run the thread's message loop.
88 scoped_ptr<base::RunLoop> run_loop_;
90 // Used for setting timeouts and delays.
91 scoped_ptr<base::Timer> timer_;
93 // Used to ensure RemoteConnectionObserver methods are called on the same
94 // thread.
95 base::ThreadChecker thread_checker_;
97 // Using WeakPtr to keep a reference to TestVideoRenderer while let the
98 // TestChromotingClient own its lifetime.
99 base::WeakPtr<TestVideoRenderer> test_video_renderer_;
101 DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture);
104 } // namespace test
105 } // namespace remoting
107 #endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_