Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / web_input_event_aura_unittest.cc
blob397ef6fb61ebb12ed07ace068d497dd10292bd58
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"
11 #if defined(USE_X11)
12 #include <X11/keysym.h>
13 #include <X11/Xlib.h>
14 #include "ui/base/x/x11_util.h"
15 #endif
17 namespace content {
19 // Checks that MakeWebKeyboardEvent makes a DOM3 spec compliant key event.
20 // crbug.com/127142
21 TEST(WebInputEventAuraTest, TestMakeWebKeyboardEvent) {
22 #if defined(USE_X11)
23 XEvent xev;
25 // Press Ctrl.
26 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED,
27 ui::VKEY_CONTROL,
28 0, // X does not set ControlMask for KeyPress.
29 &xev);
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);
36 // Release Ctrl.
37 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED,
38 ui::VKEY_CONTROL,
39 ControlMask, // X sets the mask for KeyRelease.
40 &xev);
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);
46 #endif
49 // Checks that MakeWebKeyboardEvent returns a correct windowsKeyCode.
50 TEST(WebInputEventAuraTest, TestMakeWebKeyboardEventWindowsKeyCode) {
51 #if defined(USE_X11)
52 XEvent xev;
54 // Press left Ctrl.
55 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED,
56 ui::VKEY_CONTROL,
57 0, // X does not set ControlMask for KeyPress.
58 &xev);
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);
66 // Press right Ctrl.
67 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED,
68 ui::VKEY_CONTROL,
69 0, // X does not set ControlMask for KeyPress.
70 &xev);
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);
77 #elif defined(OS_WIN)
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
82 #endif
85 } // namespace content