OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" | 5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
10 #include "ash/common/system/tray/system_tray_delegate.h" | 10 #include "ash/common/system/tray/system_tray_delegate.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/events/event_constants.h" | 23 #include "ui/events/event_constants.h" |
24 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 | 27 |
28 class TrayRotationLockTest : public test::AshTestBase { | 28 class TrayRotationLockTest : public test::AshTestBase { |
29 public: | 29 public: |
30 TrayRotationLockTest() {} | 30 TrayRotationLockTest() {} |
31 ~TrayRotationLockTest() override {} | 31 ~TrayRotationLockTest() override {} |
32 | 32 |
33 TrayRotationLock* tray() { | 33 TrayRotationLock* tray() { return tray_.get(); } |
34 return tray_.get(); | |
35 } | |
36 | 34 |
37 views::View* tray_view() { | 35 views::View* tray_view() { return tray_view_.get(); } |
38 return tray_view_.get(); | |
39 } | |
40 | 36 |
41 views::View* default_view() { | 37 views::View* default_view() { return default_view_.get(); } |
42 return default_view_.get(); | |
43 } | |
44 | 38 |
45 // Creates the tray view associated to |tray_rotation_lock|. | 39 // Creates the tray view associated to |tray_rotation_lock|. |
46 views::View* CreateTrayView(TrayRotationLock* tray_rotation_lock); | 40 views::View* CreateTrayView(TrayRotationLock* tray_rotation_lock); |
47 | 41 |
48 // Destroys only the |tray_view_|. Tests may call this to simulate destruction | 42 // Destroys only the |tray_view_|. Tests may call this to simulate destruction |
49 // order during the deletion of the StatusAreaWidget. | 43 // order during the deletion of the StatusAreaWidget. |
50 void DestroyTrayView(); | 44 void DestroyTrayView(); |
51 | 45 |
52 // Sets up a TrayRotationLock, its tray view, and its default view, for the | 46 // Sets up a TrayRotationLock, its tray view, and its default view, for the |
53 // given SystemTray and its display. On a primary display all will be | 47 // given SystemTray and its display. On a primary display all will be |
(...skipping 25 matching lines...) Expand all Loading... |
79 } | 73 } |
80 | 74 |
81 void TrayRotationLockTest::DestroyTrayView() { | 75 void TrayRotationLockTest::DestroyTrayView() { |
82 tray_view_.reset(); | 76 tray_view_.reset(); |
83 tray_->DestroyTrayView(); | 77 tray_->DestroyTrayView(); |
84 } | 78 } |
85 | 79 |
86 void TrayRotationLockTest::SetUpForStatusAreaWidget( | 80 void TrayRotationLockTest::SetUpForStatusAreaWidget( |
87 StatusAreaWidget* status_area_widget) { | 81 StatusAreaWidget* status_area_widget) { |
88 tray_.reset(new TrayRotationLock(status_area_widget->system_tray())); | 82 tray_.reset(new TrayRotationLock(status_area_widget->system_tray())); |
89 tray_view_.reset(tray_->CreateTrayView( | 83 tray_view_.reset( |
90 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | 84 tray_->CreateTrayView(StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
91 default_view_.reset(tray_->CreateDefaultView( | 85 default_view_.reset(tray_->CreateDefaultView( |
92 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | 86 StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
93 } | 87 } |
94 | 88 |
95 void TrayRotationLockTest::TearDownViews() { | 89 void TrayRotationLockTest::TearDownViews() { |
96 tray_view_.reset(); | 90 tray_view_.reset(); |
97 default_view_.reset(); | 91 default_view_.reset(); |
98 tray_.reset(); | 92 tray_.reset(); |
99 } | 93 } |
100 | 94 |
101 void TrayRotationLockTest::SetUp() { | 95 void TrayRotationLockTest::SetUp() { |
102 // The Display used for testing is not an internal display. This flag | 96 // The Display used for testing is not an internal display. This flag |
103 // allows for DisplayManager to treat it as one. TrayRotationLock is only | 97 // allows for DisplayManager to treat it as one. TrayRotationLock is only |
104 // visible on internal primary displays. | 98 // visible on internal primary displays. |
105 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 99 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
106 switches::kAshUseFirstDisplayAsInternal); | 100 switches::kAshUseFirstDisplayAsInternal); |
107 test::AshTestBase::SetUp(); | 101 test::AshTestBase::SetUp(); |
108 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 102 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
109 } | 103 } |
110 | 104 |
111 void TrayRotationLockTest::TearDown() { | 105 void TrayRotationLockTest::TearDown() { |
112 TearDownViews(); | 106 TearDownViews(); |
113 test::AshTestBase::TearDown(); | 107 test::AshTestBase::TearDown(); |
114 } | 108 } |
115 | 109 |
116 // Tests that when the tray view is initially created, that it is created | 110 // Tests that when the tray view is initially created, that it is created |
117 // not visible. | 111 // not visible. |
118 TEST_F(TrayRotationLockTest, CreateTrayView) { | 112 TEST_F(TrayRotationLockTest, CreateTrayView) { |
119 EXPECT_FALSE(tray_view()->visible()); | 113 EXPECT_FALSE(tray_view()->visible()); |
120 } | 114 } |
121 | 115 |
122 // Tests that when the tray view is created, while MaximizeMode is active, that | 116 // Tests that when the tray view is created, while MaximizeMode is active, that |
123 // it is not visible. | 117 // it is not visible. |
124 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) { | 118 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) { |
125 TearDownViews(); | 119 TearDownViews(); |
126 Shell::GetInstance()->maximize_mode_controller()-> | 120 Shell::GetInstance() |
127 EnableMaximizeModeWindowManager(true); | 121 ->maximize_mode_controller() |
| 122 ->EnableMaximizeModeWindowManager(true); |
128 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 123 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
129 EXPECT_FALSE(tray_view()->visible()); | 124 EXPECT_FALSE(tray_view()->visible()); |
130 Shell::GetInstance()->maximize_mode_controller()-> | 125 Shell::GetInstance() |
131 EnableMaximizeModeWindowManager(false); | 126 ->maximize_mode_controller() |
| 127 ->EnableMaximizeModeWindowManager(false); |
132 } | 128 } |
133 | 129 |
134 // Tests that when the tray view is created, while MaximizeMode is active, and | 130 // Tests that when the tray view is created, while MaximizeMode is active, and |
135 // rotation is locked, that it is visible. | 131 // rotation is locked, that it is visible. |
136 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) { | 132 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) { |
137 TearDownViews(); | 133 TearDownViews(); |
138 Shell::GetInstance()->maximize_mode_controller()-> | 134 Shell::GetInstance() |
139 EnableMaximizeModeWindowManager(true); | 135 ->maximize_mode_controller() |
| 136 ->EnableMaximizeModeWindowManager(true); |
140 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 137 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
141 true); | 138 true); |
142 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 139 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
143 EXPECT_TRUE(tray_view()->visible()); | 140 EXPECT_TRUE(tray_view()->visible()); |
144 Shell::GetInstance()->maximize_mode_controller()-> | 141 Shell::GetInstance() |
145 EnableMaximizeModeWindowManager(false); | 142 ->maximize_mode_controller() |
| 143 ->EnableMaximizeModeWindowManager(false); |
146 EXPECT_FALSE(tray_view()->visible()); | 144 EXPECT_FALSE(tray_view()->visible()); |
147 } | 145 } |
148 | 146 |
149 // Tests that the enabling of MaximizeMode affects a previously created tray | 147 // Tests that the enabling of MaximizeMode affects a previously created tray |
150 // view, changing the visibility. | 148 // view, changing the visibility. |
151 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) { | 149 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) { |
152 ASSERT_FALSE(tray_view()->visible()); | 150 ASSERT_FALSE(tray_view()->visible()); |
153 Shell::GetInstance()->maximize_mode_controller()-> | 151 Shell::GetInstance() |
154 EnableMaximizeModeWindowManager(true); | 152 ->maximize_mode_controller() |
| 153 ->EnableMaximizeModeWindowManager(true); |
155 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 154 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
156 true); | 155 true); |
157 EXPECT_TRUE(tray_view()->visible()); | 156 EXPECT_TRUE(tray_view()->visible()); |
158 Shell::GetInstance()->maximize_mode_controller()-> | 157 Shell::GetInstance() |
159 EnableMaximizeModeWindowManager(false); | 158 ->maximize_mode_controller() |
| 159 ->EnableMaximizeModeWindowManager(false); |
160 EXPECT_FALSE(tray_view()->visible()); | 160 EXPECT_FALSE(tray_view()->visible()); |
161 } | 161 } |
162 | 162 |
163 // Tests that the when the tray view is created for a secondary display, that | 163 // Tests that the when the tray view is created for a secondary display, that |
164 // it is not visible, and that MaximizeMode does not affect visibility. | 164 // it is not visible, and that MaximizeMode does not affect visibility. |
165 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { | 165 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { |
166 if (!SupportsMultipleDisplays()) | 166 if (!SupportsMultipleDisplays()) |
167 return; | 167 return; |
168 UpdateDisplay("400x400,200x200"); | 168 UpdateDisplay("400x400,200x200"); |
169 | 169 |
170 SetUpForStatusAreaWidget( | 170 SetUpForStatusAreaWidget( |
171 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | 171 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); |
172 EXPECT_FALSE(tray_view()->visible()); | 172 EXPECT_FALSE(tray_view()->visible()); |
173 Shell::GetInstance()->maximize_mode_controller()-> | 173 Shell::GetInstance() |
174 EnableMaximizeModeWindowManager(true); | 174 ->maximize_mode_controller() |
| 175 ->EnableMaximizeModeWindowManager(true); |
175 EXPECT_FALSE(tray_view()->visible()); | 176 EXPECT_FALSE(tray_view()->visible()); |
176 Shell::GetInstance()->maximize_mode_controller()-> | 177 Shell::GetInstance() |
177 EnableMaximizeModeWindowManager(false); | 178 ->maximize_mode_controller() |
| 179 ->EnableMaximizeModeWindowManager(false); |
178 EXPECT_FALSE(tray_view()->visible()); | 180 EXPECT_FALSE(tray_view()->visible()); |
179 } | 181 } |
180 | 182 |
181 // Tests that when the default view is initially created, that it is created | 183 // Tests that when the default view is initially created, that it is created |
182 // not visible. | 184 // not visible. |
183 TEST_F(TrayRotationLockTest, CreateDefaultView) { | 185 TEST_F(TrayRotationLockTest, CreateDefaultView) { |
184 EXPECT_FALSE(default_view()->visible()); | 186 EXPECT_FALSE(default_view()->visible()); |
185 } | 187 } |
186 | 188 |
187 // Tests that when the default view is created, while MaximizeMode is active, | 189 // Tests that when the default view is created, while MaximizeMode is active, |
188 // that it is visible. | 190 // that it is visible. |
189 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) { | 191 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) { |
190 TearDownViews(); | 192 TearDownViews(); |
191 Shell::GetInstance()->maximize_mode_controller()-> | 193 Shell::GetInstance() |
192 EnableMaximizeModeWindowManager(true); | 194 ->maximize_mode_controller() |
| 195 ->EnableMaximizeModeWindowManager(true); |
193 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 196 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
194 EXPECT_TRUE(default_view()->visible()); | 197 EXPECT_TRUE(default_view()->visible()); |
195 Shell::GetInstance()->maximize_mode_controller()-> | 198 Shell::GetInstance() |
196 EnableMaximizeModeWindowManager(false); | 199 ->maximize_mode_controller() |
| 200 ->EnableMaximizeModeWindowManager(false); |
197 } | 201 } |
198 | 202 |
199 // Tests that the enabling of MaximizeMode affects a previously created default | 203 // Tests that the enabling of MaximizeMode affects a previously created default |
200 // view, changing the visibility. | 204 // view, changing the visibility. |
201 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) { | 205 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) { |
202 Shell::GetInstance()->maximize_mode_controller()-> | 206 Shell::GetInstance() |
203 EnableMaximizeModeWindowManager(true); | 207 ->maximize_mode_controller() |
| 208 ->EnableMaximizeModeWindowManager(true); |
204 EXPECT_TRUE(default_view()->visible()); | 209 EXPECT_TRUE(default_view()->visible()); |
205 Shell::GetInstance()->maximize_mode_controller()-> | 210 Shell::GetInstance() |
206 EnableMaximizeModeWindowManager(false); | 211 ->maximize_mode_controller() |
| 212 ->EnableMaximizeModeWindowManager(false); |
207 EXPECT_FALSE(default_view()->visible()); | 213 EXPECT_FALSE(default_view()->visible()); |
208 } | 214 } |
209 | 215 |
210 // Tests that no default view is created when the target is a secondary | 216 // Tests that no default view is created when the target is a secondary |
211 // display. | 217 // display. |
212 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { | 218 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { |
213 if (!SupportsMultipleDisplays()) | 219 if (!SupportsMultipleDisplays()) |
214 return; | 220 return; |
215 UpdateDisplay("400x400,200x200"); | 221 UpdateDisplay("400x400,200x200"); |
216 | 222 |
217 TearDownViews(); | 223 TearDownViews(); |
218 SetUpForStatusAreaWidget( | 224 SetUpForStatusAreaWidget( |
219 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | 225 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); |
220 EXPECT_EQ(NULL, default_view()); | 226 EXPECT_EQ(NULL, default_view()); |
221 } | 227 } |
222 | 228 |
223 // Tests that activating the default view causes the display to have its | 229 // Tests that activating the default view causes the display to have its |
224 // rotation locked, and that the tray view becomes visible. | 230 // rotation locked, and that the tray view becomes visible. |
225 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { | 231 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { |
226 MaximizeModeController* maximize_mode_controller = Shell::GetInstance()-> | 232 MaximizeModeController* maximize_mode_controller = |
227 maximize_mode_controller(); | 233 Shell::GetInstance()->maximize_mode_controller(); |
228 ScreenOrientationController* screen_orientation_controller = | 234 ScreenOrientationController* screen_orientation_controller = |
229 Shell::GetInstance()->screen_orientation_controller(); | 235 Shell::GetInstance()->screen_orientation_controller(); |
230 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); | 236 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); |
231 maximize_mode_controller->EnableMaximizeModeWindowManager(true); | 237 maximize_mode_controller->EnableMaximizeModeWindowManager(true); |
232 ASSERT_FALSE(tray_view()->visible()); | 238 ASSERT_FALSE(tray_view()->visible()); |
233 | 239 |
234 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 240 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
235 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 241 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
236 default_view()->OnGestureEvent(&tap); | 242 default_view()->OnGestureEvent(&tap); |
237 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); | 243 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 ->EnableMaximizeModeWindowManager(true); | 275 ->EnableMaximizeModeWindowManager(true); |
270 DestroyTrayView(); | 276 DestroyTrayView(); |
271 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 277 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
272 true); | 278 true); |
273 Shell::GetInstance() | 279 Shell::GetInstance() |
274 ->maximize_mode_controller() | 280 ->maximize_mode_controller() |
275 ->EnableMaximizeModeWindowManager(false); | 281 ->EnableMaximizeModeWindowManager(false); |
276 } | 282 } |
277 | 283 |
278 } // namespace ash | 284 } // namespace ash |
OLD | NEW |