This source file includes following definitions.
- interpretKeyEvent
- setupKeyDownEvent
- interpretOSModifierKeyPress
- interpretCtrlKeyPress
- interpretTab
- interpretNewLine
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "config.h"
#include <gtest/gtest.h>
#include "WebInputEvent.h"
#include "WebInputEventConversion.h"
#include "core/editing/EditingBehavior.h"
#include "core/editing/Editor.h"
#include "core/events/EventTarget.h"
#include "core/events/KeyboardEvent.h"
#include "core/frame/Settings.h"
#include "platform/KeyboardCodes.h"
using namespace WebCore;
using namespace blink;
namespace {
class KeyboardTest : public testing::Test {
public:
const char* interpretKeyEvent(
const WebKeyboardEvent& webKeyboardEvent,
PlatformEvent::Type keyType)
{
PlatformKeyboardEventBuilder evt(webKeyboardEvent);
evt.setKeyType(keyType);
RefPtrWillBeRawPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(evt, 0);
OwnPtr<Settings> settings = Settings::create();
EditingBehavior behavior(settings->editingBehaviorType());
return behavior.interpretKeyEvent(*keyboardEvent);
}
void setupKeyDownEvent(WebKeyboardEvent* keyboardEvent,
char keyCode,
int modifiers)
{
keyboardEvent->windowsKeyCode = keyCode;
keyboardEvent->modifiers = modifiers;
keyboardEvent->type = WebInputEvent::KeyDown;
keyboardEvent->text[0] = keyCode;
keyboardEvent->setKeyIdentifierFromWindowsKeyCode();
}
const char* interpretOSModifierKeyPress(char keyCode)
{
WebKeyboardEvent keyboardEvent;
#if OS(MACOSX)
WebInputEvent::Modifiers osModifier = WebInputEvent::MetaKey;
#else
WebInputEvent::Modifiers osModifier = WebInputEvent::ControlKey;
#endif
setupKeyDownEvent(&keyboardEvent, keyCode, osModifier);
return interpretKeyEvent(keyboardEvent, PlatformEvent::RawKeyDown);
}
const char* interpretCtrlKeyPress(char keyCode)
{
WebKeyboardEvent keyboardEvent;
setupKeyDownEvent(&keyboardEvent, keyCode, WebInputEvent::ControlKey);
return interpretKeyEvent(keyboardEvent, PlatformEvent::RawKeyDown);
}
const char* interpretTab(int modifiers)
{
WebKeyboardEvent keyboardEvent;
setupKeyDownEvent(&keyboardEvent, '\t', modifiers);
return interpretKeyEvent(keyboardEvent, PlatformEvent::Char);
}
const char* interpretNewLine(int modifiers)
{
WebKeyboardEvent keyboardEvent;
setupKeyDownEvent(&keyboardEvent, '\r', modifiers);
return interpretKeyEvent(keyboardEvent, PlatformEvent::Char);
}
static const int noModifiers = 0;
};
TEST_F(KeyboardTest, TestCtrlReturn)
{
EXPECT_STREQ("InsertNewline", interpretCtrlKeyPress(0xD));
}
TEST_F(KeyboardTest, TestOSModifierZ)
{
#if !OS(MACOSX)
EXPECT_STREQ("Undo", interpretOSModifierKeyPress('Z'));
#endif
}
TEST_F(KeyboardTest, TestOSModifierY)
{
#if !OS(MACOSX)
EXPECT_STREQ("Redo", interpretOSModifierKeyPress('Y'));
#endif
}
TEST_F(KeyboardTest, TestOSModifierA)
{
#if !OS(MACOSX)
EXPECT_STREQ("SelectAll", interpretOSModifierKeyPress('A'));
#endif
}
TEST_F(KeyboardTest, TestOSModifierX)
{
#if !OS(MACOSX)
EXPECT_STREQ("Cut", interpretOSModifierKeyPress('X'));
#endif
}
TEST_F(KeyboardTest, TestOSModifierC)
{
#if !OS(MACOSX)
EXPECT_STREQ("Copy", interpretOSModifierKeyPress('C'));
#endif
}
TEST_F(KeyboardTest, TestOSModifierV)
{
#if !OS(MACOSX)
EXPECT_STREQ("Paste", interpretOSModifierKeyPress('V'));
#endif
}
TEST_F(KeyboardTest, TestEscape)
{
WebKeyboardEvent keyboardEvent;
setupKeyDownEvent(&keyboardEvent, WebCore::VKEY_ESCAPE, noModifiers);
const char* result = interpretKeyEvent(keyboardEvent,
PlatformEvent::RawKeyDown);
EXPECT_STREQ("Cancel", result);
}
TEST_F(KeyboardTest, TestInsertTab)
{
EXPECT_STREQ("InsertTab", interpretTab(noModifiers));
}
TEST_F(KeyboardTest, TestInsertBackTab)
{
EXPECT_STREQ("InsertBacktab", interpretTab(WebInputEvent::ShiftKey));
}
TEST_F(KeyboardTest, TestInsertNewline)
{
EXPECT_STREQ("InsertNewline", interpretNewLine(noModifiers));
}
TEST_F(KeyboardTest, TestInsertNewline2)
{
EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::ControlKey));
}
TEST_F(KeyboardTest, TestInsertLineBreak)
{
EXPECT_STREQ("InsertLineBreak", interpretNewLine(WebInputEvent::ShiftKey));
}
TEST_F(KeyboardTest, TestInsertNewline3)
{
EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::AltKey));
}
TEST_F(KeyboardTest, TestInsertNewline4)
{
int modifiers = WebInputEvent::AltKey | WebInputEvent::ShiftKey;
const char* result = interpretNewLine(modifiers);
EXPECT_STREQ("InsertNewline", result);
}
}