This source file includes following definitions.
- MATCHER_P2
- MakeKeyEvent
- 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 kUsbCapsLock = 0x070039;
const unsigned int kUsbLeftShift = 0x0700e1;
const unsigned int kUsbLeftOption = 0x0700e2;
const unsigned int kUsbLeftCmd = 0x0700e3;
const unsigned int kUsbRightCmd = 0x0700e7;
static const uint32 kTestLockStates = protocol::KeyEvent::LOCK_STATES_NUMLOCK;
MATCHER_P2(EqualsUsbEvent, 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;
}
}
TEST(NormalizingInputFilterMacTest, CapsLock) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(EqualsUsbEvent(kUsbCapsLock, true)));
EXPECT_CALL(stub, InjectKeyEvent(EqualsUsbEvent(kUsbCapsLock, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbCapsLock, true));
}
TEST(NormalizingInputFilterMacTest, NoInjection) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
}
processor->InjectKeyEvent(MakeKeyEvent('C', true));
processor->InjectKeyEvent(MakeKeyEvent('C', false));
}
TEST(NormalizingInputFilterMacTest, CmdKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('V', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('V', false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, true));
processor->InjectKeyEvent(MakeKeyEvent('C', true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, false));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, true));
processor->InjectKeyEvent(MakeKeyEvent('C', true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, false));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, true));
processor->InjectKeyEvent(MakeKeyEvent('C', true));
processor->InjectKeyEvent(MakeKeyEvent('V', true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, false));
}
TEST(NormalizingInputFilterMacTest, SpecialKeys) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftShift, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftShift, false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftOption, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftOption, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftShift, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, false));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftShift, false));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOption, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, false));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftOption, false));
}
TEST(NormalizingInputFilterMacTest, MultipleCmdKeys) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbLeftCmd, false)));
}
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, true));
processor->InjectKeyEvent(MakeKeyEvent('C', true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbLeftCmd, false));
}
TEST(NormalizingInputFilterMacTest, BeforeCmdKey) {
MockInputStub stub;
scoped_ptr<protocol::InputFilter> processor =
CreateNormalizingInputFilter(&stub);
{
InSequence s;
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, true)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent(kUsbRightCmd, false)));
EXPECT_CALL(stub, InjectKeyEvent(
EqualsUsbEvent('C', false)));
}
processor->InjectKeyEvent(MakeKeyEvent('C', true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, true));
processor->InjectKeyEvent(MakeKeyEvent(kUsbRightCmd, false));
processor->InjectKeyEvent(MakeKeyEvent('C', false));
}
}