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 "chrome/browser/ui/ash/event_rewriter.h" | 5 #include "chrome/browser/ui/ash/event_rewriter.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/prefs/pref_member.h" | 9 #include "chrome/browser/prefs/pref_member.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "chrome/test/base/testing_pref_service.h" | 11 #include "chrome/test/base/testing_pref_service.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/aura/event.h" | 13 #include "ui/base/event.h" |
14 | 14 |
15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
16 #include <X11/keysym.h> | 16 #include <X11/keysym.h> |
17 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
18 | 18 |
19 #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" | 19 #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" |
20 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 20 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
21 #include "chrome/browser/chromeos/preferences.h" | 21 #include "chrome/browser/chromeos/preferences.h" |
22 #include "ui/base/x/x11_util.h" | 22 #include "ui/base/x/x11_util.h" |
23 | 23 |
(...skipping 14 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 std::string GetRewrittenEventAsString(EventRewriter* rewriter, | 40 std::string GetRewrittenEventAsString(EventRewriter* rewriter, |
41 ui::KeyboardCode ui_keycode, | 41 ui::KeyboardCode ui_keycode, |
42 int ui_flags, | 42 int ui_flags, |
43 ui::EventType ui_type, | 43 ui::EventType ui_type, |
44 KeyCode x_keycode, | 44 KeyCode x_keycode, |
45 unsigned int x_state) { | 45 unsigned int x_state) { |
46 XEvent xev; | 46 XEvent xev; |
47 InitXKeyEvent(ui_keycode, ui_flags, ui_type, x_keycode, x_state, &xev); | 47 InitXKeyEvent(ui_keycode, ui_flags, ui_type, x_keycode, x_state, &xev); |
48 aura::KeyEvent keyevent(&xev, false /* is_char */); | 48 ui::KeyEvent keyevent(&xev, false /* is_char */); |
49 rewriter->RewriteForTesting(&keyevent); | 49 rewriter->RewriteForTesting(&keyevent); |
50 return StringPrintf( | 50 return StringPrintf( |
51 "ui_keycode=%d ui_flags=%d ui_type=%d x_keycode=%u x_state=%u x_type=%d", | 51 "ui_keycode=%d ui_flags=%d ui_type=%d x_keycode=%u x_state=%u x_type=%d", |
52 keyevent.key_code(), keyevent.flags(), keyevent.type(), | 52 keyevent.key_code(), keyevent.flags(), keyevent.type(), |
53 xev.xkey.keycode, xev.xkey.state, xev.xkey.type); | 53 xev.xkey.keycode, xev.xkey.state, xev.xkey.type); |
54 } | 54 } |
55 | 55 |
56 std::string GetExpectedResultAsString(ui::KeyboardCode ui_keycode, | 56 std::string GetExpectedResultAsString(ui::KeyboardCode ui_keycode, |
57 int ui_flags, | 57 int ui_flags, |
58 ui::EventType ui_type, | 58 ui::EventType ui_type, |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 EventRewriter rewriter; | 1620 EventRewriter rewriter; |
1621 rewriter.set_pref_service_for_testing(&prefs); | 1621 rewriter.set_pref_service_for_testing(&prefs); |
1622 | 1622 |
1623 // Send left control press. | 1623 // Send left control press. |
1624 std::string rewritten_event; | 1624 std::string rewritten_event; |
1625 { | 1625 { |
1626 XEvent xev; | 1626 XEvent xev; |
1627 InitXKeyEvent(ui::VKEY_CONTROL, 0, ui::ET_KEY_PRESSED, | 1627 InitXKeyEvent(ui::VKEY_CONTROL, 0, ui::ET_KEY_PRESSED, |
1628 keycode_control_l_, 0U, &xev); | 1628 keycode_control_l_, 0U, &xev); |
1629 xev.xkey.send_event = True; // XSendEvent() always does this. | 1629 xev.xkey.send_event = True; // XSendEvent() always does this. |
1630 aura::KeyEvent keyevent(&xev, false /* is_char */); | 1630 ui::KeyEvent keyevent(&xev, false /* is_char */); |
1631 rewriter.RewriteForTesting(&keyevent); | 1631 rewriter.RewriteForTesting(&keyevent); |
1632 rewritten_event = StringPrintf( | 1632 rewritten_event = StringPrintf( |
1633 "ui_keycode=%d ui_flags=%d ui_type=%d " | 1633 "ui_keycode=%d ui_flags=%d ui_type=%d " |
1634 "x_keycode=%u x_state=%u x_type=%d", | 1634 "x_keycode=%u x_state=%u x_type=%d", |
1635 keyevent.key_code(), keyevent.flags(), keyevent.type(), | 1635 keyevent.key_code(), keyevent.flags(), keyevent.type(), |
1636 xev.xkey.keycode, xev.xkey.state, xev.xkey.type); | 1636 xev.xkey.keycode, xev.xkey.state, xev.xkey.type); |
1637 } | 1637 } |
1638 | 1638 |
1639 // XK_Control_L (left Control key) should NOT be remapped to Alt if send_event | 1639 // XK_Control_L (left Control key) should NOT be remapped to Alt if send_event |
1640 // flag in the event is True. | 1640 // flag in the event is True. |
1641 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | 1641 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
1642 0, | 1642 0, |
1643 ui::ET_KEY_PRESSED, | 1643 ui::ET_KEY_PRESSED, |
1644 keycode_control_l_, | 1644 keycode_control_l_, |
1645 0U, | 1645 0U, |
1646 KeyPress), | 1646 KeyPress), |
1647 rewritten_event); | 1647 rewritten_event); |
1648 } | 1648 } |
1649 #endif // OS_CHROMEOS | 1649 #endif // OS_CHROMEOS |
OLD | NEW |