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 virtual ~OverviewButtonTrayTest() {}
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)));
81 ui::GestureEvent
tap(ui::ET_GESTURE_TAP
, 0, 0, 0, base::TimeDelta(),
82 ui::GestureEventDetails(ui::ET_GESTURE_TAP
, 0.0f
, 0.0f
), 0);
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);