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/events/event.h"
12 #include <X11/keysym.h>
14 #include "ui/events/test/events_test_utils_x11.h"
15 #include "ui/gfx/x/x11_types.h"
20 // Checks that MakeWebKeyboardEvent makes a DOM3 spec compliant key event.
22 TEST(WebInputEventAuraTest
, TestMakeWebKeyboardEvent
) {
24 ui::ScopedXI2Event xev
;
27 xev
.InitKeyEvent(ui::ET_KEY_PRESSED
, ui::VKEY_CONTROL
, 0);
28 ui::KeyEvent
event(xev
, false /* is_char */);
29 blink::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
30 // However, modifier bit for Control in |webkit_event| should be set.
31 EXPECT_EQ(webkit_event
.modifiers
, blink::WebInputEvent::ControlKey
);
35 xev
.InitKeyEvent(ui::ET_KEY_RELEASED
, ui::VKEY_CONTROL
, ControlMask
);
36 ui::KeyEvent
event(xev
, false /* is_char */);
37 blink::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
38 // However, modifier bit for Control in |webkit_event| shouldn't be set.
39 EXPECT_EQ(webkit_event
.modifiers
, 0);
44 // Checks that MakeWebKeyboardEvent returns a correct windowsKeyCode.
45 TEST(WebInputEventAuraTest
, TestMakeWebKeyboardEventWindowsKeyCode
) {
47 ui::ScopedXI2Event xev
;
50 xev
.InitKeyEvent(ui::ET_KEY_PRESSED
, ui::VKEY_CONTROL
, 0);
52 xevent
->xkey
.keycode
= XKeysymToKeycode(gfx::GetXDisplay(), XK_Control_L
);
53 ui::KeyEvent
event(xev
, false /* is_char */);
54 blink::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
55 // ui::VKEY_LCONTROL, instead of ui::VKEY_CONTROL, should be filled.
56 EXPECT_EQ(ui::VKEY_LCONTROL
, webkit_event
.windowsKeyCode
);
60 xev
.InitKeyEvent(ui::ET_KEY_PRESSED
, ui::VKEY_CONTROL
, 0);
62 xevent
->xkey
.keycode
= XKeysymToKeycode(gfx::GetXDisplay(), XK_Control_R
);
63 ui::KeyEvent
event(xev
, false /* is_char */);
64 blink::WebKeyboardEvent webkit_event
= MakeWebKeyboardEvent(&event
);
65 // ui::VKEY_RCONTROL, instead of ui::VKEY_CONTROL, should be filled.
66 EXPECT_EQ(ui::VKEY_RCONTROL
, webkit_event
.windowsKeyCode
);
69 // TODO(yusukes): Add tests for win_aura once keyboardEvent() in
70 // third_party/WebKit/Source/web/win/WebInputEventFactory.cpp is modified
71 // to return VKEY_[LR]XXX instead of VKEY_XXX.
72 // https://bugs.webkit.org/show_bug.cgi?id=86694
76 } // namespace content