| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/input_filter.h" | 5 #include "remoting/protocol/input_filter.h" |
| 6 | 6 |
| 7 #include "remoting/proto/event.pb.h" | 7 #include "remoting/proto/event.pb.h" |
| 8 #include "remoting/protocol/protocol_mock_objects.h" | 8 #include "remoting/protocol/protocol_mock_objects.h" |
| 9 #include "remoting/protocol/test_event_matchers.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 using ::testing::_; | 13 using ::testing::_; |
| 13 | 14 |
| 14 namespace remoting { | 15 namespace remoting { |
| 15 namespace protocol { | 16 namespace protocol { |
| 16 | 17 |
| 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_P(EqualsTextEvent, text, "") { | |
| 23 return arg.text() == text; | |
| 24 } | |
| 25 | |
| 26 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") { | |
| 27 return arg.x() == x && arg.y() == y; | |
| 28 } | |
| 29 | |
| 30 static KeyEvent NewKeyEvent(uint32 usb_keycode, bool pressed) { | 18 static KeyEvent NewKeyEvent(uint32 usb_keycode, bool pressed) { |
| 31 KeyEvent event; | 19 KeyEvent event; |
| 32 event.set_usb_keycode(usb_keycode); | 20 event.set_usb_keycode(usb_keycode); |
| 33 event.set_pressed(pressed); | 21 event.set_pressed(pressed); |
| 34 return event; | 22 return event; |
| 35 } | 23 } |
| 36 | 24 |
| 37 static TextEvent NewTextEvent(const std::string& text) { | 25 static TextEvent NewTextEvent(const std::string& text) { |
| 38 TextEvent event; | 26 TextEvent event; |
| 39 event.set_text(text); | 27 event.set_text(text); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 | 45 |
| 58 // Inject mouse movemement. | 46 // Inject mouse movemement. |
| 59 input_stub->InjectMouseEvent(MouseMoveEvent(10, 20)); | 47 input_stub->InjectMouseEvent(MouseMoveEvent(10, 20)); |
| 60 } | 48 } |
| 61 | 49 |
| 62 // Verify that the filter passes events on correctly to a configured stub. | 50 // Verify that the filter passes events on correctly to a configured stub. |
| 63 TEST(InputFilterTest, EventsPassThroughFilter) { | 51 TEST(InputFilterTest, EventsPassThroughFilter) { |
| 64 testing::StrictMock<MockInputStub> input_stub; | 52 testing::StrictMock<MockInputStub> input_stub; |
| 65 InputFilter input_filter(&input_stub); | 53 InputFilter input_filter(&input_stub); |
| 66 | 54 |
| 67 EXPECT_CALL(input_stub, InjectKeyEvent(EqualsKeyEvent(0, true))); | 55 EXPECT_CALL(input_stub, InjectKeyEvent(EqualsUsbEvent(0, true))); |
| 68 EXPECT_CALL(input_stub, InjectKeyEvent(EqualsKeyEvent(0, false))); | 56 EXPECT_CALL(input_stub, InjectKeyEvent(EqualsUsbEvent(0, false))); |
| 69 EXPECT_CALL(input_stub, InjectTextEvent(EqualsTextEvent("test"))); | 57 EXPECT_CALL(input_stub, InjectTextEvent(EqualsTextEvent("test"))); |
| 70 EXPECT_CALL(input_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 20))); | 58 EXPECT_CALL(input_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 20))); |
| 71 | 59 |
| 72 InjectTestSequence(&input_filter); | 60 InjectTestSequence(&input_filter); |
| 73 } | 61 } |
| 74 | 62 |
| 75 // Verify that the filter ignores events if disabled. | 63 // Verify that the filter ignores events if disabled. |
| 76 TEST(InputFilterTest, IgnoreEventsIfDisabled) { | 64 TEST(InputFilterTest, IgnoreEventsIfDisabled) { |
| 77 testing::StrictMock<MockInputStub> input_stub; | 65 testing::StrictMock<MockInputStub> input_stub; |
| 78 InputFilter input_filter(&input_stub); | 66 InputFilter input_filter(&input_stub); |
| 79 | 67 |
| 80 input_filter.set_enabled(false); | 68 input_filter.set_enabled(false); |
| 81 InjectTestSequence(&input_filter); | 69 InjectTestSequence(&input_filter); |
| 82 } | 70 } |
| 83 | 71 |
| 84 // Verify that the filter ignores events if not configured. | 72 // Verify that the filter ignores events if not configured. |
| 85 TEST(InputFilterTest, IgnoreEventsIfNotConfigured) { | 73 TEST(InputFilterTest, IgnoreEventsIfNotConfigured) { |
| 86 InputFilter input_filter; | 74 InputFilter input_filter; |
| 87 | 75 |
| 88 InjectTestSequence(&input_filter); | 76 InjectTestSequence(&input_filter); |
| 89 } | 77 } |
| 90 | 78 |
| 91 } // namespace protocol | 79 } // namespace protocol |
| 92 } // namespace remoting | 80 } // namespace remoting |
| OLD | NEW |