Index: chrome/browser/ui/ash/event_rewriter_unittest.cc |
diff --git a/chrome/browser/ui/ash/event_rewriter_unittest.cc b/chrome/browser/ui/ash/event_rewriter_unittest.cc |
index 1e2d608deac0aca6a4bb7ce598176a595e294463..4403d3d4c4e70bb9a0de722b39d15987da93d269 100644 |
--- a/chrome/browser/ui/ash/event_rewriter_unittest.cc |
+++ b/chrome/browser/ui/ash/event_rewriter_unittest.cc |
@@ -18,6 +18,8 @@ |
#include <X11/XF86keysym.h> |
#include <X11/Xlib.h> |
+#include "ash/magnifier/magnification_controller.h" |
+#include "ash/shell.h" |
#include "ash/test/ash_test_base.h" |
#include "ash/wm/window_state.h" |
#include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
@@ -2339,6 +2341,12 @@ class EventRewriterAshTest : public ash::test::AshTestBase { |
return rewriter_.RewriteFunctionKeys(event); |
} |
+ bool RewriteAccessibilityKey( |
+ ui::KeyEvent* event, |
+ ash::EventRewriterDelegate::Action* action) { |
+ return rewriter_.RewriteAccessibilityKeys(event, action); |
+ } |
+ |
protected: |
TestingPrefServiceSyncable prefs_; |
@@ -2459,4 +2467,77 @@ TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { |
} |
} |
+TEST_F(EventRewriterAshTest, MagnifierAccelerators) { |
+ ash::MagnificationController::ScopedMagnifierAcceleratorsEnablerForTest |
+ enabler; |
+ ash::Shell::GetInstance()->magnification_controller()->SetEnabled(true); |
+ |
+ ui::ScopedXI2Event xev_up; |
+ ash::EventRewriterDelegate::Action action = |
+ ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; |
+ |
+ // Press and hold. |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_SHIFT_DOWN); |
+ ui::KeyEvent press_up(xev_up, false); |
+ EXPECT_TRUE(RewriteAccessibilityKey(&press_up, &action)); |
+ EXPECT_EQ(ash::EventRewriterDelegate::ACTION_DROP_EVENT, action); |
+ } |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_SHIFT_DOWN); |
+ ui::KeyEvent press_hold_up(xev_up, false); |
+ EXPECT_TRUE(RewriteAccessibilityKey(&press_hold_up, &action)); |
+ EXPECT_EQ(ash::EventRewriterDelegate::ACTION_REWRITE_EVENT, action); |
+ |
+ EXPECT_EQ(ui::VKEY_NUMPAD6, press_hold_up.key_code()); |
+ EXPECT_TRUE(press_hold_up.flags() & ui::EF_SHIFT_DOWN); |
+ } |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_UP, 0); |
+ ui::KeyEvent release_up(xev_up, false); |
+ EXPECT_TRUE(RewriteAccessibilityKey(&release_up, &action)); |
+ EXPECT_EQ(ash::EventRewriterDelegate::ACTION_REWRITE_EVENT, action); |
+ |
+ EXPECT_EQ(ui::VKEY_NUMPAD6, release_up.key_code()); |
+ EXPECT_FALSE(release_up.flags() & ui::EF_SHIFT_DOWN); |
+ } |
+ |
+ // Press and Release |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_SHIFT_DOWN); |
+ ui::KeyEvent press_up(xev_up, false); |
+ EXPECT_TRUE(RewriteAccessibilityKey(&press_up, &action)); |
+ EXPECT_EQ(ash::EventRewriterDelegate::ACTION_DROP_EVENT, action); |
+ } |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_UP, 0); |
+ ui::KeyEvent release_up(xev_up, false); |
+ EXPECT_TRUE(RewriteAccessibilityKey(&release_up, &action)); |
+ EXPECT_EQ(ash::EventRewriterDelegate::ACTION_REWRITE_EVENT, action); |
+ |
+ EXPECT_EQ(ui::VKEY_UP, release_up.key_code()); |
+ EXPECT_EQ(ui::ET_KEY_PRESSED, release_up.type()); |
+ // The press event should have shift-down even if the release event |
+ // didn't. |
+ EXPECT_TRUE(release_up.flags() & ui::EF_SHIFT_DOWN); |
+ } |
+ |
+ // Make sure that we don't rewrite events when the magnifier is off. |
+ ash::Shell::GetInstance()->magnification_controller()->SetEnabled(false); |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_SHIFT_DOWN); |
+ ui::KeyEvent press_up(xev_up, false); |
+ EXPECT_FALSE(RewriteAccessibilityKey(&press_up, &action)); |
+ EXPECT_EQ(ui::ET_KEY_PRESSED, press_up.type()); |
+ EXPECT_EQ(ui::VKEY_UP, press_up.key_code()); |
+ } |
+ { |
+ xev_up.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_UP, ui::EF_SHIFT_DOWN); |
+ ui::KeyEvent release_up(xev_up, false); |
+ EXPECT_FALSE(RewriteAccessibilityKey(&release_up, &action)); |
+ EXPECT_EQ(ui::ET_KEY_RELEASED, release_up.type()); |
+ EXPECT_EQ(ui::VKEY_UP, release_up.key_code()); |
+ } |
+} |
+ |
#endif // OS_CHROMEOS |