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/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"
17 MATCHER_P2(EqualsKeyEvent
, usb_keycode
, pressed
, "") {
18 return arg
.usb_keycode() == static_cast<uint32
>(usb_keycode
) &&
19 arg
.pressed() == pressed
;
22 MATCHER_P2(EqualsMouseMoveEvent
, x
, y
, "") {
23 return arg
.x() == x
&& arg
.y() == y
;
26 static KeyEvent
NewKeyEvent(uint32 usb_keycode
, bool pressed
) {
28 event
.set_usb_keycode(usb_keycode
);
29 event
.set_pressed(pressed
);
33 static MouseEvent
MouseMoveEvent(int x
, int y
) {
40 static void InjectTestSequence(protocol::InputStub
* input_stub
) {
41 // Inject a key event.
42 input_stub
->InjectKeyEvent(NewKeyEvent(0, true));
43 input_stub
->InjectKeyEvent(NewKeyEvent(0, false));
45 // Inject mouse movemement.
46 input_stub
->InjectMouseEvent(MouseMoveEvent(10, 20));
49 // Verify that the filter passes events on correctly to a configured stub.
50 TEST(InputFilterTest
, EventsPassThroughFilter
) {
51 MockInputStub input_stub
;
52 InputFilter
input_filter(&input_stub
);
54 EXPECT_CALL(input_stub
, InjectKeyEvent(EqualsKeyEvent(0, true)));
55 EXPECT_CALL(input_stub
, InjectKeyEvent(EqualsKeyEvent(0, false)));
56 EXPECT_CALL(input_stub
, InjectMouseEvent(EqualsMouseMoveEvent(10, 20)));
58 InjectTestSequence(&input_filter
);
61 // Verify that the filter ignores events if disabled.
62 TEST(InputFilterTest
, IgnoreEventsIfDisabled
) {
63 MockInputStub input_stub
;
64 InputFilter
input_filter(&input_stub
);
66 input_filter
.set_enabled(false);
68 EXPECT_CALL(input_stub
, InjectKeyEvent(_
)).Times(0);
69 EXPECT_CALL(input_stub
, InjectMouseEvent(_
)).Times(0);
71 InjectTestSequence(&input_filter
);
74 // Verify that the filter ignores events if not configured.
75 TEST(InputFilterTest
, IgnoreEventsIfNotConfigured
) {
76 InputFilter input_filter
;
78 InjectTestSequence(&input_filter
);
81 } // namespace protocol
82 } // namespace remoting