| 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/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/sticky_keys/sticky_keys_controller.h" | 8 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 #include "ui/views/widget/widget.h" | |
| 12 | 11 |
| 13 namespace ash { | 12 namespace ash { |
| 14 | 13 |
| 15 using StickyKeysOverlayTest = test::AshTestBase; | 14 class StickyKeysOverlayTest : public test::AshTestBase { |
| 15 public: |
| 16 StickyKeysOverlayTest() {} |
| 17 virtual ~StickyKeysOverlayTest() {} |
| 18 }; |
| 16 | 19 |
| 17 TEST_F(StickyKeysOverlayTest, OverlayVisibility) { | 20 TEST_F(StickyKeysOverlayTest, OverlayVisibility) { |
| 18 StickyKeysOverlay overlay; | 21 StickyKeysOverlay overlay; |
| 19 EXPECT_FALSE(overlay.is_visible()); | 22 EXPECT_FALSE(overlay.is_visible()); |
| 20 overlay.Show(true); | 23 overlay.Show(true); |
| 21 EXPECT_TRUE(overlay.is_visible()); | 24 EXPECT_TRUE(overlay.is_visible()); |
| 22 } | 25 } |
| 23 | 26 |
| 24 TEST_F(StickyKeysOverlayTest, ModifierKeyState) { | 27 TEST_F(StickyKeysOverlayTest, ModifierKeyState) { |
| 25 StickyKeysOverlay overlay; | 28 StickyKeysOverlay overlay; |
| 26 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED); | 29 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED); |
| 27 overlay.SetModifierKeyState(ui::EF_ALT_DOWN, STICKY_KEY_STATE_LOCKED); | 30 overlay.SetModifierKeyState(ui::EF_ALT_DOWN, STICKY_KEY_STATE_LOCKED); |
| 28 overlay.SetModifierKeyState(ui::EF_CONTROL_DOWN, STICKY_KEY_STATE_ENABLED); | 31 overlay.SetModifierKeyState(ui::EF_CONTROL_DOWN, STICKY_KEY_STATE_ENABLED); |
| 29 overlay.SetModifierKeyState(ui::EF_COMMAND_DOWN, STICKY_KEY_STATE_LOCKED); | 32 overlay.SetModifierKeyState(ui::EF_COMMAND_DOWN, STICKY_KEY_STATE_LOCKED); |
| 30 | 33 |
| 31 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, | 34 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, |
| 32 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); | 35 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); |
| 33 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, | 36 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, |
| 34 overlay.GetModifierKeyState(ui::EF_ALT_DOWN)); | 37 overlay.GetModifierKeyState(ui::EF_ALT_DOWN)); |
| 35 EXPECT_EQ(STICKY_KEY_STATE_ENABLED, | 38 EXPECT_EQ(STICKY_KEY_STATE_ENABLED, |
| 36 overlay.GetModifierKeyState(ui::EF_CONTROL_DOWN)); | 39 overlay.GetModifierKeyState(ui::EF_CONTROL_DOWN)); |
| 37 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, | 40 EXPECT_EQ(STICKY_KEY_STATE_LOCKED, |
| 38 overlay.GetModifierKeyState(ui::EF_COMMAND_DOWN)); | 41 overlay.GetModifierKeyState(ui::EF_COMMAND_DOWN)); |
| 39 } | 42 } |
| 40 | 43 |
| 41 // This test attempts to simulate a crash report (see //crbug.com/435600). | |
| 42 // The crash is speculated to be caused by the native window of the sticky keys | |
| 43 // overlay widget being destroyed before the overlay object is. This test case | |
| 44 // tests that the overlay object maintains full ownership of the widget and view | |
| 45 // regardless. | |
| 46 TEST_F(StickyKeysOverlayTest, OverlayViewOwnership) { | |
| 47 StickyKeysOverlay overlay; | |
| 48 views::Widget* widget = overlay.GetWidgetForTesting(); | |
| 49 ASSERT_TRUE(widget); | |
| 50 delete widget->GetNativeWindow(); | |
| 51 | |
| 52 // States should still be valid even after the native window associated with | |
| 53 // the Widget is destroyed. | |
| 54 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_ENABLED); | |
| 55 EXPECT_EQ(STICKY_KEY_STATE_ENABLED, | |
| 56 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); | |
| 57 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED); | |
| 58 EXPECT_EQ(STICKY_KEY_STATE_DISABLED, | |
| 59 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN)); | |
| 60 } | |
| 61 | |
| 62 // Additional sticky key overlay tests that depend on chromeos::EventRewriter | 44 // Additional sticky key overlay tests that depend on chromeos::EventRewriter |
| 63 // are now in chrome/browser/chromeos/events/event_rewriter_unittest.cc . | 45 // are now in chrome/browser/chromeos/events/event_rewriter_unittest.cc . |
| 64 | 46 |
| 65 } // namespace ash | 47 } // namespace ash |
| OLD | NEW |