This source file includes following definitions.
- MATCHER_P2
- MouseMoveEvent
- UsbKeyEvent
- TEST
- TEST
- TEST
- TEST
- TEST
#include "remoting/host/remote_input_filter.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/input_event_tracker.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
using ::testing::ExpectationSet;
using ::testing::InSequence;
namespace remoting {
using protocol::MockInputStub;
using protocol::InputEventTracker;
namespace {
MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") {
return arg.usb_keycode() == (unsigned int)usb_keycode &&
arg.pressed() == pressed;
}
static protocol::MouseEvent MouseMoveEvent(int x, int y) {
protocol::MouseEvent event;
event.set_x(x);
event.set_y(y);
return event;
}
static protocol::KeyEvent UsbKeyEvent(int usb_keycode, bool pressed) {
protocol::KeyEvent event;
event.set_usb_keycode(usb_keycode);
event.set_pressed(pressed);
return event;
}
}
TEST(RemoteInputFilterTest, NoLocalActivity) {
MockInputStub mock_stub;
InputEventTracker input_tracker(&mock_stub);
RemoteInputFilter input_filter(&input_tracker);
EXPECT_CALL(mock_stub, InjectMouseEvent(_))
.Times(10);
for (int i = 0; i < 10; ++i)
input_filter.InjectMouseEvent(MouseMoveEvent(0, 0));
}
TEST(RemoteInputFilterTest, MismatchedLocalActivity) {
MockInputStub mock_stub;
InputEventTracker input_tracker(&mock_stub);
RemoteInputFilter input_filter(&input_tracker);
EXPECT_CALL(mock_stub, InjectMouseEvent(_))
.Times(5);
for (int i = 0; i < 10; ++i) {
input_filter.InjectMouseEvent(MouseMoveEvent(0, 0));
if (i == 4)
input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1));
}
}
TEST(RemoteInputFilterTest, LocalEchoesOfRemoteActivity) {
MockInputStub mock_stub;
InputEventTracker input_tracker(&mock_stub);
RemoteInputFilter input_filter(&input_tracker);
EXPECT_CALL(mock_stub, InjectMouseEvent(_))
.Times(10);
for (int i = 0; i < 10; ++i) {
input_filter.InjectMouseEvent(MouseMoveEvent(0, 0));
input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0));
}
}
TEST(RemoteInputFilterTest, LocalEchosAndLocalActivity) {
MockInputStub mock_stub;
InputEventTracker input_tracker(&mock_stub);
RemoteInputFilter input_filter(&input_tracker);
EXPECT_CALL(mock_stub, InjectMouseEvent(_))
.Times(5);
for (int i = 0; i < 10; ++i) {
input_filter.InjectMouseEvent(MouseMoveEvent(0, 0));
input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0));
if (i == 4)
input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1));
}
}
TEST(RemoteInputFilterTest, LocalActivityReleasesAll) {
MockInputStub mock_stub;
InputEventTracker input_tracker(&mock_stub);
RemoteInputFilter input_filter(&input_tracker);
EXPECT_CALL(mock_stub, InjectMouseEvent(_))
.Times(5);
EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(0, true)));
EXPECT_CALL(mock_stub, InjectKeyEvent(EqualsUsbEvent(0, false)));
input_filter.InjectKeyEvent(UsbKeyEvent(0, true));
for (int i = 0; i < 10; ++i) {
input_filter.InjectMouseEvent(MouseMoveEvent(0, 0));
input_filter.LocalMouseMoved(webrtc::DesktopVector(0, 0));
if (i == 4)
input_filter.LocalMouseMoved(webrtc::DesktopVector(1, 1));
}
}
}