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

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

Issue 2845123003: Add more tests to test OverviewButtonTray. (Closed)
Patch Set: Add tests in Screen Rotation Animator for interaction with OverviewButtonTray hide animation. Created 3 years, 7 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 | « no previous file | ash/system/overview/overview_button_tray_unittest.cc » ('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"
11 #include "ash/rotator/test/screen_rotation_animator_test_api.h" 11 #include "ash/rotator/test/screen_rotation_animator_test_api.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h" 13 #include "ash/shell_port.h"
14 #include "ash/system/overview/overview_button_tray.h"
15 #include "ash/system/status_area_widget.h"
14 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
15 #include "ash/test/ash_test_helper.h" 17 #include "ash/test/ash_test_helper.h"
18 #include "ash/test/status_area_widget_test_helper.h"
19 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
16 #include "base/callback_forward.h" 20 #include "base/callback_forward.h"
17 #include "base/command_line.h" 21 #include "base/command_line.h"
18 #include "base/memory/ptr_util.h" 22 #include "base/memory/ptr_util.h"
19 #include "base/run_loop.h" 23 #include "base/run_loop.h"
20 #include "cc/output/copy_output_request.h" 24 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h" 25 #include "cc/output/copy_output_result.h"
22 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
23 #include "ui/display/display.h" 27 #include "ui/display/display.h"
24 #include "ui/display/manager/display_manager.h" 28 #include "ui/display/manager/display_manager.h"
25 #include "ui/display/screen.h" 29 #include "ui/display/screen.h"
26 30
27 namespace ash { 31 namespace ash {
28 32
29 namespace { 33 namespace {
30 34
31 display::Display::Rotation GetDisplayRotation(int64_t display_id) { 35 display::Display::Rotation GetDisplayRotation(int64_t display_id) {
32 return Shell::Get() 36 return Shell::Get()
33 ->display_manager() 37 ->display_manager()
34 ->GetDisplayInfo(display_id) 38 ->GetDisplayInfo(display_id)
35 .GetActiveRotation(); 39 .GetActiveRotation();
36 } 40 }
37 41
38 void SetDisplayRotation(int64_t display_id, 42 void SetDisplayRotation(int64_t display_id,
39 display::Display::Rotation rotation) { 43 display::Display::Rotation rotation) {
40 Shell::Get()->display_manager()->SetDisplayRotation( 44 Shell::Get()->display_manager()->SetDisplayRotation(
41 display_id, rotation, 45 display_id, rotation,
42 display::Display::RotationSource::ROTATION_SOURCE_USER); 46 display::Display::RotationSource::ROTATION_SOURCE_USER);
43 } 47 }
44 48
49 OverviewButtonTray* GetTray() {
50 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()
51 ->overview_button_tray();
52 }
53
45 class AnimationObserver : public ScreenRotationAnimatorObserver { 54 class AnimationObserver : public ScreenRotationAnimatorObserver {
46 public: 55 public:
47 AnimationObserver() {} 56 AnimationObserver() {}
48 57
49 bool notified() const { return notified_; } 58 bool notified() const { return notified_; }
50 59
51 void OnScreenRotationAnimationFinished( 60 void OnScreenRotationAnimationFinished(
52 ScreenRotationAnimator* animator) override { 61 ScreenRotationAnimator* animator) override {
53 notified_ = true; 62 notified_ = true;
54 } 63 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 394
386 animator()->Rotate(display::Display::ROTATE_270, 395 animator()->Rotate(display::Display::ROTATE_270,
387 display::Display::RotationSource::ROTATION_SOURCE_USER); 396 display::Display::RotationSource::ROTATION_SOURCE_USER);
388 EXPECT_TRUE(test_api()->HasActiveAnimations()); 397 EXPECT_TRUE(test_api()->HasActiveAnimations());
389 398
390 test_api()->CompleteAnimations(); 399 test_api()->CompleteAnimations();
391 EXPECT_FALSE(test_api()->HasActiveAnimations()); 400 EXPECT_FALSE(test_api()->HasActiveAnimations());
392 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); 401 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id()));
393 } 402 }
394 403
404 // Test that slow screen rotation animation will not interrupt hide animation.
405 // The OverviewButton should be hidden.
406 TEST_F(ScreenRotationAnimatorSlowAnimationTest,
407 OverviewButtonTrayHideAnimationAlwaysCompletes) {
408 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
409 if (Shell::GetAshConfig() == Config::MASH) {
410 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
411 display_id());
412 return;
413 }
414
415 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
416 true);
417
418 // Long duration for hide animation, to allow it to be interrupted.
419 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> hide_duration(
oshima 2017/05/06 21:02:20 can't you just create on a stack? same for the re
wutao 2017/05/31 17:29:55 Done.
420 new ui::ScopedAnimationDurationScaleMode(
421 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
422 GetTray()->SetVisible(false);
423
424 // ScreenRotationAnimator copies the current layers, and deletes them upon
425 // completion. Allow its animation to complete first.
426 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> rotate_duration(
427 new ui::ScopedAnimationDurationScaleMode(
428 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
429 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
430 animator()->Rotate(display::Display::ROTATE_90,
431 display::Display::RotationSource::ROTATION_SOURCE_USER);
432
433 EXPECT_FALSE(GetTray()->visible());
434 }
435
395 // Test enable smooth screen rotation code path. 436 // Test enable smooth screen rotation code path.
396 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 437 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
397 RotatesToDifferentRotationWithCopyCallback) { 438 RotatesToDifferentRotationWithCopyCallback) {
398 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 439 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
399 if (Shell::GetAshConfig() == Config::MASH) { 440 if (Shell::GetAshConfig() == Config::MASH) {
400 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 441 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
401 display_id()); 442 display_id());
402 return; 443 return;
403 } 444 }
404 445
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 base::Unretained(this), "640x480")); 577 base::Unretained(this), "640x480"));
537 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 578 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
538 display::Display::ROTATE_0); 579 display::Display::ROTATE_0);
539 animator()->Rotate(display::Display::ROTATE_90, 580 animator()->Rotate(display::Display::ROTATE_90,
540 display::Display::RotationSource::ROTATION_SOURCE_USER); 581 display::Display::RotationSource::ROTATION_SOURCE_USER);
541 WaitForCopyCallback(); 582 WaitForCopyCallback();
542 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 583 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
543 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 584 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
544 } 585 }
545 586
587 // Test that smooth screen rotation animation will not interrupt hide animation.
588 // The OverviewButton should be hidden.
589 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
590 OverviewButtonTrayHideAnimationAlwaysCompletes) {
591 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
592 if (Shell::GetAshConfig() == Config::MASH) {
593 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
594 display_id());
595 return;
596 }
597
598 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
599 true);
600
601 // Long duration for hide animation, to allow it to be interrupted.
602 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> hide_duration(
603 new ui::ScopedAnimationDurationScaleMode(
604 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
605 GetTray()->SetVisible(false);
606
607 // Allow ScreenRotationAnimator animation to complete first.
608 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> rotate_duration(
609 new ui::ScopedAnimationDurationScaleMode(
610 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
611 SetScreenRotationAnimator(
612 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(),
613 base::Bind(
614 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
615 base::Unretained(this)));
616 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
617 animator()->Rotate(display::Display::ROTATE_90,
618 display::Display::RotationSource::ROTATION_SOURCE_USER);
619 WaitForCopyCallback();
620
621 GetTray()->layer()->GetAnimator()->StopAnimating();
622 EXPECT_FALSE(GetTray()->visible());
623 }
624
546 } // namespace ash 625 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/overview/overview_button_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698