Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ash / system / chromeos / rotation / tray_rotation_lock_unittest.cc
blob6938469cf0946e9c6bbcaf1d8328473b0aa5de06
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/chromeos/rotation/tray_rotation_lock.h"
7 #include "ash/ash_switches.h"
8 #include "ash/content/display/screen_orientation_controller_chromeos.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/root_window_controller.h"
11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "ash/system/status_area_widget.h"
14 #include "ash/system/tray/system_tray.h"
15 #include "ash/system/tray/system_tray_delegate.h"
16 #include "ash/test/ash_test_base.h"
17 #include "ash/test/status_area_widget_test_helper.h"
18 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
19 #include "base/command_line.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/time/time.h"
22 #include "ui/events/event.h"
23 #include "ui/events/event_constants.h"
24 #include "ui/views/view.h"
26 namespace ash {
28 class TrayRotationLockTest : public test::AshTestBase {
29 public:
30 TrayRotationLockTest() {}
31 ~TrayRotationLockTest() override {}
33 TrayRotationLock* tray() {
34 return tray_.get();
37 views::View* tray_view() {
38 return tray_view_.get();
41 views::View* default_view() {
42 return default_view_.get();
45 // Creates the tray view associated to |tray_rotation_lock|.
46 views::View* CreateTrayView(TrayRotationLock* tray_rotation_lock);
48 // Sets up a TrayRotationLock, its tray view, and its default view, for the
49 // given SystemTray and its display. On a primary display all will be
50 // created. On a secondary display both the tray view and default view will
51 // be null.
52 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget);
54 // Resets |tray_| |tray_view_| and |default_view_| so that all components of
55 // TrayRotationLock have been cleared. Tests may then call
56 // SetUpForStatusAreaWidget in order to initial the components.
57 void TearDownViews();
59 // test::AshTestBase:
60 void SetUp() override;
61 void TearDown() override;
63 private:
64 scoped_ptr<TrayRotationLock> tray_;
65 scoped_ptr<views::View> tray_view_;
66 scoped_ptr<views::View> default_view_;
68 DISALLOW_COPY_AND_ASSIGN(TrayRotationLockTest);
71 views::View* TrayRotationLockTest::CreateTrayView(
72 TrayRotationLock* tray_rotation_lock) {
73 return tray_rotation_lock->CreateTrayView(
74 StatusAreaWidgetTestHelper::GetUserLoginStatus());
77 void TrayRotationLockTest::SetUpForStatusAreaWidget(
78 StatusAreaWidget* status_area_widget) {
79 tray_.reset(new TrayRotationLock(status_area_widget->system_tray()));
80 tray_view_.reset(tray_->CreateTrayView(
81 StatusAreaWidgetTestHelper::GetUserLoginStatus()));
82 default_view_.reset(tray_->CreateDefaultView(
83 StatusAreaWidgetTestHelper::GetUserLoginStatus()));
86 void TrayRotationLockTest::TearDownViews() {
87 tray_view_.reset();
88 default_view_.reset();
89 tray_.reset();
92 void TrayRotationLockTest::SetUp() {
93 // The Display used for testing is not an internal display. This flag
94 // allows for DisplayManager to treat it as one. TrayRotationLock is only
95 // visible on internal primary displays.
96 base::CommandLine::ForCurrentProcess()->AppendSwitch(
97 switches::kAshUseFirstDisplayAsInternal);
98 test::AshTestBase::SetUp();
99 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
102 void TrayRotationLockTest::TearDown() {
103 TearDownViews();
104 test::AshTestBase::TearDown();
107 // Tests that when the tray view is initially created, that it is created
108 // not visible.
109 TEST_F(TrayRotationLockTest, CreateTrayView) {
110 EXPECT_FALSE(tray_view()->visible());
113 // Tests that when the tray view is created, while MaximizeMode is active, that
114 // it is not visible.
115 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) {
116 TearDownViews();
117 Shell::GetInstance()->maximize_mode_controller()->
118 EnableMaximizeModeWindowManager(true);
119 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
120 EXPECT_FALSE(tray_view()->visible());
121 Shell::GetInstance()->maximize_mode_controller()->
122 EnableMaximizeModeWindowManager(false);
125 // Tests that when the tray view is created, while MaximizeMode is active, and
126 // rotation is locked, that it is visible.
127 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) {
128 TearDownViews();
129 Shell::GetInstance()->maximize_mode_controller()->
130 EnableMaximizeModeWindowManager(true);
131 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked(
132 true);
133 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
134 EXPECT_TRUE(tray_view()->visible());
135 Shell::GetInstance()->maximize_mode_controller()->
136 EnableMaximizeModeWindowManager(false);
137 EXPECT_FALSE(tray_view()->visible());
140 // Tests that the enabling of MaximizeMode affects a previously created tray
141 // view, changing the visibility.
142 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) {
143 ASSERT_FALSE(tray_view()->visible());
144 Shell::GetInstance()->maximize_mode_controller()->
145 EnableMaximizeModeWindowManager(true);
146 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked(
147 true);
148 EXPECT_TRUE(tray_view()->visible());
149 Shell::GetInstance()->maximize_mode_controller()->
150 EnableMaximizeModeWindowManager(false);
151 EXPECT_FALSE(tray_view()->visible());
154 // Tests that the when the tray view is created for a secondary display, that
155 // it is not visible, and that MaximizeMode does not affect visibility.
156 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) {
157 if (!SupportsMultipleDisplays())
158 return;
159 UpdateDisplay("400x400,200x200");
161 SetUpForStatusAreaWidget(
162 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget());
163 EXPECT_FALSE(tray_view()->visible());
164 Shell::GetInstance()->maximize_mode_controller()->
165 EnableMaximizeModeWindowManager(true);
166 EXPECT_FALSE(tray_view()->visible());
167 Shell::GetInstance()->maximize_mode_controller()->
168 EnableMaximizeModeWindowManager(false);
169 EXPECT_FALSE(tray_view()->visible());
172 // Tests that when the default view is initially created, that it is created
173 // not visible.
174 TEST_F(TrayRotationLockTest, CreateDefaultView) {
175 EXPECT_FALSE(default_view()->visible());
178 // Tests that when the default view is created, while MaximizeMode is active,
179 // that it is visible.
180 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) {
181 TearDownViews();
182 Shell::GetInstance()->maximize_mode_controller()->
183 EnableMaximizeModeWindowManager(true);
184 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget());
185 EXPECT_TRUE(default_view()->visible());
186 Shell::GetInstance()->maximize_mode_controller()->
187 EnableMaximizeModeWindowManager(false);
190 // Tests that the enabling of MaximizeMode affects a previously created default
191 // view, changing the visibility.
192 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) {
193 Shell::GetInstance()->maximize_mode_controller()->
194 EnableMaximizeModeWindowManager(true);
195 EXPECT_TRUE(default_view()->visible());
196 Shell::GetInstance()->maximize_mode_controller()->
197 EnableMaximizeModeWindowManager(false);
198 EXPECT_FALSE(default_view()->visible());
201 // Tests that no default view is created when the target is a secondary
202 // display.
203 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) {
204 if (!SupportsMultipleDisplays())
205 return;
206 UpdateDisplay("400x400,200x200");
208 TearDownViews();
209 SetUpForStatusAreaWidget(
210 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget());
211 EXPECT_EQ(NULL, default_view());
214 // Tests that activating the default view causes the display to have its
215 // rotation locked, and that the tray view becomes visible.
216 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) {
217 MaximizeModeController* maximize_mode_controller = Shell::GetInstance()->
218 maximize_mode_controller();
219 ScreenOrientationController* screen_orientation_controller =
220 Shell::GetInstance()->screen_orientation_controller();
221 ASSERT_FALSE(screen_orientation_controller->rotation_locked());
222 maximize_mode_controller->EnableMaximizeModeWindowManager(true);
223 ASSERT_FALSE(tray_view()->visible());
225 ui::GestureEvent tap(
226 0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP));
227 default_view()->OnGestureEvent(&tap);
228 EXPECT_TRUE(screen_orientation_controller->rotation_locked());
229 EXPECT_TRUE(tray_view()->visible());
231 maximize_mode_controller->EnableMaximizeModeWindowManager(false);
234 // Tests that when the tray is created without the internal display being known,
235 // that it will still display correctly once the internal display is known.
236 TEST_F(TrayRotationLockTest, InternalDisplayNotAvailableAtCreation) {
237 int64 internal_display_id = gfx::Display::InternalDisplayId();
238 TearDownViews();
239 gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
241 scoped_ptr<TrayRotationLock> tray(new TrayRotationLock(
242 StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray()));
244 gfx::Display::SetInternalDisplayId(internal_display_id);
245 scoped_ptr<views::View> tray_view(CreateTrayView(tray.get()));
246 scoped_ptr<views::View> default_view(tray->CreateDefaultView(
247 StatusAreaWidgetTestHelper::GetUserLoginStatus()));
248 EXPECT_TRUE(default_view);
249 Shell::GetInstance()
250 ->maximize_mode_controller()
251 ->EnableMaximizeModeWindowManager(true);
252 EXPECT_TRUE(default_view->visible());
255 } // namespace ash