win: wstring->string16 in chrome/installer/util/html_dialog
[chromium-blink-merge.git] / remoting / protocol / input_filter_unittest.cc
blob25b02ee683eb8c9ec236c64340c18fc1b9268a0a
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 "remoting/protocol/test_event_matchers.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using ::testing::_;
15 namespace remoting {
16 namespace protocol {
18 using test::EqualsKeyEvent;
19 using test::EqualsMouseMoveEvent;
20 using test::EqualsTextEvent;
22 static KeyEvent NewKeyEvent(uint32 usb_keycode, bool pressed) {
23 KeyEvent event;
24 event.set_usb_keycode(usb_keycode);
25 event.set_pressed(pressed);
26 return event;
29 static TextEvent NewTextEvent(const std::string& text) {
30 TextEvent event;
31 event.set_text(text);
32 return event;
35 static MouseEvent MouseMoveEvent(int x, int y) {
36 MouseEvent event;
37 event.set_x(x);
38 event.set_y(y);
39 return event;
42 static void InjectTestSequence(protocol::InputStub* input_stub) {
43 // Inject a key event.
44 input_stub->InjectKeyEvent(NewKeyEvent(0, true));
45 input_stub->InjectKeyEvent(NewKeyEvent(0, false));
47 // Inject a text event
48 input_stub->InjectTextEvent(NewTextEvent("test"));
50 // Inject mouse movemement.
51 input_stub->InjectMouseEvent(MouseMoveEvent(10, 20));
54 // Verify that the filter passes events on correctly to a configured stub.
55 TEST(InputFilterTest, EventsPassThroughFilter) {
56 testing::StrictMock<MockInputStub> input_stub;
57 InputFilter input_filter(&input_stub);
59 EXPECT_CALL(input_stub, InjectKeyEvent(EqualsKeyEvent(0, true)));
60 EXPECT_CALL(input_stub, InjectKeyEvent(EqualsKeyEvent(0, false)));
61 EXPECT_CALL(input_stub, InjectTextEvent(EqualsTextEvent("test")));
62 EXPECT_CALL(input_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 20)));
64 InjectTestSequence(&input_filter);
67 // Verify that the filter ignores events if disabled.
68 TEST(InputFilterTest, IgnoreEventsIfDisabled) {
69 testing::StrictMock<MockInputStub> input_stub;
70 InputFilter input_filter(&input_stub);
72 input_filter.set_enabled(false);
73 InjectTestSequence(&input_filter);
76 // Verify that the filter ignores events if not configured.
77 TEST(InputFilterTest, IgnoreEventsIfNotConfigured) {
78 InputFilter input_filter;
80 InjectTestSequence(&input_filter);
83 } // namespace protocol
84 } // namespace remoting