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

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

Issue 2906873003: chromeos: turn on simplified display management for mash (Closed)
Patch Set: bug refs Created 3 years, 6 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
« no previous file with comments | « ash/mus/window_manager_application.cc ('k') | ash/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 5 #include "ash/rotator/screen_rotation_animator.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/display/window_tree_host_manager.h" 8 #include "ash/display/window_tree_host_manager.h"
9 #include "ash/public/cpp/config.h" 9 #include "ash/public/cpp/config.h"
10 #include "ash/rotator/screen_rotation_animator_observer.h" 10 #include "ash/rotator/screen_rotation_animator_observer.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; 166 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
167 167
168 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorSlowAnimationTest); 168 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorSlowAnimationTest);
169 }; 169 };
170 170
171 void ScreenRotationAnimatorSlowAnimationTest::SetUp() { 171 void ScreenRotationAnimatorSlowAnimationTest::SetUp() {
172 AshTestBase::SetUp(); 172 AshTestBase::SetUp();
173 173
174 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); 174 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
175 if (Shell::GetAshConfig() == Config::MASH) {
176 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
177 display_id());
178 return;
179 }
180
181 animator_ = 175 animator_ =
182 base::MakeUnique<ScreenRotationAnimator>(GetRootWindow(display_.id())); 176 base::MakeUnique<ScreenRotationAnimator>(GetRootWindow(display_.id()));
183 test_api_ = 177 test_api_ =
184 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); 178 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
185 test_api()->DisableAnimationTimers(); 179 test_api()->DisableAnimationTimers();
186 non_zero_duration_mode_ = 180 non_zero_duration_mode_ =
187 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( 181 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
188 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 182 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
189 } 183 }
190 184
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 231 }
238 232
239 void ScreenRotationAnimatorSmoothAnimationTest::SetUp() { 233 void ScreenRotationAnimatorSmoothAnimationTest::SetUp() {
240 AshTestBase::SetUp(); 234 AshTestBase::SetUp();
241 // Resets the commandline will clear all the switches, including 235 // Resets the commandline will clear all the switches, including
242 // "ash-disable-smooth-screen-rotation", so that we can test the smooth screen 236 // "ash-disable-smooth-screen-rotation", so that we can test the smooth screen
243 // rotation animation. The |animator| is recreated and checking this swtich. 237 // rotation animation. The |animator| is recreated and checking this swtich.
244 ash_test_helper()->reset_commandline(); 238 ash_test_helper()->reset_commandline();
245 239
246 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); 240 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
247 if (Shell::GetAshConfig() == Config::MASH) {
248 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
249 display_id());
250 return;
251 }
252
253 run_loop_ = base::MakeUnique<base::RunLoop>(); 241 run_loop_ = base::MakeUnique<base::RunLoop>();
254 SetScreenRotationAnimator(GetRootWindow(display_.id()), 242 SetScreenRotationAnimator(GetRootWindow(display_.id()),
255 run_loop_->QuitWhenIdleClosure(), 243 run_loop_->QuitWhenIdleClosure(),
256 run_loop_->QuitWhenIdleClosure()); 244 run_loop_->QuitWhenIdleClosure());
257 non_zero_duration_mode_ = 245 non_zero_duration_mode_ =
258 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( 246 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
259 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 247 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
260 } 248 }
261 249
262 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator( 250 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator(
263 aura::Window* root_window, 251 aura::Window* root_window,
264 const base::Closure& before_callback, 252 const base::Closure& before_callback,
265 const base::Closure& after_callback) { 253 const base::Closure& after_callback) {
266 animator_ = base::MakeUnique<TestScreenRotationAnimator>( 254 animator_ = base::MakeUnique<TestScreenRotationAnimator>(
267 root_window, before_callback, after_callback); 255 root_window, before_callback, after_callback);
268 test_api_ = 256 test_api_ =
269 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); 257 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
270 test_api()->DisableAnimationTimers(); 258 test_api()->DisableAnimationTimers();
271 } 259 }
272 260
273 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() { 261 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() {
274 run_loop_.reset(new base::RunLoop()); 262 run_loop_.reset(new base::RunLoop());
275 run_loop_->Run(); 263 run_loop_->Run();
276 } 264 }
277 265
278 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldNotifyObserver) { 266 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldNotifyObserver) {
279 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
280 if (Shell::GetAshConfig() == Config::MASH) {
281 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
282 display_id());
283 return;
284 }
285
286 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 267 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
287 AnimationObserver observer; 268 AnimationObserver observer;
288 animator()->AddScreenRotationAnimatorObserver(&observer); 269 animator()->AddScreenRotationAnimatorObserver(&observer);
289 EXPECT_FALSE(observer.notified()); 270 EXPECT_FALSE(observer.notified());
290 271
291 animator()->Rotate(display::Display::ROTATE_90, 272 animator()->Rotate(display::Display::ROTATE_90,
292 display::Display::RotationSource::ROTATION_SOURCE_USER); 273 display::Display::RotationSource::ROTATION_SOURCE_USER);
293 EXPECT_FALSE(observer.notified()); 274 EXPECT_FALSE(observer.notified());
294 275
295 test_api()->CompleteAnimations(); 276 test_api()->CompleteAnimations();
296 EXPECT_TRUE(observer.notified()); 277 EXPECT_TRUE(observer.notified());
297 EXPECT_FALSE(test_api()->HasActiveAnimations()); 278 EXPECT_FALSE(test_api()->HasActiveAnimations());
298 animator()->RemoveScreenRotationAnimatorObserver(&observer); 279 animator()->RemoveScreenRotationAnimatorObserver(&observer);
299 } 280 }
300 281
301 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldNotifyObserverOnce) { 282 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldNotifyObserverOnce) {
302 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
303 if (Shell::GetAshConfig() == Config::MASH) {
304 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
305 display_id());
306 return;
307 }
308
309 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 283 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
310 AnimationObserver observer; 284 AnimationObserver observer;
311 animator()->AddScreenRotationAnimatorObserver(&observer); 285 animator()->AddScreenRotationAnimatorObserver(&observer);
312 EXPECT_FALSE(observer.notified()); 286 EXPECT_FALSE(observer.notified());
313 287
314 animator()->Rotate(display::Display::ROTATE_90, 288 animator()->Rotate(display::Display::ROTATE_90,
315 display::Display::RotationSource::ROTATION_SOURCE_USER); 289 display::Display::RotationSource::ROTATION_SOURCE_USER);
316 EXPECT_FALSE(observer.notified()); 290 EXPECT_FALSE(observer.notified());
317 291
318 animator()->Rotate(display::Display::ROTATE_180, 292 animator()->Rotate(display::Display::ROTATE_180,
319 display::Display::RotationSource::ROTATION_SOURCE_USER); 293 display::Display::RotationSource::ROTATION_SOURCE_USER);
320 EXPECT_FALSE(observer.notified()); 294 EXPECT_FALSE(observer.notified());
321 295
322 test_api()->CompleteAnimations(); 296 test_api()->CompleteAnimations();
323 EXPECT_TRUE(observer.notified()); 297 EXPECT_TRUE(observer.notified());
324 EXPECT_FALSE(test_api()->HasActiveAnimations()); 298 EXPECT_FALSE(test_api()->HasActiveAnimations());
325 animator()->RemoveScreenRotationAnimatorObserver(&observer); 299 animator()->RemoveScreenRotationAnimatorObserver(&observer);
326 } 300 }
327 301
328 TEST_F(ScreenRotationAnimatorSlowAnimationTest, RotatesToDifferentRotation) { 302 TEST_F(ScreenRotationAnimatorSlowAnimationTest, RotatesToDifferentRotation) {
329 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
330 if (Shell::GetAshConfig() == Config::MASH) {
331 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
332 display_id());
333 return;
334 }
335
336 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 303 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
337 animator()->Rotate(display::Display::ROTATE_90, 304 animator()->Rotate(display::Display::ROTATE_90,
338 display::Display::RotationSource::ROTATION_SOURCE_USER); 305 display::Display::RotationSource::ROTATION_SOURCE_USER);
339 EXPECT_TRUE(test_api()->HasActiveAnimations()); 306 EXPECT_TRUE(test_api()->HasActiveAnimations());
340 307
341 test_api()->CompleteAnimations(); 308 test_api()->CompleteAnimations();
342 EXPECT_FALSE(test_api()->HasActiveAnimations()); 309 EXPECT_FALSE(test_api()->HasActiveAnimations());
343 } 310 }
344 311
345 TEST_F(ScreenRotationAnimatorSlowAnimationTest, 312 TEST_F(ScreenRotationAnimatorSlowAnimationTest,
346 ShouldNotRotateTheSameRotation) { 313 ShouldNotRotateTheSameRotation) {
347 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
348 if (Shell::GetAshConfig() == Config::MASH) {
349 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
350 display_id());
351 return;
352 }
353
354 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 314 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
355 animator()->Rotate(display::Display::ROTATE_0, 315 animator()->Rotate(display::Display::ROTATE_0,
356 display::Display::RotationSource::ROTATION_SOURCE_USER); 316 display::Display::RotationSource::ROTATION_SOURCE_USER);
357 EXPECT_FALSE(test_api()->HasActiveAnimations()); 317 EXPECT_FALSE(test_api()->HasActiveAnimations());
358 } 318 }
359 319
360 // Simulates the situation that if there is a new rotation request during 320 // Simulates the situation that if there is a new rotation request during
361 // animation, it should stop the animation immediately and add the new rotation 321 // animation, it should stop the animation immediately and add the new rotation
362 // request to the |last_pending_request_|. 322 // request to the |last_pending_request_|.
363 TEST_F(ScreenRotationAnimatorSlowAnimationTest, RotatesDuringRotation) { 323 TEST_F(ScreenRotationAnimatorSlowAnimationTest, RotatesDuringRotation) {
364 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
365 if (Shell::GetAshConfig() == Config::MASH) {
366 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
367 display_id());
368 return;
369 }
370
371 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 324 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
372 animator()->Rotate(display::Display::ROTATE_90, 325 animator()->Rotate(display::Display::ROTATE_90,
373 display::Display::RotationSource::ROTATION_SOURCE_USER); 326 display::Display::RotationSource::ROTATION_SOURCE_USER);
374 animator()->Rotate(display::Display::ROTATE_180, 327 animator()->Rotate(display::Display::ROTATE_180,
375 display::Display::RotationSource::ROTATION_SOURCE_USER); 328 display::Display::RotationSource::ROTATION_SOURCE_USER);
376 EXPECT_TRUE(test_api()->HasActiveAnimations()); 329 EXPECT_TRUE(test_api()->HasActiveAnimations());
377 330
378 test_api()->CompleteAnimations(); 331 test_api()->CompleteAnimations();
379 EXPECT_FALSE(test_api()->HasActiveAnimations()); 332 EXPECT_FALSE(test_api()->HasActiveAnimations());
380 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id())); 333 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id()));
381 } 334 }
382 335
383 // If there are multiple requests queued during animation, it should process the 336 // If there are multiple requests queued during animation, it should process the
384 // last request and finish the rotation animation. 337 // last request and finish the rotation animation.
385 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldCompleteAnimations) { 338 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldCompleteAnimations) {
386 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
387 if (Shell::GetAshConfig() == Config::MASH) {
388 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
389 display_id());
390 return;
391 }
392
393 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 339 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
394 animator()->Rotate(display::Display::ROTATE_90, 340 animator()->Rotate(display::Display::ROTATE_90,
395 display::Display::RotationSource::ROTATION_SOURCE_USER); 341 display::Display::RotationSource::ROTATION_SOURCE_USER);
396 EXPECT_TRUE(test_api()->HasActiveAnimations()); 342 EXPECT_TRUE(test_api()->HasActiveAnimations());
397 343
398 animator()->Rotate(display::Display::ROTATE_180, 344 animator()->Rotate(display::Display::ROTATE_180,
399 display::Display::RotationSource::ROTATION_SOURCE_USER); 345 display::Display::RotationSource::ROTATION_SOURCE_USER);
400 EXPECT_TRUE(test_api()->HasActiveAnimations()); 346 EXPECT_TRUE(test_api()->HasActiveAnimations());
401 347
402 animator()->Rotate(display::Display::ROTATE_270, 348 animator()->Rotate(display::Display::ROTATE_270,
403 display::Display::RotationSource::ROTATION_SOURCE_USER); 349 display::Display::RotationSource::ROTATION_SOURCE_USER);
404 EXPECT_TRUE(test_api()->HasActiveAnimations()); 350 EXPECT_TRUE(test_api()->HasActiveAnimations());
405 351
406 test_api()->CompleteAnimations(); 352 test_api()->CompleteAnimations();
407 EXPECT_FALSE(test_api()->HasActiveAnimations()); 353 EXPECT_FALSE(test_api()->HasActiveAnimations());
408 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); 354 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id()));
409 } 355 }
410 356
411 // Test that slow screen rotation animation will not interrupt hide animation. 357 // Test that slow screen rotation animation will not interrupt hide animation.
412 // The OverviewButton should be hidden. 358 // The OverviewButton should be hidden.
413 TEST_F(ScreenRotationAnimatorSlowAnimationTest, 359 TEST_F(ScreenRotationAnimatorSlowAnimationTest,
414 OverviewButtonTrayHideAnimationAlwaysCompletes) { 360 OverviewButtonTrayHideAnimationAlwaysCompletes) {
415 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
416 if (Shell::GetAshConfig() == Config::MASH) {
417 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
418 display_id());
419 return;
420 }
421
422 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 361 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
423 true); 362 true);
424 363
425 // Long duration for hide animation, to allow it to be interrupted. 364 // Long duration for hide animation, to allow it to be interrupted.
426 ui::ScopedAnimationDurationScaleMode hide_duration( 365 ui::ScopedAnimationDurationScaleMode hide_duration(
427 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 366 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
428 GetTray()->SetVisible(false); 367 GetTray()->SetVisible(false);
429 368
430 // ScreenRotationAnimator copies the current layers, and deletes them upon 369 // ScreenRotationAnimator copies the current layers, and deletes them upon
431 // completion. Allow its animation to complete first. 370 // completion. Allow its animation to complete first.
432 ui::ScopedAnimationDurationScaleMode rotate_duration( 371 ui::ScopedAnimationDurationScaleMode rotate_duration(
433 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 372 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
434 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 373 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
435 animator()->Rotate(display::Display::ROTATE_90, 374 animator()->Rotate(display::Display::ROTATE_90,
436 display::Display::RotationSource::ROTATION_SOURCE_USER); 375 display::Display::RotationSource::ROTATION_SOURCE_USER);
437 376
438 EXPECT_FALSE(GetTray()->visible()); 377 EXPECT_FALSE(GetTray()->visible());
439 } 378 }
440 379
441 // Test enable smooth screen rotation code path. 380 // Test enable smooth screen rotation code path.
442 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 381 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
443 RotatesToDifferentRotationWithCopyCallback) { 382 RotatesToDifferentRotationWithCopyCallback) {
444 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 383 // TODO(sky): remove this, temporary until mash_unittests as a separate
445 if (Shell::GetAshConfig() == Config::MASH) { 384 // executable is nuked. http://crbug.com/729810.
446 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 385 if (Shell::GetAshConfig() == Config::MASH)
447 display_id());
448 return; 386 return;
449 }
450 387
451 const int64_t display_id = display_manager()->GetDisplayAt(0).id(); 388 const int64_t display_id = display_manager()->GetDisplayAt(0).id();
452 SetScreenRotationAnimator( 389 SetScreenRotationAnimator(
453 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(), 390 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(),
454 base::Bind( 391 base::Bind(
455 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, 392 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
456 base::Unretained(this))); 393 base::Unretained(this)));
457 SetDisplayRotation(display_id, display::Display::ROTATE_0); 394 SetDisplayRotation(display_id, display::Display::ROTATE_0);
458 animator()->Rotate(display::Display::ROTATE_90, 395 animator()->Rotate(display::Display::ROTATE_90,
459 display::Display::RotationSource::ROTATION_SOURCE_USER); 396 display::Display::RotationSource::ROTATION_SOURCE_USER);
460 WaitForCopyCallback(); 397 WaitForCopyCallback();
461 EXPECT_TRUE(test_api()->HasActiveAnimations()); 398 EXPECT_TRUE(test_api()->HasActiveAnimations());
462 399
463 test_api()->CompleteAnimations(); 400 test_api()->CompleteAnimations();
464 EXPECT_FALSE(test_api()->HasActiveAnimations()); 401 EXPECT_FALSE(test_api()->HasActiveAnimations());
465 EXPECT_EQ(display::Display::ROTATE_90, GetDisplayRotation(display_id)); 402 EXPECT_EQ(display::Display::ROTATE_90, GetDisplayRotation(display_id));
466 } 403 }
467 404
468 // If the rotating external secondary display is removed before the first copy 405 // If the rotating external secondary display is removed before the first copy
469 // request callback called, it should stop rotating. 406 // request callback called, it should stop rotating.
470 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 407 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
471 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) { 408 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) {
472 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
473 if (Shell::GetAshConfig() == Config::MASH) {
474 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
475 display_id());
476 return;
477 }
478
479 UpdateDisplay("640x480,800x600"); 409 UpdateDisplay("640x480,800x600");
480 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 410 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
481 411
482 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id(); 412 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
483 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id(); 413 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
484 414
485 SetScreenRotationAnimator( 415 SetScreenRotationAnimator(
486 GetRootWindow(secondary_display_id), 416 GetRootWindow(secondary_display_id),
487 base::Bind( 417 base::Bind(
488 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 418 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
489 base::Unretained(this), "640x480"), 419 base::Unretained(this), "640x480"),
490 run_loop_->QuitWhenIdleClosure()); 420 run_loop_->QuitWhenIdleClosure());
491 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0); 421 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
492 animator()->Rotate(display::Display::ROTATE_90, 422 animator()->Rotate(display::Display::ROTATE_90,
493 display::Display::RotationSource::ROTATION_SOURCE_USER); 423 display::Display::RotationSource::ROTATION_SOURCE_USER);
494 WaitForCopyCallback(); 424 WaitForCopyCallback();
495 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 425 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
496 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); 426 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
497 } 427 }
498 428
499 // If the rotating external primary display is removed before the first copy 429 // If the rotating external primary display is removed before the first copy
500 // request callback called, it should stop rotating. 430 // request callback called, it should stop rotating.
501 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 431 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
502 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) { 432 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) {
503 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
504 if (Shell::GetAshConfig() == Config::MASH) {
505 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
506 display_id());
507 return;
508 }
509
510 UpdateDisplay("640x480,800x600"); 433 UpdateDisplay("640x480,800x600");
511 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 434 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
512 435
513 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( 436 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
514 display_manager()->GetDisplayAt(1).id()); 437 display_manager()->GetDisplayAt(1).id());
515 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id(); 438 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id();
516 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id(); 439 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
517 SetScreenRotationAnimator( 440 SetScreenRotationAnimator(
518 GetRootWindow(primary_display_id), 441 GetRootWindow(primary_display_id),
519 base::Bind( 442 base::Bind(
520 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 443 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
521 base::Unretained(this), "640x480"), 444 base::Unretained(this), "640x480"),
522 run_loop_->QuitWhenIdleClosure()); 445 run_loop_->QuitWhenIdleClosure());
523 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0); 446 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0);
524 animator()->Rotate(display::Display::ROTATE_90, 447 animator()->Rotate(display::Display::ROTATE_90,
525 display::Display::RotationSource::ROTATION_SOURCE_USER); 448 display::Display::RotationSource::ROTATION_SOURCE_USER);
526 WaitForCopyCallback(); 449 WaitForCopyCallback();
527 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 450 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
528 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 451 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
529 } 452 }
530 453
531 // If the rotating external secondary display is removed before the second copy 454 // If the rotating external secondary display is removed before the second copy
532 // request callback called, it should stop rotating. 455 // request callback called, it should stop rotating.
533 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 456 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
534 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) { 457 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) {
535 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 458 // TODO(sky): remove this, temporary until mash_unittests as a separate
536 if (Shell::GetAshConfig() == Config::MASH) { 459 // executable is nuked. http://crbug.com/729810.
537 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 460 if (Shell::GetAshConfig() == Config::MASH)
538 display_id());
539 return; 461 return;
540 }
541 462
542 UpdateDisplay("640x480,800x600"); 463 UpdateDisplay("640x480,800x600");
543 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 464 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
544 465
545 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id(); 466 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
546 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id(); 467 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
547 SetScreenRotationAnimator( 468 SetScreenRotationAnimator(
548 GetRootWindow(secondary_display_id), run_loop_->QuitWhenIdleClosure(), 469 GetRootWindow(secondary_display_id), run_loop_->QuitWhenIdleClosure(),
549 base::Bind( 470 base::Bind(
550 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 471 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
551 base::Unretained(this), "640x480")); 472 base::Unretained(this), "640x480"));
552 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0); 473 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
553 animator()->Rotate(display::Display::ROTATE_90, 474 animator()->Rotate(display::Display::ROTATE_90,
554 display::Display::RotationSource::ROTATION_SOURCE_USER); 475 display::Display::RotationSource::ROTATION_SOURCE_USER);
555 WaitForCopyCallback(); 476 WaitForCopyCallback();
556 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 477 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
557 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); 478 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
558 } 479 }
559 480
560 // If the rotating external primary display is removed before the second copy 481 // If the rotating external primary display is removed before the second copy
561 // request callback called, it should stop rotating. 482 // request callback called, it should stop rotating.
562 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 483 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
563 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) { 484 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) {
564 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 485 // TODO(sky): remove this, temporary until mash_unittests as a separate
565 if (Shell::GetAshConfig() == Config::MASH) { 486 // executable is nuked. http://crbug.com/729810.
566 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 487 if (Shell::GetAshConfig() == Config::MASH)
567 display_id());
568 return; 488 return;
569 }
570 489
571 UpdateDisplay("640x480,800x600"); 490 UpdateDisplay("640x480,800x600");
572 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 491 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
573 492
574 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( 493 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
575 display_manager()->GetDisplayAt(1).id()); 494 display_manager()->GetDisplayAt(1).id());
576 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id(); 495 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id();
577 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id(); 496 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
578 SetScreenRotationAnimator( 497 SetScreenRotationAnimator(
579 GetRootWindow(primary_display_id), run_loop_->QuitWhenIdleClosure(), 498 GetRootWindow(primary_display_id), run_loop_->QuitWhenIdleClosure(),
580 base::Bind( 499 base::Bind(
581 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 500 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
582 base::Unretained(this), "640x480")); 501 base::Unretained(this), "640x480"));
583 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0); 502 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0);
584 animator()->Rotate(display::Display::ROTATE_90, 503 animator()->Rotate(display::Display::ROTATE_90,
585 display::Display::RotationSource::ROTATION_SOURCE_USER); 504 display::Display::RotationSource::ROTATION_SOURCE_USER);
586 WaitForCopyCallback(); 505 WaitForCopyCallback();
587 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 506 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
588 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 507 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
589 } 508 }
590 509
591 // If the external primary display is removed while rotating the secondary 510 // If the external primary display is removed while rotating the secondary
592 // display. It should stop rotating the secondary display because the 511 // display. It should stop rotating the secondary display because the
593 // |root_window| changed. 512 // |root_window| changed.
594 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 513 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
595 RemoveExternalPrimaryDisplayDuringAnimationChangedRootWindow) { 514 RemoveExternalPrimaryDisplayDuringAnimationChangedRootWindow) {
596 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
597 if (Shell::GetAshConfig() == Config::MASH) {
598 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
599 display_id());
600 return;
601 }
602
603 UpdateDisplay("640x480,800x600"); 515 UpdateDisplay("640x480,800x600");
604 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 516 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
605 517
606 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( 518 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
607 display_manager()->GetDisplayAt(1).id()); 519 display_manager()->GetDisplayAt(1).id());
608 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id(); 520 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
609 SetScreenRotationAnimator( 521 SetScreenRotationAnimator(
610 GetRootWindow(secondary_display_id), 522 GetRootWindow(secondary_display_id),
611 base::Bind( 523 base::Bind(
612 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 524 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
613 base::Unretained(this), "640x480"), 525 base::Unretained(this), "640x480"),
614 run_loop_->QuitWhenIdleClosure()); 526 run_loop_->QuitWhenIdleClosure());
615 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0); 527 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
616 animator()->Rotate(display::Display::ROTATE_90, 528 animator()->Rotate(display::Display::ROTATE_90,
617 display::Display::RotationSource::ROTATION_SOURCE_USER); 529 display::Display::RotationSource::ROTATION_SOURCE_USER);
618 WaitForCopyCallback(); 530 WaitForCopyCallback();
619 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 531 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
620 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 532 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
621 EXPECT_EQ(display::Display::ROTATE_0, 533 EXPECT_EQ(display::Display::ROTATE_0,
622 GetDisplayRotation(secondary_display_id)); 534 GetDisplayRotation(secondary_display_id));
623 } 535 }
624 536
625 // Test that smooth screen rotation animation will not interrupt hide animation. 537 // Test that smooth screen rotation animation will not interrupt hide animation.
626 // The OverviewButton should be hidden. 538 // The OverviewButton should be hidden.
627 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 539 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
628 OverviewButtonTrayHideAnimationAlwaysCompletes) { 540 OverviewButtonTrayHideAnimationAlwaysCompletes) {
629 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 541 // TODO(sky): remove this, temporary until mash_unittests as a separate
630 if (Shell::GetAshConfig() == Config::MASH) { 542 // executable is nuked. http://crbug.com/729810.
631 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 543 if (Shell::GetAshConfig() == Config::MASH)
632 display_id());
633 return; 544 return;
634 }
635 545
636 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 546 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
637 true); 547 true);
638 548
639 // Long duration for hide animation, to allow it to be interrupted. 549 // Long duration for hide animation, to allow it to be interrupted.
640 ui::ScopedAnimationDurationScaleMode hide_duration( 550 ui::ScopedAnimationDurationScaleMode hide_duration(
641 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 551 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
642 GetTray()->SetVisible(false); 552 GetTray()->SetVisible(false);
643 553
644 // Allow ScreenRotationAnimator animation to complete first. 554 // Allow ScreenRotationAnimator animation to complete first.
645 ui::ScopedAnimationDurationScaleMode rotate_duration( 555 ui::ScopedAnimationDurationScaleMode rotate_duration(
646 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 556 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
647 int64_t display_id = display_manager()->GetDisplayAt(0).id(); 557 int64_t display_id = display_manager()->GetDisplayAt(0).id();
648 SetScreenRotationAnimator( 558 SetScreenRotationAnimator(
649 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(), 559 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(),
650 base::Bind( 560 base::Bind(
651 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, 561 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
652 base::Unretained(this))); 562 base::Unretained(this)));
653 SetDisplayRotation(display_id, display::Display::ROTATE_0); 563 SetDisplayRotation(display_id, display::Display::ROTATE_0);
654 animator()->Rotate(display::Display::ROTATE_90, 564 animator()->Rotate(display::Display::ROTATE_90,
655 display::Display::RotationSource::ROTATION_SOURCE_USER); 565 display::Display::RotationSource::ROTATION_SOURCE_USER);
656 WaitForCopyCallback(); 566 WaitForCopyCallback();
657 567
658 GetTray()->layer()->GetAnimator()->StopAnimating(); 568 GetTray()->layer()->GetAnimator()->StopAnimating();
659 EXPECT_FALSE(GetTray()->visible()); 569 EXPECT_FALSE(GetTray()->visible());
660 } 570 }
661 571
662 } // namespace ash 572 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/window_manager_application.cc ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698