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 "content/browser/renderer_host/web_input_event_aura.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/events/event.h"
12 #include <X11/keysym.h>
14 #include "ui/base/x/x11_util.h"
19 // Checks that MakeWebKeyboardEvent makes a DOM3 spec compliant key event.
21 TEST(WebInputEventAuraTest
, TestMakeWebKeyboardEvent
) {
26 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED
,
28 0, // X does not set ControlMask for KeyPress.
30 ui::KeyEvent
event(&xev
, false /* is_char */);
31 WebKit::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
32 // However, modifier bit for Control in |webkit_event| should be set.
33 EXPECT_EQ(webkit_event
.modifiers
, WebKit::WebInputEvent::ControlKey
);
37 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED
,
39 ControlMask
, // X sets the mask for KeyRelease.
41 ui::KeyEvent
event(&xev
, false /* is_char */);
42 WebKit::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
43 // However, modifier bit for Control in |webkit_event| shouldn't be set.
44 EXPECT_EQ(webkit_event
.modifiers
, 0);
49 // Checks that MakeWebKeyboardEvent returns a correct windowsKeyCode.
50 TEST(WebInputEventAuraTest
, TestMakeWebKeyboardEventWindowsKeyCode
) {
55 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED
,
57 0, // X does not set ControlMask for KeyPress.
59 xev
.xkey
.keycode
= XKeysymToKeycode(ui::GetXDisplay(), XK_Control_L
);
60 ui::KeyEvent
event(&xev
, false /* is_char */);
61 WebKit::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
62 // ui::VKEY_LCONTROL, instead of ui::VKEY_CONTROL, should be filled.
63 EXPECT_EQ(ui::VKEY_LCONTROL
, webkit_event
.windowsKeyCode
);
67 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED
,
69 0, // X does not set ControlMask for KeyPress.
71 xev
.xkey
.keycode
= XKeysymToKeycode(ui::GetXDisplay(), XK_Control_R
);
72 ui::KeyEvent
event(&xev
, false /* is_char */);
73 WebKit::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
74 // ui::VKEY_RCONTROL, instead of ui::VKEY_CONTROL, should be filled.
75 EXPECT_EQ(ui::VKEY_RCONTROL
, webkit_event
.windowsKeyCode
);
78 // TODO(yusukes): Add tests for win_aura once keyboardEvent() in
79 // WebKit/Source/WebKit/chromium/src/win/WebInputEventFactory.cpp is modified
80 // to return VKEY_[LR]XXX instead of VKEY_XXX.
81 // https://bugs.webkit.org/show_bug.cgi?id=86694
85 } // namespace content