[MFYI sheriffing] Suppress warnings, widen/merge suppressions, exclude failing tests
[chromium-blink-merge.git] / content / browser / renderer_host / web_input_event_aura_unittest.cc
blob0e6fd82a7a645256206784dd9cb28b94ed871d43
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"
10 #include "ui/events/keycodes/dom3/dom_code.h"
11 #include "ui/events/keycodes/dom3/dom_key.h"
12 #include "ui/events/keycodes/dom4/keycode_converter.h"
14 #if defined(USE_X11)
15 #include <X11/keysym.h>
16 #include <X11/Xlib.h>
17 #include "ui/events/test/events_test_utils_x11.h"
18 #include "ui/gfx/x/x11_types.h"
19 #endif
21 namespace content {
23 // Checks that MakeWebKeyboardEvent makes a DOM3 spec compliant key event.
24 // crbug.com/127142
25 TEST(WebInputEventAuraTest, TestMakeWebKeyboardEvent) {
26 #if defined(USE_X11)
27 ui::ScopedXI2Event xev;
29 // Press Ctrl.
30 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, 0);
31 ui::KeyEvent event(xev);
32 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
33 // However, modifier bit for Control in |webkit_event| should be set.
34 EXPECT_EQ(webkit_event.modifiers, blink::WebInputEvent::ControlKey);
37 // Release Ctrl.
38 xev.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_CONTROL, ControlMask);
39 ui::KeyEvent event(xev);
40 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
41 // However, modifier bit for Control in |webkit_event| shouldn't be set.
42 EXPECT_EQ(webkit_event.modifiers, 0);
44 #endif
47 // Checks that MakeWebKeyboardEvent returns a correct windowsKeyCode.
48 #if defined(THREAD_SANITIZER)
49 // This test fails under ThreadSanitizer on Linux, see
50 // https://crbug.com/449103.
51 #define MAYBE_TestMakeWebKeyboardEventWindowsKeyCode \
52 DISABLED_TestMakeWebKeyboardEventWindowsKeyCode
53 #else
54 #define MAYBE_TestMakeWebKeyboardEventWindowsKeyCode \
55 TestMakeWebKeyboardEventWindowsKeyCode
56 #endif
57 TEST(WebInputEventAuraTest, MAYBE_TestMakeWebKeyboardEventWindowsKeyCode) {
58 #if defined(USE_X11)
59 ui::ScopedXI2Event xev;
61 // Press left Ctrl.
62 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, 0);
63 XEvent* xevent = xev;
64 xevent->xkey.keycode = ui::KeycodeConverter::DomCodeToNativeKeycode(
65 ui::DomCode::CONTROL_LEFT);
66 ui::KeyEvent event(xev);
67 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
68 // ui::VKEY_LCONTROL, instead of ui::VKEY_CONTROL, should be filled.
69 EXPECT_EQ(ui::VKEY_LCONTROL, webkit_event.windowsKeyCode);
72 // Press right Ctrl.
73 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, 0);
74 XEvent* xevent = xev;
75 xevent->xkey.keycode = ui::KeycodeConverter::DomCodeToNativeKeycode(
76 ui::DomCode::CONTROL_RIGHT);
77 ui::KeyEvent event(xev);
78 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
79 // ui::VKEY_RCONTROL, instead of ui::VKEY_CONTROL, should be filled.
80 EXPECT_EQ(ui::VKEY_RCONTROL, webkit_event.windowsKeyCode);
82 #elif defined(OS_WIN)
83 // TODO(yusukes): Add tests for win_aura once keyboardEvent() in
84 // third_party/WebKit/Source/web/win/WebInputEventFactory.cpp is modified
85 // to return VKEY_[LR]XXX instead of VKEY_XXX.
86 // https://bugs.webkit.org/show_bug.cgi?id=86694
87 #endif
89 // Press left Ctrl.
90 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL,
91 ui::DomCode::CONTROL_LEFT, ui::EF_CONTROL_DOWN,
92 ui::DomKey::CONTROL, 0);
93 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
94 // ui::VKEY_LCONTROL, instead of ui::VKEY_CONTROL, should be filled.
95 EXPECT_EQ(ui::VKEY_LCONTROL, webkit_event.windowsKeyCode);
98 // Press right Ctrl.
99 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_CONTROL,
100 ui::DomCode::CONTROL_RIGHT, ui::EF_CONTROL_DOWN,
101 ui::DomKey::CONTROL, 0);
102 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
103 // ui::VKEY_RCONTROL, instead of ui::VKEY_CONTROL, should be filled.
104 EXPECT_EQ(ui::VKEY_RCONTROL, webkit_event.windowsKeyCode);
108 // Checks that MakeWebKeyboardEvent fills a correct keypard modifier.
109 TEST(WebInputEventAuraTest, TestMakeWebKeyboardEventKeyPadKeyCode) {
110 #if defined(USE_X11)
111 struct TestCase {
112 ui::KeyboardCode ui_keycode; // The virtual key code.
113 uint32 x_keycode; // The platform key code.
114 bool expected_result; // true if the event has "isKeyPad" modifier.
115 } kTesCases[] = {
116 {ui::VKEY_0, XK_0, false},
117 {ui::VKEY_1, XK_1, false},
118 {ui::VKEY_2, XK_2, false},
119 {ui::VKEY_3, XK_3, false},
120 {ui::VKEY_4, XK_4, false},
121 {ui::VKEY_5, XK_5, false},
122 {ui::VKEY_6, XK_6, false},
123 {ui::VKEY_7, XK_7, false},
124 {ui::VKEY_8, XK_8, false},
125 {ui::VKEY_9, XK_9, false},
127 {ui::VKEY_NUMPAD0, XK_KP_0, true},
128 {ui::VKEY_NUMPAD1, XK_KP_1, true},
129 {ui::VKEY_NUMPAD2, XK_KP_2, true},
130 {ui::VKEY_NUMPAD3, XK_KP_3, true},
131 {ui::VKEY_NUMPAD4, XK_KP_4, true},
132 {ui::VKEY_NUMPAD5, XK_KP_5, true},
133 {ui::VKEY_NUMPAD6, XK_KP_6, true},
134 {ui::VKEY_NUMPAD7, XK_KP_7, true},
135 {ui::VKEY_NUMPAD8, XK_KP_8, true},
136 {ui::VKEY_NUMPAD9, XK_KP_9, true},
138 {ui::VKEY_MULTIPLY, XK_KP_Multiply, true},
139 {ui::VKEY_SUBTRACT, XK_KP_Subtract, true},
140 {ui::VKEY_ADD, XK_KP_Add, true},
141 {ui::VKEY_DIVIDE, XK_KP_Divide, true},
142 {ui::VKEY_DECIMAL, XK_KP_Decimal, true},
143 {ui::VKEY_DELETE, XK_KP_Delete, true},
144 {ui::VKEY_INSERT, XK_KP_Insert, true},
145 {ui::VKEY_END, XK_KP_End, true},
146 {ui::VKEY_DOWN, XK_KP_Down, true},
147 {ui::VKEY_NEXT, XK_KP_Page_Down, true},
148 {ui::VKEY_LEFT, XK_KP_Left, true},
149 {ui::VKEY_CLEAR, XK_KP_Begin, true},
150 {ui::VKEY_RIGHT, XK_KP_Right, true},
151 {ui::VKEY_HOME, XK_KP_Home, true},
152 {ui::VKEY_UP, XK_KP_Up, true},
153 {ui::VKEY_PRIOR, XK_KP_Page_Up, true},
155 ui::ScopedXI2Event xev;
156 for (size_t i = 0; i < arraysize(kTesCases); ++i) {
157 const TestCase& test_case = kTesCases[i];
159 xev.InitKeyEvent(ui::ET_KEY_PRESSED, test_case.ui_keycode, 0);
160 XEvent* xevent = xev;
161 xevent->xkey.keycode = XKeysymToKeycode(gfx::GetXDisplay(),
162 test_case.x_keycode);
163 ui::KeyEvent event(xev);
164 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(event);
165 EXPECT_EQ(test_case.expected_result,
166 (webkit_event.modifiers & blink::WebInputEvent::IsKeyPad) != 0)
167 << "Failed in " << i << "th test case: "
168 << "{ui_keycode:" << test_case.ui_keycode
169 << ", x_keycode:" << test_case.x_keycode
170 << "}, expect: " << test_case.expected_result;
172 #endif
175 } // namespace content