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

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

Issue 2919393002: [merge to m60] 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(aura::Window* root_window,
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
69 private: 74 private:
70 CopyCallback CreateAfterCopyCallbackBeforeRotation( 75 CopyCallback CreateAfterCopyCallbackBeforeRotation(
71 std::unique_ptr<ScreenRotationRequest> rotation_request) override; 76 std::unique_ptr<ScreenRotationRequest> rotation_request) override;
72 CopyCallback CreateAfterCopyCallbackAfterRotation( 77 CopyCallback CreateAfterCopyCallbackAfterRotation(
73 std::unique_ptr<ScreenRotationRequest> rotation_request) override; 78 std::unique_ptr<ScreenRotationRequest> rotation_request) override;
74 79
75 void IntersectBefore(CopyCallback next_callback, 80 void IntersectBefore(CopyCallback next_callback,
76 std::unique_ptr<cc::CopyOutputResult> result); 81 std::unique_ptr<cc::CopyOutputResult> result);
77 void IntersectAfter(CopyCallback next_callback, 82 void IntersectAfter(CopyCallback next_callback,
78 std::unique_ptr<cc::CopyOutputResult> result); 83 std::unique_ptr<cc::CopyOutputResult> result);
79 84
80 base::Closure intersect_before_callback_; 85 base::Closure intersect_before_callback_;
81 base::Closure intersect_after_callback_; 86 base::Closure intersect_after_callback_;
82 87
83 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); 88 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator);
84 }; 89 };
85 90
86 TestScreenRotationAnimator::TestScreenRotationAnimator( 91 TestScreenRotationAnimator::TestScreenRotationAnimator(
87 int64_t display_id, 92 aura::Window* root_window,
88 const base::Closure& before_callback, 93 const base::Closure& before_callback,
89 const base::Closure& after_callback) 94 const base::Closure& after_callback)
90 : ScreenRotationAnimator(display_id), 95 : ScreenRotationAnimator(root_window),
91 intersect_before_callback_(before_callback), 96 intersect_before_callback_(before_callback),
92 intersect_after_callback_(after_callback) {} 97 intersect_after_callback_(after_callback) {}
93 98
94 ScreenRotationAnimator::CopyCallback 99 ScreenRotationAnimator::CopyCallback
95 TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( 100 TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation(
96 std::unique_ptr<ScreenRotationRequest> rotation_request) { 101 std::unique_ptr<ScreenRotationRequest> rotation_request) {
97 CopyCallback next_callback = 102 CopyCallback next_callback =
98 ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( 103 ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation(
99 std::move(rotation_request)); 104 std::move(rotation_request));
100 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, 105 return base::Bind(&TestScreenRotationAnimator::IntersectBefore,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void ScreenRotationAnimatorSlowAnimationTest::SetUp() { 162 void ScreenRotationAnimatorSlowAnimationTest::SetUp() {
158 AshTestBase::SetUp(); 163 AshTestBase::SetUp();
159 164
160 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); 165 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
161 if (Shell::GetAshConfig() == Config::MASH) { 166 if (Shell::GetAshConfig() == Config::MASH) {
162 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 167 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
163 display_id()); 168 display_id());
164 return; 169 return;
165 } 170 }
166 171
167 animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id()); 172 animator_ =
173 base::MakeUnique<ScreenRotationAnimator>(GetRootWindow(display_.id()));
168 test_api_ = 174 test_api_ =
169 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); 175 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
170 test_api()->DisableAnimationTimers(); 176 test_api()->DisableAnimationTimers();
171 non_zero_duration_mode_ = 177 non_zero_duration_mode_ =
172 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( 178 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
173 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 179 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
174 } 180 }
175 181
176 class ScreenRotationAnimatorSmoothAnimationTest : public test::AshTestBase { 182 class ScreenRotationAnimatorSmoothAnimationTest : public test::AshTestBase {
177 public: 183 public:
178 ScreenRotationAnimatorSmoothAnimationTest() {} 184 ScreenRotationAnimatorSmoothAnimationTest() {}
179 ~ScreenRotationAnimatorSmoothAnimationTest() override {} 185 ~ScreenRotationAnimatorSmoothAnimationTest() override {}
180 186
181 // AshTestBase: 187 // AshTestBase:
182 void SetUp() override; 188 void SetUp() override;
183 189
184 void RemoveSecondaryDisplay(const std::string& specs); 190 void RemoveSecondaryDisplay(const std::string& specs);
185 void QuitWaitForCopyCallback(); 191 void QuitWaitForCopyCallback();
186 192
187 protected: 193 protected:
188 int64_t display_id() const { return display_.id(); } 194 int64_t display_id() const { return display_.id(); }
189 195
190 TestScreenRotationAnimator* animator() { return animator_.get(); } 196 TestScreenRotationAnimator* animator() { return animator_.get(); }
191 197
192 void SetScreenRotationAnimator(int64_t display_id, 198 void SetScreenRotationAnimator(aura::Window* root_window,
193 const base::Closure& before_callback, 199 const base::Closure& before_callback,
194 const base::Closure& after_callback); 200 const base::Closure& after_callback);
195 201
196 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } 202 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); }
197 203
198 void WaitForCopyCallback(); 204 void WaitForCopyCallback();
199 205
200 std::unique_ptr<base::RunLoop> run_loop_; 206 std::unique_ptr<base::RunLoop> run_loop_;
201 207
202 private: 208 private:
(...skipping 26 matching lines...) Expand all
229 ash_test_helper()->reset_commandline(); 235 ash_test_helper()->reset_commandline();
230 236
231 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); 237 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
232 if (Shell::GetAshConfig() == Config::MASH) { 238 if (Shell::GetAshConfig() == Config::MASH) {
233 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 239 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
234 display_id()); 240 display_id());
235 return; 241 return;
236 } 242 }
237 243
238 run_loop_ = base::MakeUnique<base::RunLoop>(); 244 run_loop_ = base::MakeUnique<base::RunLoop>();
239 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure(), 245 SetScreenRotationAnimator(GetRootWindow(display_.id()),
246 run_loop_->QuitWhenIdleClosure(),
240 run_loop_->QuitWhenIdleClosure()); 247 run_loop_->QuitWhenIdleClosure());
241 non_zero_duration_mode_ = 248 non_zero_duration_mode_ =
242 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( 249 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
243 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 250 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
244 } 251 }
245 252
246 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator( 253 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator(
247 int64_t display_id, 254 aura::Window* root_window,
248 const base::Closure& before_callback, 255 const base::Closure& before_callback,
249 const base::Closure& after_callback) { 256 const base::Closure& after_callback) {
250 animator_ = base::MakeUnique<TestScreenRotationAnimator>( 257 animator_ = base::MakeUnique<TestScreenRotationAnimator>(
251 display_id, before_callback, after_callback); 258 root_window, before_callback, after_callback);
252 test_api_ = 259 test_api_ =
253 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); 260 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
254 test_api()->DisableAnimationTimers(); 261 test_api()->DisableAnimationTimers();
255 } 262 }
256 263
257 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() { 264 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() {
258 run_loop_.reset(new base::RunLoop()); 265 run_loop_.reset(new base::RunLoop());
259 run_loop_->Run(); 266 run_loop_->Run();
260 } 267 }
261 268
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // Test enable smooth screen rotation code path. 402 // Test enable smooth screen rotation code path.
396 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 403 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
397 RotatesToDifferentRotationWithCopyCallback) { 404 RotatesToDifferentRotationWithCopyCallback) {
398 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 405 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
399 if (Shell::GetAshConfig() == Config::MASH) { 406 if (Shell::GetAshConfig() == Config::MASH) {
400 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 407 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
401 display_id()); 408 display_id());
402 return; 409 return;
403 } 410 }
404 411
412 const int64_t display_id = display_manager()->GetDisplayAt(0).id();
405 SetScreenRotationAnimator( 413 SetScreenRotationAnimator(
406 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(), 414 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(),
407 base::Bind( 415 base::Bind(
408 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, 416 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
409 base::Unretained(this))); 417 base::Unretained(this)));
410 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 418 SetDisplayRotation(display_id, display::Display::ROTATE_0);
411 animator()->Rotate(display::Display::ROTATE_90, 419 animator()->Rotate(display::Display::ROTATE_90,
412 display::Display::RotationSource::ROTATION_SOURCE_USER); 420 display::Display::RotationSource::ROTATION_SOURCE_USER);
413 WaitForCopyCallback(); 421 WaitForCopyCallback();
414 EXPECT_TRUE(test_api()->HasActiveAnimations()); 422 EXPECT_TRUE(test_api()->HasActiveAnimations());
415 423
416 test_api()->CompleteAnimations(); 424 test_api()->CompleteAnimations();
417 EXPECT_FALSE(test_api()->HasActiveAnimations()); 425 EXPECT_FALSE(test_api()->HasActiveAnimations());
426 EXPECT_EQ(display::Display::ROTATE_90, GetDisplayRotation(display_id));
418 } 427 }
419 428
420 // If the external secondary display is removed before the first copy request 429 // If the rotating external secondary display is removed before the first copy
421 // callback called, it should not crash. 430 // request callback called, it should stop rotating.
422 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 431 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
423 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) { 432 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) {
424 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 433 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
425 if (Shell::GetAshConfig() == Config::MASH) { 434 if (Shell::GetAshConfig() == Config::MASH) {
426 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 435 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
427 display_id()); 436 display_id());
428 return; 437 return;
429 } 438 }
430 439
431 UpdateDisplay("640x480,800x600"); 440 UpdateDisplay("640x480,800x600");
432 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 441 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
433 442
434 const unsigned int primary_display_id = 443 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
435 display_manager()->GetDisplayAt(0).id(); 444 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
445
436 SetScreenRotationAnimator( 446 SetScreenRotationAnimator(
437 display_manager()->GetDisplayAt(1).id(), 447 GetRootWindow(secondary_display_id),
438 base::Bind( 448 base::Bind(
439 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 449 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
440 base::Unretained(this), "640x480"), 450 base::Unretained(this), "640x480"),
441 run_loop_->QuitWhenIdleClosure()); 451 run_loop_->QuitWhenIdleClosure());
442 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 452 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
443 display::Display::ROTATE_0);
444 animator()->Rotate(display::Display::ROTATE_90, 453 animator()->Rotate(display::Display::ROTATE_90,
445 display::Display::RotationSource::ROTATION_SOURCE_USER); 454 display::Display::RotationSource::ROTATION_SOURCE_USER);
446 WaitForCopyCallback(); 455 WaitForCopyCallback();
447 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 456 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
448 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); 457 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
449 } 458 }
450 459
451 // If the external primary display is removed before the first copy request 460 // If the rotating external primary display is removed before the first copy
452 // callback called, it should not crash. 461 // request callback called, it should stop rotating.
453 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 462 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
454 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) { 463 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) {
455 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 464 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
456 if (Shell::GetAshConfig() == Config::MASH) { 465 if (Shell::GetAshConfig() == Config::MASH) {
457 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 466 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
458 display_id()); 467 display_id());
459 return; 468 return;
460 } 469 }
461 470
462 UpdateDisplay("640x480,800x600"); 471 UpdateDisplay("640x480,800x600");
463 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 472 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
464 473
465 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( 474 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
466 display_manager()->GetDisplayAt(1).id()); 475 display_manager()->GetDisplayAt(1).id());
467 const unsigned int secondary_display_id = 476 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id();
468 display_manager()->GetDisplayAt(0).id(); 477 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
469 SetScreenRotationAnimator( 478 SetScreenRotationAnimator(
470 display_manager()->GetDisplayAt(1).id(), 479 GetRootWindow(primary_display_id),
471 base::Bind( 480 base::Bind(
472 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 481 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
473 base::Unretained(this), "640x480"), 482 base::Unretained(this), "640x480"),
474 run_loop_->QuitWhenIdleClosure()); 483 run_loop_->QuitWhenIdleClosure());
475 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 484 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0);
476 display::Display::ROTATE_0);
477 animator()->Rotate(display::Display::ROTATE_90, 485 animator()->Rotate(display::Display::ROTATE_90,
478 display::Display::RotationSource::ROTATION_SOURCE_USER); 486 display::Display::RotationSource::ROTATION_SOURCE_USER);
479 WaitForCopyCallback(); 487 WaitForCopyCallback();
480 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 488 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
481 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 489 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
482 } 490 }
483 491
484 // If the external secondary display is removed before the second copy request 492 // If the rotating external secondary display is removed before the second copy
485 // callback called, it should not crash. 493 // request callback called, it should stop rotating.
486 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 494 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
487 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) { 495 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) {
488 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 496 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
489 if (Shell::GetAshConfig() == Config::MASH) { 497 if (Shell::GetAshConfig() == Config::MASH) {
490 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 498 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
491 display_id()); 499 display_id());
492 return; 500 return;
493 } 501 }
494 502
495 UpdateDisplay("640x480,800x600"); 503 UpdateDisplay("640x480,800x600");
496 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 504 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
497 505
498 const unsigned int primary_display_id = 506 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
499 display_manager()->GetDisplayAt(0).id(); 507 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
500 SetScreenRotationAnimator( 508 SetScreenRotationAnimator(
501 display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(), 509 GetRootWindow(secondary_display_id), run_loop_->QuitWhenIdleClosure(),
502 base::Bind( 510 base::Bind(
503 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 511 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
504 base::Unretained(this), "640x480")); 512 base::Unretained(this), "640x480"));
505 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 513 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
506 display::Display::ROTATE_0);
507 animator()->Rotate(display::Display::ROTATE_90, 514 animator()->Rotate(display::Display::ROTATE_90,
508 display::Display::RotationSource::ROTATION_SOURCE_USER); 515 display::Display::RotationSource::ROTATION_SOURCE_USER);
509 WaitForCopyCallback(); 516 WaitForCopyCallback();
510 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 517 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
511 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); 518 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
512 } 519 }
513 520
514 // If the external primary display is removed before the second copy request 521 // If the rotating external primary display is removed before the second copy
515 // callback called, it should not crash. 522 // request callback called, it should stop rotating.
516 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, 523 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
517 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) { 524 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) {
518 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 525 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
519 if (Shell::GetAshConfig() == Config::MASH) { 526 if (Shell::GetAshConfig() == Config::MASH) {
520 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != 527 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
521 display_id()); 528 display_id());
522 return; 529 return;
523 } 530 }
524 531
525 UpdateDisplay("640x480,800x600"); 532 UpdateDisplay("640x480,800x600");
526 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); 533 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
527 534
528 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( 535 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
529 display_manager()->GetDisplayAt(1).id()); 536 display_manager()->GetDisplayAt(1).id());
530 const unsigned int secondary_display_id = 537 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id();
531 display_manager()->GetDisplayAt(0).id(); 538 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
532 SetScreenRotationAnimator( 539 SetScreenRotationAnimator(
533 display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(), 540 GetRootWindow(primary_display_id), run_loop_->QuitWhenIdleClosure(),
534 base::Bind( 541 base::Bind(
535 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, 542 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
536 base::Unretained(this), "640x480")); 543 base::Unretained(this), "640x480"));
537 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), 544 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0);
538 display::Display::ROTATE_0);
539 animator()->Rotate(display::Display::ROTATE_90, 545 animator()->Rotate(display::Display::ROTATE_90,
540 display::Display::RotationSource::ROTATION_SOURCE_USER); 546 display::Display::RotationSource::ROTATION_SOURCE_USER);
541 WaitForCopyCallback(); 547 WaitForCopyCallback();
542 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); 548 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
543 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); 549 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
544 } 550 }
545 551
552 // If the external primary display is removed while rotating the secondary
553 // display. It should stop rotating the secondary display because the
554 // |root_window| changed.
555 TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
556 RemoveExternalPrimaryDisplayDuringAnimationChangedRootWindow) {
557 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
558 if (Shell::GetAshConfig() == Config::MASH) {
559 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
560 display_id());
561 return;
562 }
563
564 UpdateDisplay("640x480,800x600");
565 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
566
567 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
568 display_manager()->GetDisplayAt(1).id());
569 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
570 SetScreenRotationAnimator(
571 GetRootWindow(secondary_display_id),
572 base::Bind(
573 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
574 base::Unretained(this), "640x480"),
575 run_loop_->QuitWhenIdleClosure());
576 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
577 animator()->Rotate(display::Display::ROTATE_90,
578 display::Display::RotationSource::ROTATION_SOURCE_USER);
579 WaitForCopyCallback();
580 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
581 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
582 EXPECT_EQ(display::Display::ROTATE_0,
583 GetDisplayRotation(secondary_display_id));
584 }
585
546 } // namespace ash 586 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | ash/test/display_configuration_controller_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698