Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: ash/rotator/screen_rotation_animator_unittest.cc

Issue 2808723004: Renames WmShell to ShellPort (Closed)
Patch Set: feedback Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/rotator/screen_rotation_animator.h"
6
5 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
6 #include "ash/rotator/screen_rotation_animator.h"
7 #include "ash/rotator/screen_rotation_animator_observer.h" 8 #include "ash/rotator/screen_rotation_animator_observer.h"
8 #include "ash/rotator/test/screen_rotation_animator_test_api.h" 9 #include "ash/rotator/test/screen_rotation_animator_test_api.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_port.h"
10 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
11 #include "ash/wm_shell.h"
12 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "cc/output/copy_output_request.h" 17 #include "cc/output/copy_output_request.h"
17 #include "cc/output/copy_output_result.h" 18 #include "cc/output/copy_output_result.h"
18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
19 #include "ui/display/display.h" 20 #include "ui/display/display.h"
20 #include "ui/display/manager/display_manager.h" 21 #include "ui/display/manager/display_manager.h"
21 #include "ui/display/screen.h" 22 #include "ui/display/screen.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); 158 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
158 test_api()->DisableAnimationTimers(); 159 test_api()->DisableAnimationTimers();
159 } 160 }
160 161
161 void ScreenRotationAnimatorTest::WaitForCopyCallback() { 162 void ScreenRotationAnimatorTest::WaitForCopyCallback() {
162 run_loop_->Run(); 163 run_loop_->Run();
163 } 164 }
164 165
165 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { 166 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) {
166 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 167 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
167 if (WmShell::Get()->IsRunningInMash()) { 168 if (ShellPort::Get()->IsRunningInMash()) {
168 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 169 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
169 display_id()); 170 display_id());
170 return; 171 return;
171 } 172 }
172 173
173 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 174 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
174 AnimationObserver observer; 175 AnimationObserver observer;
175 animator()->AddScreenRotationAnimatorObserver(&observer); 176 animator()->AddScreenRotationAnimatorObserver(&observer);
176 EXPECT_FALSE(observer.notified()); 177 EXPECT_FALSE(observer.notified());
177 178
178 animator()->Rotate(display::Display::ROTATE_90, 179 animator()->Rotate(display::Display::ROTATE_90,
179 display::Display::RotationSource::ROTATION_SOURCE_USER); 180 display::Display::RotationSource::ROTATION_SOURCE_USER);
180 EXPECT_FALSE(observer.notified()); 181 EXPECT_FALSE(observer.notified());
181 182
182 test_api()->CompleteAnimations(); 183 test_api()->CompleteAnimations();
183 EXPECT_TRUE(observer.notified()); 184 EXPECT_TRUE(observer.notified());
184 EXPECT_FALSE(test_api()->HasActiveAnimations()); 185 EXPECT_FALSE(test_api()->HasActiveAnimations());
185 animator()->RemoveScreenRotationAnimatorObserver(&observer); 186 animator()->RemoveScreenRotationAnimatorObserver(&observer);
186 } 187 }
187 188
188 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserverOnce) { 189 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserverOnce) {
189 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 190 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
190 if (WmShell::Get()->IsRunningInMash()) { 191 if (ShellPort::Get()->IsRunningInMash()) {
191 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 192 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
192 display_id()); 193 display_id());
193 return; 194 return;
194 } 195 }
195 196
196 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 197 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
197 AnimationObserver observer; 198 AnimationObserver observer;
198 animator()->AddScreenRotationAnimatorObserver(&observer); 199 animator()->AddScreenRotationAnimatorObserver(&observer);
199 EXPECT_FALSE(observer.notified()); 200 EXPECT_FALSE(observer.notified());
200 201
201 animator()->Rotate(display::Display::ROTATE_90, 202 animator()->Rotate(display::Display::ROTATE_90,
202 display::Display::RotationSource::ROTATION_SOURCE_USER); 203 display::Display::RotationSource::ROTATION_SOURCE_USER);
203 EXPECT_FALSE(observer.notified()); 204 EXPECT_FALSE(observer.notified());
204 205
205 animator()->Rotate(display::Display::ROTATE_180, 206 animator()->Rotate(display::Display::ROTATE_180,
206 display::Display::RotationSource::ROTATION_SOURCE_USER); 207 display::Display::RotationSource::ROTATION_SOURCE_USER);
207 EXPECT_FALSE(observer.notified()); 208 EXPECT_FALSE(observer.notified());
208 209
209 test_api()->CompleteAnimations(); 210 test_api()->CompleteAnimations();
210 EXPECT_TRUE(observer.notified()); 211 EXPECT_TRUE(observer.notified());
211 EXPECT_FALSE(test_api()->HasActiveAnimations()); 212 EXPECT_FALSE(test_api()->HasActiveAnimations());
212 animator()->RemoveScreenRotationAnimatorObserver(&observer); 213 animator()->RemoveScreenRotationAnimatorObserver(&observer);
213 } 214 }
214 215
215 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) { 216 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) {
216 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 217 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
217 if (WmShell::Get()->IsRunningInMash()) { 218 if (ShellPort::Get()->IsRunningInMash()) {
218 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 219 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
219 display_id()); 220 display_id());
220 return; 221 return;
221 } 222 }
222 223
223 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 224 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
224 animator()->Rotate(display::Display::ROTATE_90, 225 animator()->Rotate(display::Display::ROTATE_90,
225 display::Display::RotationSource::ROTATION_SOURCE_USER); 226 display::Display::RotationSource::ROTATION_SOURCE_USER);
226 EXPECT_TRUE(test_api()->HasActiveAnimations()); 227 EXPECT_TRUE(test_api()->HasActiveAnimations());
227 228
228 test_api()->CompleteAnimations(); 229 test_api()->CompleteAnimations();
229 EXPECT_FALSE(test_api()->HasActiveAnimations()); 230 EXPECT_FALSE(test_api()->HasActiveAnimations());
230 } 231 }
231 232
232 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) { 233 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) {
233 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 234 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
234 if (WmShell::Get()->IsRunningInMash()) { 235 if (ShellPort::Get()->IsRunningInMash()) {
235 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 236 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
236 display_id()); 237 display_id());
237 return; 238 return;
238 } 239 }
239 240
240 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 241 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
241 animator()->Rotate(display::Display::ROTATE_0, 242 animator()->Rotate(display::Display::ROTATE_0,
242 display::Display::RotationSource::ROTATION_SOURCE_USER); 243 display::Display::RotationSource::ROTATION_SOURCE_USER);
243 EXPECT_FALSE(test_api()->HasActiveAnimations()); 244 EXPECT_FALSE(test_api()->HasActiveAnimations());
244 } 245 }
245 246
246 // Simulates the situation that if there is a new rotation request during 247 // Simulates the situation that if there is a new rotation request during
247 // animation, it should stop the animation immediately and add the new rotation 248 // animation, it should stop the animation immediately and add the new rotation
248 // request to the |last_pending_request_|. 249 // request to the |last_pending_request_|.
249 TEST_F(ScreenRotationAnimatorTest, RotatesDuringRotation) { 250 TEST_F(ScreenRotationAnimatorTest, RotatesDuringRotation) {
250 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 251 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
251 if (WmShell::Get()->IsRunningInMash()) { 252 if (ShellPort::Get()->IsRunningInMash()) {
252 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 253 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
253 display_id()); 254 display_id());
254 return; 255 return;
255 } 256 }
256 257
257 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 258 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
258 animator()->Rotate(display::Display::ROTATE_90, 259 animator()->Rotate(display::Display::ROTATE_90,
259 display::Display::RotationSource::ROTATION_SOURCE_USER); 260 display::Display::RotationSource::ROTATION_SOURCE_USER);
260 animator()->Rotate(display::Display::ROTATE_180, 261 animator()->Rotate(display::Display::ROTATE_180,
261 display::Display::RotationSource::ROTATION_SOURCE_USER); 262 display::Display::RotationSource::ROTATION_SOURCE_USER);
262 EXPECT_TRUE(test_api()->HasActiveAnimations()); 263 EXPECT_TRUE(test_api()->HasActiveAnimations());
263 264
264 test_api()->CompleteAnimations(); 265 test_api()->CompleteAnimations();
265 EXPECT_FALSE(test_api()->HasActiveAnimations()); 266 EXPECT_FALSE(test_api()->HasActiveAnimations());
266 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id())); 267 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id()));
267 } 268 }
268 269
269 // If there are multiple requests queued during animation, it should process the 270 // If there are multiple requests queued during animation, it should process the
270 // last request and finish the rotation animation. 271 // last request and finish the rotation animation.
271 TEST_F(ScreenRotationAnimatorTest, ShouldCompleteAnimations) { 272 TEST_F(ScreenRotationAnimatorTest, ShouldCompleteAnimations) {
272 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 273 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
273 if (WmShell::Get()->IsRunningInMash()) { 274 if (ShellPort::Get()->IsRunningInMash()) {
274 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 275 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
275 display_id()); 276 display_id());
276 return; 277 return;
277 } 278 }
278 279
279 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 280 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
280 animator()->Rotate(display::Display::ROTATE_90, 281 animator()->Rotate(display::Display::ROTATE_90,
281 display::Display::RotationSource::ROTATION_SOURCE_USER); 282 display::Display::RotationSource::ROTATION_SOURCE_USER);
282 EXPECT_TRUE(test_api()->HasActiveAnimations()); 283 EXPECT_TRUE(test_api()->HasActiveAnimations());
283 284
284 animator()->Rotate(display::Display::ROTATE_180, 285 animator()->Rotate(display::Display::ROTATE_180,
285 display::Display::RotationSource::ROTATION_SOURCE_USER); 286 display::Display::RotationSource::ROTATION_SOURCE_USER);
286 EXPECT_TRUE(test_api()->HasActiveAnimations()); 287 EXPECT_TRUE(test_api()->HasActiveAnimations());
287 288
288 animator()->Rotate(display::Display::ROTATE_270, 289 animator()->Rotate(display::Display::ROTATE_270,
289 display::Display::RotationSource::ROTATION_SOURCE_USER); 290 display::Display::RotationSource::ROTATION_SOURCE_USER);
290 EXPECT_TRUE(test_api()->HasActiveAnimations()); 291 EXPECT_TRUE(test_api()->HasActiveAnimations());
291 292
292 test_api()->CompleteAnimations(); 293 test_api()->CompleteAnimations();
293 EXPECT_FALSE(test_api()->HasActiveAnimations()); 294 EXPECT_FALSE(test_api()->HasActiveAnimations());
294 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); 295 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id()));
295 } 296 }
296 297
297 // Test enable smooth screen rotation code path. 298 // Test enable smooth screen rotation code path.
298 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) { 299 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
299 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 300 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
300 if (WmShell::Get()->IsRunningInMash()) { 301 if (ShellPort::Get()->IsRunningInMash()) {
301 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 302 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
302 display_id()); 303 display_id());
303 return; 304 return;
304 } 305 }
305 306
306 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 307 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
307 base::CommandLine::ForCurrentProcess()->AppendSwitch( 308 base::CommandLine::ForCurrentProcess()->AppendSwitch(
308 switches::kAshEnableSmoothScreenRotation); 309 switches::kAshEnableSmoothScreenRotation);
309 animator()->Rotate(display::Display::ROTATE_90, 310 animator()->Rotate(display::Display::ROTATE_90,
310 display::Display::RotationSource::ROTATION_SOURCE_USER); 311 display::Display::RotationSource::ROTATION_SOURCE_USER);
311 WaitForCopyCallback(); 312 WaitForCopyCallback();
312 EXPECT_TRUE(test_api()->HasActiveAnimations()); 313 EXPECT_TRUE(test_api()->HasActiveAnimations());
313 314
314 test_api()->CompleteAnimations(); 315 test_api()->CompleteAnimations();
315 EXPECT_FALSE(test_api()->HasActiveAnimations()); 316 EXPECT_FALSE(test_api()->HasActiveAnimations());
316 } 317 }
317 318
318 // If the external display is removed, it should not crash. 319 // If the external display is removed, it should not crash.
319 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) { 320 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
320 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 321 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
321 if (WmShell::Get()->IsRunningInMash()) { 322 if (ShellPort::Get()->IsRunningInMash()) {
322 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 323 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
323 display_id()); 324 display_id());
324 return; 325 return;
325 } 326 }
326 327
327 UpdateDisplay("640x480,800x600"); 328 UpdateDisplay("640x480,800x600");
328 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 329 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
329 330
330 const unsigned int primary_display_id = 331 const unsigned int primary_display_id =
331 display_manager()->GetDisplayAt(0).id(); 332 display_manager()->GetDisplayAt(0).id();
332 SetScreenRotationAnimator( 333 SetScreenRotationAnimator(
333 display_manager()->GetDisplayAt(1).id(), 334 display_manager()->GetDisplayAt(1).id(),
334 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, 335 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
335 base::Unretained(this), "640x480")); 336 base::Unretained(this), "640x480"));
336 base::CommandLine::ForCurrentProcess()->AppendSwitch( 337 base::CommandLine::ForCurrentProcess()->AppendSwitch(
337 switches::kAshEnableSmoothScreenRotation); 338 switches::kAshEnableSmoothScreenRotation);
338 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 339 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
339 display::Display::ROTATE_0); 340 display::Display::ROTATE_0);
340 animator()->Rotate(display::Display::ROTATE_90, 341 animator()->Rotate(display::Display::ROTATE_90,
341 display::Display::RotationSource::ROTATION_SOURCE_USER); 342 display::Display::RotationSource::ROTATION_SOURCE_USER);
342 WaitForCopyCallback(); 343 WaitForCopyCallback();
343 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 344 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
344 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); 345 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
345 } 346 }
346 347
347 } // namespace ash 348 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698