Make multiple-connections.html less aggressive.
[chromium-blink-merge.git] / ash / sticky_keys / sticky_keys_overlay_unittest.cc
blob2566a8b0433c2666b59377f7aac2c0bbfa8fc873
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_controller.h"
8 #include "ash/display/display_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 DisplayController* display_controller =
59 Shell::GetInstance()->display_controller();
60 EXPECT_EQ(display_controller->GetRootWindowForDisplayId(secondary_display_id),
61 overlay_widget->GetNativeWindow()->GetRootWindow());
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());
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));
77 // Additional sticky key overlay tests that depend on chromeos::EventRewriter
78 // are now in chrome/browser/chromeos/events/event_rewriter_unittest.cc .
80 } // namespace ash