OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/events/event_rewriter.h" | 5 #include "chrome/browser/chromeos/events/event_rewriter.h" |
6 | 6 |
7 #include <X11/keysym.h> | 7 #include <X11/keysym.h> |
8 #include <X11/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #undef Bool | 10 #undef Bool |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
33 #include "ui/events/event.h" | 33 #include "ui/events/event.h" |
34 #include "ui/events/event_rewriter.h" | 34 #include "ui/events/event_rewriter.h" |
35 #include "ui/events/test/events_test_utils_x11.h" | 35 #include "ui/events/test/events_test_utils_x11.h" |
36 #include "ui/events/x/touch_factory_x11.h" | 36 #include "ui/events/x/touch_factory_x11.h" |
37 #include "ui/gfx/x/x11_types.h" | 37 #include "ui/gfx/x/x11_types.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 std::string GetExpectedResultAsString(ui::KeyboardCode ui_keycode, | 41 std::string GetExpectedResultAsString(ui::KeyboardCode ui_keycode, |
kpschoedel
2014/06/02 00:52:36
All changes to this file in this patch set are fro
| |
42 int ui_flags, | 42 int ui_flags, |
43 ui::EventType ui_type) { | 43 ui::EventType ui_type) { |
44 return base::StringPrintf("ui_keycode=0x%X ui_flags=0x%X ui_type=%d", | 44 return base::StringPrintf("ui_keycode=0x%X ui_flags=0x%X ui_type=%d", |
45 ui_keycode, | 45 ui_keycode, |
46 ui_flags, | 46 ui_flags, |
47 ui_type); | 47 ui_type); |
48 } | 48 } |
49 | 49 |
50 std::string GetKeyEventAsString(const ui::KeyEvent& keyevent) { | 50 std::string GetKeyEventAsString(const ui::KeyEvent& keyevent) { |
51 return GetExpectedResultAsString( | 51 return GetExpectedResultAsString( |
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1558 // rewritten to the back key. | 1558 // rewritten to the back key. |
1559 send_function_keys_pref.SetValue(false); | 1559 send_function_keys_pref.SetValue(false); |
1560 ASSERT_TRUE(RewriteFunctionKeys(press_f1, &rewritten_event)); | 1560 ASSERT_TRUE(RewriteFunctionKeys(press_f1, &rewritten_event)); |
1561 ASSERT_TRUE(rewritten_event); | 1561 ASSERT_TRUE(rewritten_event); |
1562 EXPECT_EQ(GetExpectedResultAsString( | 1562 EXPECT_EQ(GetExpectedResultAsString( |
1563 ui::VKEY_BROWSER_BACK, ui::EF_NONE, ui::ET_KEY_PRESSED), | 1563 ui::VKEY_BROWSER_BACK, ui::EF_NONE, ui::ET_KEY_PRESSED), |
1564 GetKeyEventAsString( | 1564 GetKeyEventAsString( |
1565 *static_cast<const ui::KeyEvent*>(rewritten_event.get()))); | 1565 *static_cast<const ui::KeyEvent*>(rewritten_event.get()))); |
1566 } | 1566 } |
1567 | 1567 |
1568 TEST_F(EventRewriterTest, TestRewrittenModifierClick) { | |
1569 std::vector<unsigned int> device_list; | |
1570 device_list.push_back(10); | |
1571 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); | |
1572 | |
1573 // Remap Control to Alt. | |
1574 TestingPrefServiceSyncable prefs; | |
1575 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | |
1576 IntegerPrefMember control; | |
1577 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); | |
1578 control.SetValue(chromeos::input_method::kAltKey); | |
1579 | |
1580 EventRewriter rewriter; | |
1581 rewriter.set_pref_service_for_testing(&prefs); | |
1582 | |
1583 // Check that Control + Left Button is converted (via Alt + Left Button) | |
1584 // to Right Button. | |
1585 ui::ScopedXI2Event xev; | |
1586 xev.InitGenericButtonEvent(10, | |
1587 ui::ET_MOUSE_PRESSED, | |
1588 gfx::Point(), | |
1589 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN); | |
1590 ui::MouseEvent press(xev); | |
1591 // Sanity check. | |
1592 EXPECT_EQ(ui::ET_MOUSE_PRESSED, press.type()); | |
1593 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN, press.flags()); | |
1594 int flags = RewriteMouseEvent(&rewriter, press); | |
1595 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & flags); | |
1596 EXPECT_FALSE(ui::EF_CONTROL_DOWN & flags); | |
1597 EXPECT_FALSE(ui::EF_ALT_DOWN & flags); | |
1598 } | |
1599 | |
1600 | |
1568 TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { | 1601 TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { |
1569 std::vector<unsigned int> device_list; | 1602 std::vector<unsigned int> device_list; |
1570 device_list.push_back(10); | 1603 device_list.push_back(10); |
1571 device_list.push_back(11); | 1604 device_list.push_back(11); |
1572 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); | 1605 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); |
1573 TestingPrefServiceSyncable prefs; | 1606 TestingPrefServiceSyncable prefs; |
1574 EventRewriter rewriter; | 1607 EventRewriter rewriter; |
1575 rewriter.set_pref_service_for_testing(&prefs); | 1608 rewriter.set_pref_service_for_testing(&prefs); |
1576 const int kLeftAndAltFlag = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN; | 1609 const int kLeftAndAltFlag = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN; |
1577 { | 1610 { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1633 ui::ScopedXI2Event xev; | 1666 ui::ScopedXI2Event xev; |
1634 xev.InitGenericButtonEvent( | 1667 xev.InitGenericButtonEvent( |
1635 11, ui::ET_MOUSE_RELEASED, gfx::Point(), kLeftAndAltFlag); | 1668 11, ui::ET_MOUSE_RELEASED, gfx::Point(), kLeftAndAltFlag); |
1636 ui::MouseEvent release(xev); | 1669 ui::MouseEvent release(xev); |
1637 int flags = RewriteMouseEvent(&rewriter, release); | 1670 int flags = RewriteMouseEvent(&rewriter, release); |
1638 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & flags); | 1671 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & flags); |
1639 } | 1672 } |
1640 } | 1673 } |
1641 | 1674 |
1642 } // namespace chromeos | 1675 } // namespace chromeos |
OLD | NEW |