1 // Copyright (c) 2012 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 #include "remoting/protocol/mouse_input_filter.h"
7 #include "remoting/proto/event.pb.h"
8 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
14 using ::testing::InSequence;
19 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
20 return arg.x() == x && arg.y() == y;
23 static MouseEvent MouseMoveEvent(int x, int y) {
30 static void InjectTestSequence(InputStub* input_stub) {
35 static const Point input_sequence[] = {
36 {-5, 10}, {0, 10}, {-1, 10}, {15, 40}, {15, 45}, {15, 39}, {15, 25}
38 // arraysize() cannot be used here, becase Point is declared inside of a
40 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(input_sequence); ++i) {
41 const Point& point = input_sequence[i];
42 input_stub->InjectMouseEvent(MouseMoveEvent(point.x, point.y));
44 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(input_sequence); ++i) {
45 const Point& point = input_sequence[i];
46 input_stub->InjectMouseEvent(MouseMoveEvent(point.y, point.x));
50 // Verify that no events get through if we don't set either dimensions.
51 TEST(MouseInputFilterTest, BothDimensionsZero) {
52 MockInputStub mock_stub;
53 MouseInputFilter mouse_filter(&mock_stub);
55 EXPECT_CALL(mock_stub, InjectMouseEvent(_))
58 InjectTestSequence(&mouse_filter);
61 // Verify that no events get through if there's no input size.
62 TEST(MouseInputFilterTest, InputDimensionsZero) {
63 MockInputStub mock_stub;
64 MouseInputFilter mouse_filter(&mock_stub);
65 mouse_filter.set_output_size(webrtc::DesktopSize(50, 50));
67 EXPECT_CALL(mock_stub, InjectMouseEvent(_))
70 InjectTestSequence(&mouse_filter);
73 // Verify that no events get through if there's no output size.
74 TEST(MouseInputFilterTest, OutputDimensionsZero) {
75 MockInputStub mock_stub;
76 MouseInputFilter mouse_filter(&mock_stub);
77 mouse_filter.set_input_size(webrtc::DesktopSize(50, 50));
79 EXPECT_CALL(mock_stub, InjectMouseEvent(_))
82 InjectTestSequence(&mouse_filter);
85 // Verify that all events get through, clamped to the output.
86 TEST(MouseInputFilterTest, NoScalingOrClipping) {
87 MockInputStub mock_stub;
88 MouseInputFilter mouse_filter(&mock_stub);
89 mouse_filter.set_output_size(webrtc::DesktopSize(40,40));
90 mouse_filter.set_input_size(webrtc::DesktopSize(40,40));
95 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 10))).
97 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(15, 39))).
99 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(15, 25))).
102 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 0))).
104 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(39, 15))).
106 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(25, 15))).
110 InjectTestSequence(&mouse_filter);
113 // Verify that we can up-scale with clamping.
114 TEST(MouseInputFilterTest, UpScalingAndClamping) {
115 MockInputStub mock_stub;
116 MouseInputFilter mouse_filter(&mock_stub);
117 mouse_filter.set_output_size(webrtc::DesktopSize(80, 80));
118 mouse_filter.set_input_size(webrtc::DesktopSize(40, 40));
123 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 20))).
125 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(30, 79))).
127 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(30, 51))).
130 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(20, 0))).
132 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(79, 30))).
134 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(51, 30))).
138 InjectTestSequence(&mouse_filter);
141 // Verify that we can down-scale with clamping.
142 TEST(MouseInputFilterTest, DownScalingAndClamping) {
143 MockInputStub mock_stub;
144 MouseInputFilter mouse_filter(&mock_stub);
145 mouse_filter.set_output_size(webrtc::DesktopSize(30, 30));
146 mouse_filter.set_input_size(webrtc::DesktopSize(40, 40));
151 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 7))).
153 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(11, 29))).
155 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(11, 19))).
158 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(7, 0))).
160 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(29, 11))).
162 EXPECT_CALL(mock_stub, InjectMouseEvent(EqualsMouseMoveEvent(19, 11))).
167 InjectTestSequence(&mouse_filter);
170 } // namespace protocol
171 } // namespace remoting