cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / sticky_keys / sticky_keys_overlay_unittest.cc
blobd28c5364020cd7a99440979cb50d3a71201559a9
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
3 // found in the LICENSE file.
5 #include "ash/sticky_keys/sticky_keys_overlay.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/display/window_tree_host_manager.h"
9 #include "ash/shell.h"
10 #include "ash/sticky_keys/sticky_keys_controller.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ui/events/event.h"
13 #include "ui/views/widget/widget.h"
15 namespace ash {
17 using StickyKeysOverlayTest = test::AshTestBase;
19 TEST_F(StickyKeysOverlayTest, OverlayVisibility) {
20 StickyKeysOverlay overlay;
21 EXPECT_FALSE(overlay.is_visible());
22 overlay.Show(true);
23 EXPECT_TRUE(overlay.is_visible());
26 TEST_F(StickyKeysOverlayTest, ModifierKeyState) {
27 StickyKeysOverlay overlay;
28 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED);
29 overlay.SetModifierKeyState(ui::EF_ALT_DOWN, STICKY_KEY_STATE_LOCKED);
30 overlay.SetModifierKeyState(ui::EF_CONTROL_DOWN, STICKY_KEY_STATE_ENABLED);
31 overlay.SetModifierKeyState(ui::EF_COMMAND_DOWN, STICKY_KEY_STATE_LOCKED);
33 EXPECT_EQ(STICKY_KEY_STATE_DISABLED,
34 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN));
35 EXPECT_EQ(STICKY_KEY_STATE_LOCKED,
36 overlay.GetModifierKeyState(ui::EF_ALT_DOWN));
37 EXPECT_EQ(STICKY_KEY_STATE_ENABLED,
38 overlay.GetModifierKeyState(ui::EF_CONTROL_DOWN));
39 EXPECT_EQ(STICKY_KEY_STATE_LOCKED,
40 overlay.GetModifierKeyState(ui::EF_COMMAND_DOWN));
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_t primary_display_id = display_ids.first;
51 int64_t secondary_display_id = display_ids.second;
52 display_manager->SetLayoutForCurrentDisplays(
53 DisplayLayout(DisplayLayout::LEFT, 0));
55 // The overlay should belong to the secondary root window.
56 StickyKeysOverlay overlay;
57 views::Widget* overlay_widget = overlay.GetWidgetForTesting();
58 WindowTreeHostManager* window_tree_host_manager =
59 Shell::GetInstance()->window_tree_host_manager();
60 EXPECT_EQ(
61 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id),
62 overlay_widget->GetNativeWindow()->GetRootWindow());
64 // Removing the second display should move the overlay to the primary root
65 // window.
66 UpdateDisplay("1280x1024");
67 EXPECT_EQ(
68 window_tree_host_manager->GetRootWindowForDisplayId(primary_display_id),
69 overlay_widget->GetNativeWindow()->GetRootWindow());
71 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_ENABLED);
72 EXPECT_EQ(STICKY_KEY_STATE_ENABLED,
73 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN));
74 overlay.SetModifierKeyState(ui::EF_SHIFT_DOWN, STICKY_KEY_STATE_DISABLED);
75 EXPECT_EQ(STICKY_KEY_STATE_DISABLED,
76 overlay.GetModifierKeyState(ui::EF_SHIFT_DOWN));
79 // Additional sticky key overlay tests that depend on chromeos::EventRewriter
80 // are now in chrome/browser/chromeos/events/event_rewriter_unittest.cc .
82 } // namespace ash