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. 4 5 #include "content/browser/renderer_host/web_input_event_aura.h" 6 7 #include "base/basictypes.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "ui/base/events/event.h" 10 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 16 17 namespace content { 18 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; 24 { 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); 34 } 35 { 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); 45 } 46 #endif 47 } 48 49 // Checks that MakeWebKeyboardEvent returns a correct windowsKeyCode. 50 TEST(WebInputEventAuraTest, TestMakeWebKeyboardEventWindowsKeyCode) { 51 #if defined(USE_X11) 52 XEvent xev; 53 { 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); 64 } 65 { 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); 76 } 77 #elif defined(OS_WIN) 78 // TODO(yusukes): Add tests for win_aura once keyboardEvent() in 79 // third_party/WebKit/Source/web/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 83 } 84 85 } // namespace content 86