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

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

Issue 2910413002: cros: Do not cache |root_window| in ScreenRotationAnimator. (Closed)
Patch Set: 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
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 24 matching lines...) Expand all
35 .GetActiveRotation(); 35 .GetActiveRotation();
36 } 36 }
37 37
38 void SetDisplayRotation(int64_t display_id, 38 void SetDisplayRotation(int64_t display_id,
39 display::Display::Rotation rotation) { 39 display::Display::Rotation rotation) {
40 Shell::Get()->display_manager()->SetDisplayRotation( 40 Shell::Get()->display_manager()->SetDisplayRotation(
41 display_id, rotation, 41 display_id, rotation,
42 display::Display::RotationSource::ROTATION_SOURCE_USER); 42 display::Display::RotationSource::ROTATION_SOURCE_USER);
43 } 43 }
44 44
45 aura::Window* GetRootWindow(int64_t display_id) {
46 return Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId(
47 display_id);
48 }
49
45 class AnimationObserver : public ScreenRotationAnimatorObserver { 50 class AnimationObserver : public ScreenRotationAnimatorObserver {
46 public: 51 public:
47 AnimationObserver() {} 52 AnimationObserver() {}
48 53
49 bool notified() const { return notified_; } 54 bool notified() const { return notified_; }
50 55
51 void OnScreenRotationAnimationFinished( 56 void OnScreenRotationAnimationFinished(
52 ScreenRotationAnimator* animator) override { 57 ScreenRotationAnimator* animator) override {
53 notified_ = true; 58 notified_ = true;
54 } 59 }
55 60
56 private: 61 private:
57 bool notified_ = false; 62 bool notified_ = false;
58 63
59 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); 64 DISALLOW_COPY_AND_ASSIGN(AnimationObserver);
60 }; 65 };
61 66
62 class TestScreenRotationAnimator : public ScreenRotationAnimator { 67 class TestScreenRotationAnimator : public ScreenRotationAnimator {
63 public: 68 public:
64 TestScreenRotationAnimator(int64_t display_id, 69 TestScreenRotationAnimator(int64_t display_id,
65 const base::Closure& before_callback, 70 const base::Closure& before_callback,
66 const base::Closure& after_callback); 71 const base::Closure& after_callback);
67 ~TestScreenRotationAnimator() override {} 72 ~TestScreenRotationAnimator() override {}
68 73
74 void set_intersect_after_callback(const base::Closure& after_callback) {
75 intersect_after_callback_ = after_callback;
76 }
77
69 private: 78 private:
70 CopyCallback CreateAfterCopyCallbackBeforeRotation( 79 CopyCallback CreateAfterCopyCallbackBeforeRotation(
71 std::unique_ptr<ScreenRotationRequest> rotation_request) override; 80 std::unique_ptr<ScreenRotationRequest> rotation_request) override;
72 CopyCallback CreateAfterCopyCallbackAfterRotation( 81 CopyCallback CreateAfterCopyCallbackAfterRotation(
73 std::unique_ptr<ScreenRotationRequest> rotation_request) override; 82 std::unique_ptr<ScreenRotationRequest> rotation_request) override;
74 83
75 void IntersectBefore(CopyCallback next_callback, 84 void IntersectBefore(CopyCallback next_callback,
76 std::unique_ptr<cc::CopyOutputResult> result); 85 std::unique_ptr<cc::CopyOutputResult> result);
77 void IntersectAfter(CopyCallback next_callback, 86 void IntersectAfter(CopyCallback next_callback,
78 std::unique_ptr<cc::CopyOutputResult> result); 87 std::unique_ptr<cc::CopyOutputResult> result);
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 base::Unretained(this), "640x480")); 545 base::Unretained(this), "640x480"));
537 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 546 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
538 display::Display::ROTATE_0); 547 display::Display::ROTATE_0);
539 animator()->Rotate(display::Display::ROTATE_90, 548 animator()->Rotate(display::Display::ROTATE_90,
540 display::Display::RotationSource::ROTATION_SOURCE_USER); 549 display::Display::RotationSource::ROTATION_SOURCE_USER);
541 WaitForCopyCallback(); 550 WaitForCopyCallback();
542 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 551 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
543 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 552 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
544 } 553 }
545 554
555 // If the external primary display is removed during a rotation animation. It
556 // should work for the next rotation request even the |root_window| changed.
557 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
558 RemoveExternalPrimaryDisplayDuringAnimationChangedRootWindow) {
559 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
560 if (Shell::GetAshConfig() == Config::MASH) {
561 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
562 display_id());
563 return;
564 }
565
566 UpdateDisplay("640x480,800x600");
567 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
568
569 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
570 display_manager()->GetDisplayAt(1).id());
571 const unsigned int secondary_display_id =
572 display_manager()->GetDisplayAt(0).id();
573 aura::Window* old_root_window = GetRootWindow(secondary_display_id);
574
575 SetScreenRotationAnimator(
576 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(),
577 base::Bind(
578 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
579 base::Unretained(this), "640x480"));
580 SetDisplayRotation(display_manager()->GetDisplayAt(0).id(),
581 display::Display::ROTATE_0);
582 animator()->Rotate(display::Display::ROTATE_90,
583 display::Display::RotationSource::ROTATION_SOURCE_USER);
584 WaitForCopyCallback();
585 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
586 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
587
588 // Rotate again, should finish.
589 animator()->set_intersect_after_callback(base::Bind(
590 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
591 base::Unretained(this)));
592 animator()->Rotate(display::Display::ROTATE_270,
593 display::Display::RotationSource::ROTATION_SOURCE_USER);
594 WaitForCopyCallback();
595 EXPECT_EQ(display::Display::ROTATE_270,
596 GetDisplayRotation(secondary_display_id));
597 aura::Window* new_root_window = GetRootWindow(secondary_display_id);
598 EXPECT_NE(old_root_window, new_root_window);
599 }
600
546 } // namespace ash 601 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698