OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "remoting/protocol/input_filter.h" |
| 6 |
| 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 |
| 12 using ::testing::_; |
| 13 |
| 14 namespace remoting { |
| 15 namespace protocol { |
| 16 |
| 17 MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") { |
| 18 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && |
| 19 arg.pressed() == pressed; |
| 20 } |
| 21 |
| 22 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") { |
| 23 return arg.x() == x && arg.y() == y; |
| 24 } |
| 25 |
| 26 static KeyEvent NewKeyEvent(uint32 usb_keycode, bool pressed) { |
| 27 KeyEvent event; |
| 28 event.set_usb_keycode(usb_keycode); |
| 29 event.set_pressed(pressed); |
| 30 return event; |
| 31 } |
| 32 |
| 33 static MouseEvent MouseMoveEvent(int x, int y) { |
| 34 MouseEvent event; |
| 35 event.set_x(x); |
| 36 event.set_y(y); |
| 37 return event; |
| 38 } |
| 39 |
| 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)); |
| 44 |
| 45 // Inject mouse movemement. |
| 46 input_stub->InjectMouseEvent(MouseMoveEvent(10, 20)); |
| 47 } |
| 48 |
| 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); |
| 53 |
| 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))); |
| 57 |
| 58 InjectTestSequence(&input_filter); |
| 59 } |
| 60 |
| 61 // Verify that the filter ignores events if disabled. |
| 62 TEST(InputFilterTest, IgnoreEventsIfDisabled) { |
| 63 MockInputStub input_stub; |
| 64 InputFilter input_filter(&input_stub); |
| 65 |
| 66 input_filter.set_enabled(false); |
| 67 |
| 68 EXPECT_CALL(input_stub, InjectKeyEvent(_)).Times(0); |
| 69 EXPECT_CALL(input_stub, InjectMouseEvent(_)).Times(0); |
| 70 |
| 71 InjectTestSequence(&input_filter); |
| 72 } |
| 73 |
| 74 // Verify that the filter ignores events if not configured. |
| 75 TEST(InputFilterTest, IgnoreEventsIfNotConfigured) { |
| 76 InputFilter input_filter; |
| 77 |
| 78 InjectTestSequence(&input_filter); |
| 79 } |
| 80 |
| 81 } // namespace protocol |
| 82 } // namespace remoting |
OLD | NEW |