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_P(EqualsTextEvent
, text
, "") {
23 return arg
.text() == text
;
26 MATCHER_P2(EqualsMouseMoveEvent
, x
, y
, "") {
27 return arg
.x() == x
&& arg
.y() == y
;
30 static KeyEvent
NewKeyEvent(uint32 usb_keycode
, bool pressed
) {
32 event
.set_usb_keycode(usb_keycode
);
33 event
.set_pressed(pressed
);
37 static TextEvent
NewTextEvent(const std::string
& text
) {
43 static MouseEvent
MouseMoveEvent(int x
, int y
) {
50 static void InjectTestSequence(protocol::InputStub
* input_stub
) {
51 // Inject a key event.
52 input_stub
->InjectKeyEvent(NewKeyEvent(0, true));
53 input_stub
->InjectKeyEvent(NewKeyEvent(0, false));
55 // Inject a text event
56 input_stub
->InjectTextEvent(NewTextEvent("test"));
58 // Inject mouse movemement.
59 input_stub
->InjectMouseEvent(MouseMoveEvent(10, 20));
62 // Verify that the filter passes events on correctly to a configured stub.
63 TEST(InputFilterTest
, EventsPassThroughFilter
) {
64 testing::StrictMock
<MockInputStub
> input_stub
;
65 InputFilter
input_filter(&input_stub
);
67 EXPECT_CALL(input_stub
, InjectKeyEvent(EqualsKeyEvent(0, true)));
68 EXPECT_CALL(input_stub
, InjectKeyEvent(EqualsKeyEvent(0, false)));
69 EXPECT_CALL(input_stub
, InjectTextEvent(EqualsTextEvent("test")));
70 EXPECT_CALL(input_stub
, InjectMouseEvent(EqualsMouseMoveEvent(10, 20)));
72 InjectTestSequence(&input_filter
);
75 // Verify that the filter ignores events if disabled.
76 TEST(InputFilterTest
, IgnoreEventsIfDisabled
) {
77 testing::StrictMock
<MockInputStub
> input_stub
;
78 InputFilter
input_filter(&input_stub
);
80 input_filter
.set_enabled(false);
81 InjectTestSequence(&input_filter
);
84 // Verify that the filter ignores events if not configured.
85 TEST(InputFilterTest
, IgnoreEventsIfNotConfigured
) {
86 InputFilter input_filter
;
88 InjectTestSequence(&input_filter
);
91 } // namespace protocol
92 } // namespace remoting