Chromium Code Reviews| 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 "ash/sticky_keys/sticky_keys_overlay.h" | 5 #include "ash/sticky_keys/sticky_keys_overlay.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | |
| 8 #include "ash/display/display_manager.h" | |
| 7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 8 #include "ash/sticky_keys/sticky_keys_controller.h" | 10 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 9 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 10 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 13 #include "ui/views/widget/widget.h" | |
| 11 | 14 |
| 12 namespace ash { | 15 namespace ash { |
| 13 | 16 |
| 14 class StickyKeysOverlayTest : public test::AshTestBase { | 17 using StickyKeysOverlayTest = test::AshTestBase; |
| 15 public: | |
| 16 StickyKeysOverlayTest() {} | |
| 17 virtual ~StickyKeysOverlayTest() {} | |
| 18 }; | |
| 19 | 18 |
| 20 TEST_F(StickyKeysOverlayTest, OverlayVisibility) { | 19 TEST_F(StickyKeysOverlayTest, OverlayVisibility) { |
| 21 StickyKeysOverlay overlay; | 20 StickyKeysOverlay overlay; |
| 22 EXPECT_FALSE(overlay.is_visible()); | 21 EXPECT_FALSE(overlay.is_visible()); |
| 23 overlay.Show(true); | 22 overlay.Show(true); |
| 24 EXPECT_TRUE(overlay.is_visible()); | 23 EXPECT_TRUE(overlay.is_visible()); |
| 25 } | 24 } |
| 26 | 25 |
| 27 TEST_F(StickyKeysOverlayTest, ModifierKeyState) { | 26 TEST_F(StickyKeysOverlayTest, ModifierKeyState) { |
| 28 StickyKeysOverlay overlay; | 27 StickyKeysOverlay overlay; |
| 29 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED); | 28 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED); |
| 30 overlay.SetModifierKeyState(ui::EF_ALT_DOWN, STICKY_KEY_STATE_LOCKED); | 29 overlay.SetModifierKeyState(ui::EF_ALT_DOWN, STICKY_KEY_STATE_LOCKED); |
| 31 overlay.SetModifierKeyState(ui::EF_CONTROL_DOWN, STICKY_KEY_STATE_ENABLED); | 30 overlay.SetModifierKeyState(ui::EF_CONTROL_DOWN, STICKY_KEY_STATE_ENABLED); |
| 32 overlay.SetModifierKeyState(ui::EF_COMMAND_DOWN, STICKY_KEY_STATE_LOCKED); | 31 overlay.SetModifierKeyState(ui::EF_COMMAND_DOWN, STICKY_KEY_STATE_LOCKED); |
| 33 | 32 |
| 34 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, | 33 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, |
| 35 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); | 34 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); |
| 36 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, | 35 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, |
| 37 overlay.GetModifierKeyState(ui::EF_ALT_DOWN)); | 36 overlay.GetModifierKeyState(ui::EF_ALT_DOWN)); |
| 38 EXPECT_EQ(STICKY_KEY_STATE_ENABLED, | 37 EXPECT_EQ(STICKY_KEY_STATE_ENABLED, |
| 39 overlay.GetModifierKeyState(ui::EF_CONTROL_DOWN)); | 38 overlay.GetModifierKeyState(ui::EF_CONTROL_DOWN)); |
| 40 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, | 39 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, |
| 41 overlay.GetModifierKeyState(ui::EF_COMMAND_DOWN)); | 40 overlay.GetModifierKeyState(ui::EF_COMMAND_DOWN)); |
| 42 } | 41 } |
| 43 | 42 |
| 43 // This test addresses the crash report at crbug.com/435600, speculated to be | |
| 44 // caused by using sticky keys with multiple displays. | |
| 45 TEST_F(StickyKeysOverlayTest, OverlayNotDestroyedAfterDisplayRemoved) { | |
| 46 // Add a secondary display to the left of the primary one. | |
| 47 UpdateDisplay("1280x1024,1980x1080"); | |
| 48 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 49 DisplayIdPair display_ids = display_manager->GetCurrentDisplayIdPair(); | |
| 50 int64 primary_display_id = display_ids.first; | |
|
James Cook
2014/12/04 22:00:45
nit: int64_t and next line too
Tim Song
2014/12/04 23:53:37
Done.
| |
| 51 int64 secondary_display_id = display_ids.second; | |
| 52 display_manager->SetLayoutForCurrentDisplays( | |
| 53 DisplayLayout(DisplayLayout::LEFT, 0)); | |
| 54 | |
| 55 // The overlay should belong to the secondary root window. | |
| 56 StickyKeysOverlay overlay; | |
| 57 views::Widget* overlay_widget = overlay.GetWidgetForTesting(); | |
| 58 DisplayController* display_controller = | |
| 59 Shell::GetInstance()->display_controller(); | |
| 60 EXPECT_EQ(display_controller->GetRootWindowForDisplayId(secondary_display_id), | |
| 61 overlay_widget->GetNativeWindow()->GetRootWindow()); | |
| 62 | |
| 63 // Removing the second display should move the overlay to the primary root | |
| 64 // window. | |
| 65 UpdateDisplay("1280x1024"); | |
| 66 EXPECT_EQ(display_controller->GetRootWindowForDisplayId(primary_display_id), | |
| 67 overlay_widget->GetNativeWindow()->GetRootWindow()); | |
| 68 | |
| 69 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_ENABLED); | |
| 70 EXPECT_EQ(STICKY_KEY_STATE_ENABLED, | |
| 71 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); | |
| 72 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED); | |
| 73 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, | |
| 74 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); | |
| 75 } | |
|
James Cook
2014/12/04 22:00:45
Much better test!
Tim Song
2014/12/04 23:53:37
Thanks!
| |
| 76 | |
| 44 // Additional sticky key overlay tests that depend on chromeos::EventRewriter | 77 // Additional sticky key overlay tests that depend on chromeos::EventRewriter |
| 45 // are now in chrome/browser/chromeos/events/event_rewriter_unittest.cc . | 78 // are now in chrome/browser/chromeos/events/event_rewriter_unittest.cc . |
| 46 | 79 |
| 47 } // namespace ash | 80 } // namespace ash |
| OLD | NEW |