cleanup: pass string as const reference from c/b/extension
[chromium-blink-merge.git] / remoting / protocol / input_filter_unittest.cc
blob8059cee85cdd8b972d2764af771ff7f0abed31a3
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"
12 using ::testing::_;
14 namespace remoting {
15 namespace protocol {
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) {
31 KeyEvent event;
32 event.set_usb_keycode(usb_keycode);
33 event.set_pressed(pressed);
34 return event;
37 static TextEvent NewTextEvent(const std::string& text) {
38 TextEvent event;
39 event.set_text(text);
40 return event;
43 static MouseEvent MouseMoveEvent(int x, int y) {
44 MouseEvent event;
45 event.set_x(x);
46 event.set_y(y);
47 return event;
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