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

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

Issue 2845123003: Add more tests to test OverviewButtonTray. (Closed)
Patch Set: Fix nits in patch 2. 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 | « 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 ui::ScopedAnimationDurationScaleMode hide_duration(
420 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
421 GetTray()->SetVisible(false);
422
423 // ScreenRotationAnimator copies the current layers, and deletes them upon
424 // completion. Allow its animation to complete first.
425 ui::ScopedAnimationDurationScaleMode rotate_duration(
426 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
427 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
428 animator()->Rotate(display::Display::ROTATE_90,
429 display::Display::RotationSource::ROTATION_SOURCE_USER);
430
431 EXPECT_FALSE(GetTray()->visible());
432 }
433
395 // Test enable smooth screen rotation code path. 434 // Test enable smooth screen rotation code path.
396 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 435 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
397 RotatesToDifferentRotationWithCopyCallback) { 436 RotatesToDifferentRotationWithCopyCallback) {
398 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 437 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
399 if (Shell::GetAshConfig() == Config::MASH) { 438 if (Shell::GetAshConfig() == Config::MASH) {
400 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 439 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
401 display_id()); 440 display_id());
402 return; 441 return;
403 } 442 }
404 443
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 base::Unretained(this), "640x480")); 575 base::Unretained(this), "640x480"));
537 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 576 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
538 display::Display::ROTATE_0); 577 display::Display::ROTATE_0);
539 animator()->Rotate(display::Display::ROTATE_90, 578 animator()->Rotate(display::Display::ROTATE_90,
540 display::Display::RotationSource::ROTATION_SOURCE_USER); 579 display::Display::RotationSource::ROTATION_SOURCE_USER);
541 WaitForCopyCallback(); 580 WaitForCopyCallback();
542 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 581 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
543 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 582 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
544 } 583 }
545 584
585 // Test that smooth screen rotation animation will not interrupt hide animation.
586 // The OverviewButton should be hidden.
587 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
588 OverviewButtonTrayHideAnimationAlwaysCompletes) {
589 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
590 if (Shell::GetAshConfig() == Config::MASH) {
591 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
592 display_id());
593 return;
594 }
595
596 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
597 true);
598
599 // Long duration for hide animation, to allow it to be interrupted.
600 ui::ScopedAnimationDurationScaleMode hide_duration(
601 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
602 GetTray()->SetVisible(false);
603
604 // Allow ScreenRotationAnimator animation to complete first.
605 ui::ScopedAnimationDurationScaleMode rotate_duration(
606 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
607 SetScreenRotationAnimator(
608 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(),
609 base::Bind(
610 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
611 base::Unretained(this)));
612 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
613 animator()->Rotate(display::Display::ROTATE_90,
614 display::Display::RotationSource::ROTATION_SOURCE_USER);
615 WaitForCopyCallback();
616
617 GetTray()->layer()->GetAnimator()->StopAnimating();
618 EXPECT_FALSE(GetTray()->visible());
619 }
620
546 } // namespace ash 621 } // 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