This source file includes following definitions.
- MATCHER_P2
- MakeKeyEvent
- PressAndReleaseKey
- MATCHER_P2
- MakeMouseMoveEvent
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "remoting/client/plugin/normalizing_input_filter.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::InSequence;
using remoting::protocol::InputStub;
using remoting::protocol::KeyEvent;
using remoting::protocol::MockInputStub;
using remoting::protocol::MouseEvent;
namespace remoting {
namespace {
const unsigned int kUsbLeftOsKey = 0x0700e3;
const unsigned int kUsbRightOsKey = 0x0700e7;
const unsigned int kUsbFunctionKey = 0x07003a;
const unsigned int kUsbExtendedKey = 0x070049;
const unsigned int kUsbOtherKey = 0x07002b;
static const uint32 kTestLockStates = protocol::KeyEvent::LOCK_STATES_NUMLOCK;
MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") {
return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
arg.pressed() == pressed &&
arg.lock_states() == kTestLockStates;
}
KeyEvent MakeKeyEvent(uint32 keycode, bool pressed) {
KeyEvent event;
event.set_usb_keycode(keycode);
event.set_pressed(pressed);
event.set_lock_states(kTestLockStates);
return event;
}
void PressAndReleaseKey(InputStub* input_stub, uint32 keycode) {
input_stub->InjectKeyEvent(MakeKeyEvent(keycode, true));
input_stub->InjectKeyEvent(MakeKeyEvent(keycode, false));
}
MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
return arg.x() == x && arg.y() == y;
}
static MouseEvent MakeMouseMoveEvent(int x, int y) {
MouseEvent event;
event.set_x(x);
event.set_y(y);
return event;
}
}
TEST(NormalizingInputFilterCrosTest, PressReleaseOsKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, false)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbRightOsKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbRightOsKey, false)));
}
PressAndReleaseKey(processor.get(), kUsbLeftOsKey);
PressAndReleaseKey(processor.get(), kUsbRightOsKey);
}
TEST(NormalizingInputFilterCrosTest, OSKeyRepeats) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
}
TEST(NormalizingInputFilterCrosTest, FunctionKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbFunctionKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbFunctionKey, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
PressAndReleaseKey(processor.get(), kUsbFunctionKey);
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, false));
}
TEST(NormalizingInputFilterCrosTest, ExtendedKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbExtendedKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbExtendedKey, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
PressAndReleaseKey(processor.get(), kUsbExtendedKey);
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, false));
}
TEST(NormalizingInputFilterCrosTest, OtherKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbOtherKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbOtherKey, false)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
PressAndReleaseKey(processor.get(), kUsbOtherKey);
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, false));
}
TEST(NormalizingInputFilterCrosTest, ExtendedThenOtherKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbExtendedKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbExtendedKey, false)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbOtherKey, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbOtherKey, false)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
PressAndReleaseKey(processor.get(), kUsbExtendedKey);
PressAndReleaseKey(processor.get(), kUsbOtherKey);
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, false));
}
TEST(NormalizingInputFilterCrosTest, MouseEvent) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, true)));
EXPECT_CALL(stub, InjectMouseEvent(EqualsMouseMoveEvent(0, 0)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(kUsbLeftOsKey, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, true));
processor->InjectMouseEvent(MakeMouseMoveEvent(0, 0));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOsKey, false));
}
}