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/system/overview/overview_button_tray.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/system/status_area_widget.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/status_area_widget_test_helper.h"
16 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
17 #include "ash/wm/overview/window_selector_controller.h"
18 #include "base/time/time.h"
19 #include "ui/events/event.h"
20 #include "ui/events/event_constants.h"
21 #include "ui/events/gestures/gesture_types.h"
22 #include "ui/views/controls/image_view.h"
28 OverviewButtonTray
* GetTray() {
29 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->
30 overview_button_tray();
33 OverviewButtonTray
* GetSecondaryTray() {
34 return StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()->
35 overview_button_tray();
40 class OverviewButtonTrayTest
: public test::AshTestBase
{
42 OverviewButtonTrayTest() {}
43 ~OverviewButtonTrayTest() override
{}
46 views::ImageView
* GetImageView(OverviewButtonTray
* tray
) {
51 DISALLOW_COPY_AND_ASSIGN(OverviewButtonTrayTest
);
54 // Ensures that creation doesn't cause any crashes and adds the image icon.
55 TEST_F(OverviewButtonTrayTest
, BasicConstruction
) {
56 EXPECT_TRUE(GetImageView(GetTray()) != NULL
);
59 // Test that maximize mode toggle changes visibility.
60 // OverviewButtonTray should only be visible when MaximizeMode is enabled.
61 // By default the system should not have MaximizeMode enabled.
62 TEST_F(OverviewButtonTrayTest
, MaximizeModeObserverOnMaximizeModeToggled
) {
63 ASSERT_FALSE(GetTray()->visible());
64 Shell::GetInstance()->maximize_mode_controller()->
65 EnableMaximizeModeWindowManager(true);
66 EXPECT_TRUE(GetTray()->visible());
68 Shell::GetInstance()->maximize_mode_controller()->
69 EnableMaximizeModeWindowManager(false);
70 EXPECT_FALSE(GetTray()->visible());
73 // Tests that activating this control brings up window selection mode.
74 TEST_F(OverviewButtonTrayTest
, PerformAction
) {
75 ASSERT_FALSE(Shell::GetInstance()->window_selector_controller()->
78 // Overview Mode only works when there is a window
79 scoped_ptr
<aura::Window
> window(
80 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
82 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP
));
83 GetTray()->PerformAction(tap
);
84 EXPECT_TRUE(Shell::GetInstance()->window_selector_controller()->
88 // Tests that a second OverviewButtonTray has been created, and only shows
89 // when MaximizeMode has been enabled, when we are using multiple displays.
90 // By default the DisplayManger is in extended mode.
91 TEST_F(OverviewButtonTrayTest
, DisplaysOnBothDisplays
) {
92 if (!SupportsMultipleDisplays())
95 UpdateDisplay("400x400,200x200");
96 EXPECT_FALSE(GetTray()->visible());
97 EXPECT_FALSE(GetSecondaryTray()->visible());
98 Shell::GetInstance()->maximize_mode_controller()->
99 EnableMaximizeModeWindowManager(true);
100 EXPECT_TRUE(GetTray()->visible());
101 EXPECT_TRUE(GetSecondaryTray()->visible());
102 Shell::GetInstance()->maximize_mode_controller()->
103 EnableMaximizeModeWindowManager(false);
106 // Tests if Maximize Mode is enabled before a secondary display is attached
107 // that the second OverviewButtonTray should be created in a visible state.
108 TEST_F(OverviewButtonTrayTest
, SecondaryTrayCreatedVisible
) {
109 if (!SupportsMultipleDisplays())
112 Shell::GetInstance()->maximize_mode_controller()->
113 EnableMaximizeModeWindowManager(true);
114 UpdateDisplay("400x400,200x200");
115 EXPECT_TRUE(GetSecondaryTray()->visible());
116 Shell::GetInstance()->maximize_mode_controller()->
117 EnableMaximizeModeWindowManager(false);
120 // Tests that the tray loses visibility when a user logs out, and that it
121 // regains visibility when a user logs back in.
122 TEST_F(OverviewButtonTrayTest
, VisibilityChangesForLoginStatus
) {
123 Shell::GetInstance()->maximize_mode_controller()->
124 EnableMaximizeModeWindowManager(true);
125 SetUserLoggedIn(false);
126 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_NONE
);
127 EXPECT_FALSE(GetTray()->visible());
128 SetUserLoggedIn(true);
129 SetSessionStarted(true);
130 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER
);
131 EXPECT_TRUE(GetTray()->visible());
132 Shell::GetInstance()->maximize_mode_controller()->
133 EnableMaximizeModeWindowManager(false);
136 // Tests that the tray only renders as active while selection is ongoing. Any
137 // dismissal of overview mode clears the active state.
138 TEST_F(OverviewButtonTrayTest
, ActiveStateOnlyDuringOverviewMode
) {
140 Shell::GetInstance()->window_selector_controller()->IsSelecting());
141 ASSERT_FALSE(GetTray()->draw_background_as_active());
143 // Overview Mode only works when there is a window
144 scoped_ptr
<aura::Window
> window(
145 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
146 ui::GestureEvent
tap(
147 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP
));
148 GetTray()->PerformAction(tap
);
150 Shell::GetInstance()->window_selector_controller()->IsSelecting());
151 EXPECT_TRUE(GetTray()->draw_background_as_active());
153 Shell::GetInstance()->window_selector_controller()->OnSelectionEnded();
155 Shell::GetInstance()->window_selector_controller()->IsSelecting());
156 EXPECT_FALSE(GetTray()->draw_background_as_active());