OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/web_input_event_aura.h" | 5 #include "content/browser/renderer_host/web_input_event_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_EQ(ui::VKEY_RCONTROL, webkit_event.windowsKeyCode); | 66 EXPECT_EQ(ui::VKEY_RCONTROL, webkit_event.windowsKeyCode); |
67 } | 67 } |
68 #elif defined(OS_WIN) | 68 #elif defined(OS_WIN) |
69 // TODO(yusukes): Add tests for win_aura once keyboardEvent() in | 69 // TODO(yusukes): Add tests for win_aura once keyboardEvent() in |
70 // third_party/WebKit/Source/web/win/WebInputEventFactory.cpp is modified | 70 // third_party/WebKit/Source/web/win/WebInputEventFactory.cpp is modified |
71 // to return VKEY_[LR]XXX instead of VKEY_XXX. | 71 // to return VKEY_[LR]XXX instead of VKEY_XXX. |
72 // https://bugs.webkit.org/show_bug.cgi?id=86694 | 72 // https://bugs.webkit.org/show_bug.cgi?id=86694 |
73 #endif | 73 #endif |
74 } | 74 } |
75 | 75 |
| 76 // Checks that MakeWebKeyboardEvent fills a correct keypard modifier. |
| 77 TEST(WebInputEventAuraTest, TestMakeWebKeyboardEventKeyPadKeyCode) { |
| 78 #if defined(USE_X11) |
| 79 struct TestCase { |
| 80 ui::KeyboardCode ui_keycode; // The virtual key code. |
| 81 uint32 x_keycode; // The platform key code. |
| 82 bool expected_result; // true if the event has "isKeyPad" modifier. |
| 83 } kTesCases[] = { |
| 84 {ui::VKEY_0, XK_0, false}, |
| 85 {ui::VKEY_1, XK_1, false}, |
| 86 {ui::VKEY_2, XK_2, false}, |
| 87 {ui::VKEY_3, XK_3, false}, |
| 88 {ui::VKEY_4, XK_4, false}, |
| 89 {ui::VKEY_5, XK_5, false}, |
| 90 {ui::VKEY_6, XK_6, false}, |
| 91 {ui::VKEY_7, XK_7, false}, |
| 92 {ui::VKEY_8, XK_8, false}, |
| 93 {ui::VKEY_9, XK_9, false}, |
| 94 |
| 95 {ui::VKEY_NUMPAD0, XK_KP_0, true}, |
| 96 {ui::VKEY_NUMPAD1, XK_KP_1, true}, |
| 97 {ui::VKEY_NUMPAD2, XK_KP_2, true}, |
| 98 {ui::VKEY_NUMPAD3, XK_KP_3, true}, |
| 99 {ui::VKEY_NUMPAD4, XK_KP_4, true}, |
| 100 {ui::VKEY_NUMPAD5, XK_KP_5, true}, |
| 101 {ui::VKEY_NUMPAD6, XK_KP_6, true}, |
| 102 {ui::VKEY_NUMPAD7, XK_KP_7, true}, |
| 103 {ui::VKEY_NUMPAD8, XK_KP_8, true}, |
| 104 {ui::VKEY_NUMPAD9, XK_KP_9, true}, |
| 105 |
| 106 {ui::VKEY_MULTIPLY, XK_KP_Multiply, true}, |
| 107 {ui::VKEY_SUBTRACT, XK_KP_Subtract, true}, |
| 108 {ui::VKEY_ADD, XK_KP_Add, true}, |
| 109 {ui::VKEY_DIVIDE, XK_KP_Divide, true}, |
| 110 {ui::VKEY_DECIMAL, XK_KP_Decimal, true}, |
| 111 {ui::VKEY_DELETE, XK_KP_Delete, true}, |
| 112 {ui::VKEY_INSERT, XK_KP_Insert, true}, |
| 113 {ui::VKEY_END, XK_KP_End, true}, |
| 114 {ui::VKEY_DOWN, XK_KP_Down, true}, |
| 115 {ui::VKEY_NEXT, XK_KP_Page_Down, true}, |
| 116 {ui::VKEY_LEFT, XK_KP_Left, true}, |
| 117 {ui::VKEY_CLEAR, XK_KP_Begin, true}, |
| 118 {ui::VKEY_RIGHT, XK_KP_Right, true}, |
| 119 {ui::VKEY_HOME, XK_KP_Home, true}, |
| 120 {ui::VKEY_UP, XK_KP_Up, true}, |
| 121 {ui::VKEY_PRIOR, XK_KP_Page_Up, true}, |
| 122 }; |
| 123 ui::ScopedXI2Event xev; |
| 124 for (size_t i = 0; i < arraysize(kTesCases); ++i) { |
| 125 const TestCase& test_case = kTesCases[i]; |
| 126 |
| 127 xev.InitKeyEvent(ui::ET_KEY_PRESSED, test_case.ui_keycode, 0); |
| 128 XEvent* xevent = xev; |
| 129 xevent->xkey.keycode = XKeysymToKeycode(gfx::GetXDisplay(), |
| 130 test_case.x_keycode); |
| 131 ui::KeyEvent event(xev); |
| 132 blink::WebKeyboardEvent webkit_event = MakeWebKeyboardEvent(&event); |
| 133 EXPECT_EQ(test_case.expected_result, |
| 134 (webkit_event.modifiers & blink::WebInputEvent::IsKeyPad) != 0) |
| 135 << "Failed in " << i << "th test case: " |
| 136 << "{ui_keycode:" << test_case.ui_keycode |
| 137 << ", x_keycode:" << test_case.x_keycode |
| 138 << "}, expect: " << test_case.expected_result; |
| 139 } |
| 140 #endif |
| 141 } |
| 142 |
76 } // namespace content | 143 } // namespace content |
OLD | NEW |