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

Side by Side Diff: ash/display/window_tree_host_manager_unittest.cc

Issue 2355063002: Separate ash::test::DisplayManagerTestApi from ash (Closed)
Patch Set: review comment Created 4 years, 2 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/display/window_tree_host_manager.cc ('k') | ash/extended_desktop_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/display/window_tree_host_manager.h" 5 #include "ash/display/window_tree_host_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/aura/wm_window_aura.h" 9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 display::Display GetPrimaryDisplay() { 184 display::Display GetPrimaryDisplay() {
185 return display::Screen::GetScreen()->GetDisplayNearestWindow( 185 return display::Screen::GetScreen()->GetDisplayNearestWindow(
186 Shell::GetAllRootWindows()[0]); 186 Shell::GetAllRootWindows()[0]);
187 } 187 }
188 188
189 display::Display GetSecondaryDisplay() { 189 display::Display GetSecondaryDisplay() {
190 return display::Screen::GetScreen()->GetDisplayNearestWindow( 190 return display::Screen::GetScreen()->GetDisplayNearestWindow(
191 Shell::GetAllRootWindows()[1]); 191 Shell::GetAllRootWindows()[1]);
192 } 192 }
193 193
194 void SetSecondaryDisplayLayoutAndOffset( 194 class TestHelper {
195 public:
196 explicit TestHelper(test::AshTestBase* delegate);
197 ~TestHelper();
198
199 void SetSecondaryDisplayLayoutAndOffset(
200 display::DisplayPlacement::Position position,
201 int offset);
202
203 void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position);
204
205 void SetDefaultDisplayLayout(display::DisplayPlacement::Position position);
206
207 float GetStoredUIScale(int64_t id);
208
209 private:
210 test::AshTestBase* delegate_; // Not owned
211 DISALLOW_COPY_AND_ASSIGN(TestHelper);
212 };
213
214 TestHelper::TestHelper(test::AshTestBase* delegate) : delegate_(delegate) {}
215 TestHelper::~TestHelper() {}
216
217 void TestHelper::SetSecondaryDisplayLayoutAndOffset(
195 display::DisplayPlacement::Position position, 218 display::DisplayPlacement::Position position,
196 int offset) { 219 int offset) {
197 std::unique_ptr<display::DisplayLayout> layout( 220 std::unique_ptr<display::DisplayLayout> layout(test::CreateDisplayLayout(
198 test::CreateDisplayLayout(position, offset)); 221 delegate_->display_manager(), position, offset));
199 ASSERT_GT(display::Screen::GetScreen()->GetNumDisplays(), 1); 222 ASSERT_GT(display::Screen::GetScreen()->GetNumDisplays(), 1);
200 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 223 delegate_->display_manager()->SetLayoutForCurrentDisplays(std::move(layout));
201 std::move(layout));
202 } 224 }
203 225
204 void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) { 226 void TestHelper::SetSecondaryDisplayLayout(
227 display::DisplayPlacement::Position position) {
205 SetSecondaryDisplayLayoutAndOffset(position, 0); 228 SetSecondaryDisplayLayoutAndOffset(position, 0);
206 } 229 }
207 230
208 void SetDefaultDisplayLayout(display::DisplayPlacement::Position position) { 231 void TestHelper::SetDefaultDisplayLayout(
232 display::DisplayPlacement::Position position) {
209 display::DisplayPlacement default_placement(position, 0); 233 display::DisplayPlacement default_placement(position, 0);
210 234 delegate_->display_manager()->layout_store()->SetDefaultDisplayPlacement(
211 Shell::GetInstance() 235 default_placement);
212 ->display_manager()
213 ->layout_store()
214 ->SetDefaultDisplayPlacement(default_placement);
215 } 236 }
216 237
217 class WindowTreeHostManagerShutdownTest : public test::AshTestBase { 238 float TestHelper::GetStoredUIScale(int64_t id) {
239 return delegate_->display_manager()->GetDisplayInfo(id).GetEffectiveUIScale();
240 }
241
242 class WindowTreeHostManagerShutdownTest : public test::AshTestBase,
243 public TestHelper {
218 public: 244 public:
219 WindowTreeHostManagerShutdownTest() {} 245 WindowTreeHostManagerShutdownTest() : TestHelper(this) {}
220 ~WindowTreeHostManagerShutdownTest() override {} 246 ~WindowTreeHostManagerShutdownTest() override {}
221 247
222 void TearDown() override { 248 void TearDown() override {
223 test::AshTestBase::TearDown(); 249 test::AshTestBase::TearDown();
224 if (!SupportsMultipleDisplays()) 250 if (!SupportsMultipleDisplays())
225 return; 251 return;
226 252
227 // Make sure that primary display is accessible after shutdown. 253 // Make sure that primary display is accessible after shutdown.
228 display::Display primary = 254 display::Display primary =
229 display::Screen::GetScreen()->GetPrimaryDisplay(); 255 display::Screen::GetScreen()->GetPrimaryDisplay();
(...skipping 23 matching lines...) Expand all
253 } 279 }
254 280
255 bool displays_initialized() const { return displays_initialized_; } 281 bool displays_initialized() const { return displays_initialized_; }
256 282
257 private: 283 private:
258 bool displays_initialized_; 284 bool displays_initialized_;
259 285
260 DISALLOW_COPY_AND_ASSIGN(StartupHelper); 286 DISALLOW_COPY_AND_ASSIGN(StartupHelper);
261 }; 287 };
262 288
263 class WindowTreeHostManagerStartupTest : public test::AshTestBase { 289 class WindowTreeHostManagerStartupTest : public test::AshTestBase,
290 public TestHelper {
264 public: 291 public:
265 WindowTreeHostManagerStartupTest() : startup_helper_(new StartupHelper) {} 292 WindowTreeHostManagerStartupTest()
293 : TestHelper(this), startup_helper_(new StartupHelper) {}
266 ~WindowTreeHostManagerStartupTest() override {} 294 ~WindowTreeHostManagerStartupTest() override {}
267 295
268 // ash::test::AshTestBase: 296 // ash::test::AshTestBase:
269 void SetUp() override { 297 void SetUp() override {
270 ash_test_helper()->set_test_shell_delegate(startup_helper_); 298 ash_test_helper()->set_test_shell_delegate(startup_helper_);
271 test::AshTestBase::SetUp(); 299 test::AshTestBase::SetUp();
272 } 300 }
273 void TearDown() override { 301 void TearDown() override {
274 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver( 302 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(
275 startup_helper_); 303 startup_helper_);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 float touch_radius_x_; 384 float touch_radius_x_;
357 float touch_radius_y_; 385 float touch_radius_y_;
358 float scroll_x_offset_; 386 float scroll_x_offset_;
359 float scroll_y_offset_; 387 float scroll_y_offset_;
360 float scroll_x_offset_ordinal_; 388 float scroll_x_offset_ordinal_;
361 float scroll_y_offset_ordinal_; 389 float scroll_y_offset_ordinal_;
362 390
363 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 391 DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
364 }; 392 };
365 393
366 float GetStoredUIScale(int64_t id) {
367 return Shell::GetInstance()
368 ->display_manager()
369 ->GetDisplayInfo(id)
370 .GetEffectiveUIScale();
371 }
372 394
373 class TestMouseWatcherListener : public views::MouseWatcherListener { 395 class TestMouseWatcherListener : public views::MouseWatcherListener {
374 public: 396 public:
375 TestMouseWatcherListener() {} 397 TestMouseWatcherListener() {}
376 398
377 private: 399 private:
378 // views::MouseWatcherListener: 400 // views::MouseWatcherListener:
379 void MouseMovedOutOfHost() override {} 401 void MouseMovedOutOfHost() override {}
380 402
381 DISALLOW_COPY_AND_ASSIGN(TestMouseWatcherListener); 403 DISALLOW_COPY_AND_ASSIGN(TestMouseWatcherListener);
382 }; 404 };
383 405
384 } // namespace 406 } // namespace
385 407
386 using WindowTreeHostManagerTest = test::AshMDTestBase; 408 class WindowTreeHostManagerTest : public test::AshMDTestBase,
409 public TestHelper {
410 public:
411 WindowTreeHostManagerTest() : TestHelper(this){};
412 ~WindowTreeHostManagerTest() override{};
413
414 private:
415 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostManagerTest);
416 };
387 417
388 INSTANTIATE_TEST_CASE_P( 418 INSTANTIATE_TEST_CASE_P(
389 /* prefix intentionally left blank due to only one parameterization */, 419 /* prefix intentionally left blank due to only one parameterization */,
390 WindowTreeHostManagerTest, 420 WindowTreeHostManagerTest,
391 testing::Values(MaterialDesignController::NON_MATERIAL, 421 testing::Values(MaterialDesignController::NON_MATERIAL,
392 MaterialDesignController::MATERIAL_NORMAL, 422 MaterialDesignController::MATERIAL_NORMAL,
393 MaterialDesignController::MATERIAL_EXPERIMENTAL)); 423 MaterialDesignController::MATERIAL_EXPERIMENTAL));
394 424
395 TEST_F(WindowTreeHostManagerShutdownTest, Shutdown) { 425 TEST_F(WindowTreeHostManagerShutdownTest, Shutdown) {
396 if (!SupportsMultipleDisplays()) 426 if (!SupportsMultipleDisplays())
(...skipping 18 matching lines...) Expand all
415 w1->Focus(); 445 w1->Focus();
416 446
417 TestObserver observer; 447 TestObserver observer;
418 UpdateDisplay("500x500,400x400"); 448 UpdateDisplay("500x500,400x400");
419 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 449 EXPECT_EQ(1, observer.CountAndReset()); // resize and add
420 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 450 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
421 EXPECT_EQ(2, observer.GetWorkareaChangedCountAndReset()); 451 EXPECT_EQ(2, observer.GetWorkareaChangedCountAndReset());
422 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 452 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
423 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 453 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
424 gfx::Insets insets(5, 5, 5, 5); 454 gfx::Insets insets(5, 5, 5, 5);
425 int64_t secondary_display_id = ScreenUtil::GetSecondaryDisplay().id(); 455 int64_t secondary_display_id = display_manager()->GetSecondaryDisplay().id();
426 Shell::GetInstance()->display_manager()->UpdateWorkAreaOfDisplay( 456 display_manager()->UpdateWorkAreaOfDisplay(secondary_display_id, insets);
427 secondary_display_id, insets);
428 457
429 // Default layout is RIGHT. 458 // Default layout is RIGHT.
430 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 459 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
431 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); 460 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString());
432 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); 461 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString());
433 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 462 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
434 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 463 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
435 464
436 // Layout the secondary display to the bottom of the primary. 465 // Layout the secondary display to the bottom of the primary.
437 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); 466 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 603
575 TEST_P(WindowTreeHostManagerTest, MirrorToDockedWithFullscreen) { 604 TEST_P(WindowTreeHostManagerTest, MirrorToDockedWithFullscreen) {
576 if (!SupportsMultipleDisplays()) 605 if (!SupportsMultipleDisplays())
577 return; 606 return;
578 607
579 // Creates windows to catch activation change event. 608 // Creates windows to catch activation change event.
580 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1)); 609 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1));
581 w1->Focus(); 610 w1->Focus();
582 611
583 // Docked mode. 612 // Docked mode.
584 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
585 613
586 const display::ManagedDisplayInfo internal_display_info = 614 const display::ManagedDisplayInfo internal_display_info =
587 CreateMirroredDisplayInfo(1, 2.0f); 615 CreateMirroredDisplayInfo(1, 2.0f);
588 const display::ManagedDisplayInfo external_display_info = 616 const display::ManagedDisplayInfo external_display_info =
589 CreateMirroredDisplayInfo(2, 1.0f); 617 CreateMirroredDisplayInfo(2, 1.0f);
590 618
591 std::vector<display::ManagedDisplayInfo> display_info_list; 619 std::vector<display::ManagedDisplayInfo> display_info_list;
592 // Mirror. 620 // Mirror.
593 display_info_list.push_back(internal_display_info); 621 display_info_list.push_back(internal_display_info);
594 display_info_list.push_back(external_display_info); 622 display_info_list.push_back(external_display_info);
595 display_manager->OnNativeDisplaysChanged(display_info_list); 623 display_manager()->OnNativeDisplaysChanged(display_info_list);
596 const int64_t internal_display_id = 624 const int64_t internal_display_id =
597 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); 625 test::DisplayManagerTestApi(display_manager())
626 .SetFirstDisplayAsInternalDisplay();
598 EXPECT_EQ(1, internal_display_id); 627 EXPECT_EQ(1, internal_display_id);
599 EXPECT_EQ(2U, display_manager->num_connected_displays()); 628 EXPECT_EQ(2U, display_manager()->num_connected_displays());
600 EXPECT_EQ(1U, display_manager->GetNumDisplays()); 629 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
601 630
602 wm::WindowState* window_state = wm::GetWindowState(w1.get()); 631 wm::WindowState* window_state = wm::GetWindowState(w1.get());
603 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 632 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
604 window_state->OnWMEvent(&toggle_fullscreen_event); 633 window_state->OnWMEvent(&toggle_fullscreen_event);
605 EXPECT_TRUE(window_state->IsFullscreen()); 634 EXPECT_TRUE(window_state->IsFullscreen());
606 EXPECT_EQ("0,0 250x250", w1->bounds().ToString()); 635 EXPECT_EQ("0,0 250x250", w1->bounds().ToString());
607 // Dock mode. 636 // Dock mode.
608 TestObserver observer; 637 TestObserver observer;
609 display_info_list.clear(); 638 display_info_list.clear();
610 display_info_list.push_back(external_display_info); 639 display_info_list.push_back(external_display_info);
611 display_manager->OnNativeDisplaysChanged(display_info_list); 640 display_manager()->OnNativeDisplaysChanged(display_info_list);
612 EXPECT_EQ(1U, display_manager->GetNumDisplays()); 641 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
613 EXPECT_EQ(1U, display_manager->num_connected_displays()); 642 EXPECT_EQ(1U, display_manager()->num_connected_displays());
614 // Observers are called due to primary change. 643 // Observers are called due to primary change.
615 EXPECT_EQ(2, observer.GetChangedDisplayIdAndReset()); 644 EXPECT_EQ(2, observer.GetChangedDisplayIdAndReset());
616 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 645 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
617 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); 646 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
618 EXPECT_EQ(1, observer.GetPrimaryChangedCountAndReset()); 647 EXPECT_EQ(1, observer.GetPrimaryChangedCountAndReset());
619 EXPECT_EQ(1, observer.CountAndReset()); 648 EXPECT_EQ(1, observer.CountAndReset());
620 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 649 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
621 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 650 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
622 651
623 EXPECT_TRUE(window_state->IsFullscreen()); 652 EXPECT_TRUE(window_state->IsFullscreen());
624 EXPECT_EQ("0,0 500x500", w1->bounds().ToString()); 653 EXPECT_EQ("0,0 500x500", w1->bounds().ToString());
625 } 654 }
626 655
627 TEST_P(WindowTreeHostManagerTest, BoundsUpdated) { 656 TEST_P(WindowTreeHostManagerTest, BoundsUpdated) {
628 if (!SupportsMultipleDisplays()) 657 if (!SupportsMultipleDisplays())
629 return; 658 return;
630 659
631 // Creates windows to catch activation change event. 660 // Creates windows to catch activation change event.
632 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1)); 661 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1));
633 w1->Focus(); 662 w1->Focus();
634 663
635 TestObserver observer; 664 TestObserver observer;
636 SetDefaultDisplayLayout(display::DisplayPlacement::BOTTOM); 665 SetDefaultDisplayLayout(display::DisplayPlacement::BOTTOM);
637 UpdateDisplay("200x200,300x300"); // layout, resize and add. 666 UpdateDisplay("200x200,300x300"); // layout, resize and add.
638 EXPECT_EQ(1, observer.CountAndReset()); 667 EXPECT_EQ(1, observer.CountAndReset());
639 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 668 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
640 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 669 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
641 670
642 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
643 gfx::Insets insets(5, 5, 5, 5); 671 gfx::Insets insets(5, 5, 5, 5);
644 display_manager->UpdateWorkAreaOfDisplay( 672 display_manager()->UpdateWorkAreaOfDisplay(GetSecondaryDisplay().id(),
645 ScreenUtil::GetSecondaryDisplay().id(), insets); 673 insets);
646 674
647 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); 675 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString());
648 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); 676 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString());
649 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); 677 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString());
650 678
651 UpdateDisplay("400x400,200x200"); 679 UpdateDisplay("400x400,200x200");
652 EXPECT_EQ(1, observer.CountAndReset()); // two resizes 680 EXPECT_EQ(1, observer.CountAndReset()); // two resizes
653 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 681 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
654 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 682 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
655 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 683 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
(...skipping 24 matching lines...) Expand all
680 // No change 708 // No change
681 UpdateDisplay("400x500*2,300x300"); 709 UpdateDisplay("400x500*2,300x300");
682 // We still call into Pre/PostDisplayConfigurationChange(). 710 // We still call into Pre/PostDisplayConfigurationChange().
683 EXPECT_EQ(1, observer.CountAndReset()); 711 EXPECT_EQ(1, observer.CountAndReset());
684 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 712 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
685 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 713 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
686 714
687 // Rotation 715 // Rotation
688 observer.GetRotationChangedCountAndReset(); // we only want to reset. 716 observer.GetRotationChangedCountAndReset(); // we only want to reset.
689 int64_t primary_id = GetPrimaryDisplay().id(); 717 int64_t primary_id = GetPrimaryDisplay().id();
690 display_manager->SetDisplayRotation(primary_id, display::Display::ROTATE_90, 718 display_manager()->SetDisplayRotation(
691 display::Display::ROTATION_SOURCE_ACTIVE); 719 primary_id, display::Display::ROTATE_90,
720 display::Display::ROTATION_SOURCE_ACTIVE);
692 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); 721 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
693 EXPECT_EQ(1, observer.CountAndReset()); 722 EXPECT_EQ(1, observer.CountAndReset());
694 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 723 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
695 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 724 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
696 display_manager->SetDisplayRotation(primary_id, display::Display::ROTATE_90, 725 display_manager()->SetDisplayRotation(
697 display::Display::ROTATION_SOURCE_ACTIVE); 726 primary_id, display::Display::ROTATE_90,
727 display::Display::ROTATION_SOURCE_ACTIVE);
698 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); 728 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset());
699 EXPECT_EQ(0, observer.CountAndReset()); 729 EXPECT_EQ(0, observer.CountAndReset());
700 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 730 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
701 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 731 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
702 732
703 // UI scale is eanbled only on internal display. 733 // UI scale is eanbled only on internal display.
704 int64_t secondary_id = GetSecondaryDisplay().id(); 734 int64_t secondary_id = GetSecondaryDisplay().id();
705 test::ScopedSetInternalDisplayId set_internal(secondary_id); 735 test::ScopedSetInternalDisplayId set_internal(display_manager(),
736 secondary_id);
706 // Changing internal ID display changes the DisplayIdPair (it comes 737 // Changing internal ID display changes the DisplayIdPair (it comes
707 // first), which also changes the primary display candidate. Update 738 // first), which also changes the primary display candidate. Update
708 // the primary display manually to update the primary display to 739 // the primary display manually to update the primary display to
709 // avoid getting the OnDisplayConfigurationChanged() call twice in 740 // avoid getting the OnDisplayConfigurationChanged() call twice in
710 // SetDisplayUIScale. Note that this scenario will never happen on 741 // SetDisplayUIScale. Note that this scenario will never happen on
711 // real devices. 742 // real devices.
712 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId( 743 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId(
713 secondary_id); 744 secondary_id);
714 EXPECT_EQ(1, observer.CountAndReset()); 745 EXPECT_EQ(1, observer.CountAndReset());
715 746
716 Shell::GetInstance()->display_manager()->SetDisplayUIScale(secondary_id, 747 display_manager()->SetDisplayUIScale(secondary_id, 1.125f);
717 1.125f);
718 EXPECT_EQ(1, observer.CountAndReset()); 748 EXPECT_EQ(1, observer.CountAndReset());
719 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 749 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
720 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 750 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
721 Shell::GetInstance()->display_manager()->SetDisplayUIScale(secondary_id, 751 display_manager()->SetDisplayUIScale(secondary_id, 1.125f);
722 1.125f);
723 EXPECT_EQ(0, observer.CountAndReset()); 752 EXPECT_EQ(0, observer.CountAndReset());
724 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 753 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
725 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 754 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
726 Shell::GetInstance()->display_manager()->SetDisplayUIScale(primary_id, 755 display_manager()->SetDisplayUIScale(primary_id, 1.125f);
727 1.125f);
728 EXPECT_EQ(0, observer.CountAndReset()); 756 EXPECT_EQ(0, observer.CountAndReset());
729 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 757 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
730 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 758 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
731 Shell::GetInstance()->display_manager()->SetDisplayUIScale(primary_id, 759 display_manager()->SetDisplayUIScale(primary_id, 1.125f);
732 1.125f);
733 EXPECT_EQ(0, observer.CountAndReset()); 760 EXPECT_EQ(0, observer.CountAndReset());
734 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); 761 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
735 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); 762 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
736 } 763 }
737 764
738 TEST_P(WindowTreeHostManagerTest, FindNearestDisplay) { 765 TEST_P(WindowTreeHostManagerTest, FindNearestDisplay) {
739 if (!SupportsMultipleDisplays()) 766 if (!SupportsMultipleDisplays())
740 return; 767 return;
741 768
742 WindowTreeHostManager* window_tree_host_manager = 769 WindowTreeHostManager* window_tree_host_manager =
743 Shell::GetInstance()->window_tree_host_manager(); 770 Shell::GetInstance()->window_tree_host_manager();
744 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
745 771
746 UpdateDisplay("200x200,300x300"); 772 UpdateDisplay("200x200,300x300");
747 display_manager->SetLayoutForCurrentDisplays( 773 display_manager()->SetLayoutForCurrentDisplays(test::CreateDisplayLayout(
748 test::CreateDisplayLayout(display::DisplayPlacement::RIGHT, 50)); 774 display_manager(), display::DisplayPlacement::RIGHT, 50));
749 775
750 display::Display primary_display = 776 display::Display primary_display =
751 display::Screen::GetScreen()->GetPrimaryDisplay(); 777 display::Screen::GetScreen()->GetPrimaryDisplay();
752 display::Display secondary_display = ScreenUtil::GetSecondaryDisplay(); 778 display::Display secondary_display = display_manager()->GetSecondaryDisplay();
753 EXPECT_NE(primary_display.id(), secondary_display.id()); 779 EXPECT_NE(primary_display.id(), secondary_display.id());
754 aura::Window* primary_root = 780 aura::Window* primary_root =
755 window_tree_host_manager->GetRootWindowForDisplayId(primary_display.id()); 781 window_tree_host_manager->GetRootWindowForDisplayId(primary_display.id());
756 aura::Window* secondary_root = 782 aura::Window* secondary_root =
757 window_tree_host_manager->GetRootWindowForDisplayId( 783 window_tree_host_manager->GetRootWindowForDisplayId(
758 secondary_display.id()); 784 secondary_display.id());
759 EXPECT_NE(primary_root, secondary_root); 785 EXPECT_NE(primary_root, secondary_root);
760 786
761 // Test that points outside of any display return the nearest display. 787 // Test that points outside of any display return the nearest display.
762 EXPECT_EQ(primary_display.id(), 788 EXPECT_EQ(primary_display.id(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 .id()); 823 .id());
798 } 824 }
799 825
800 TEST_P(WindowTreeHostManagerTest, SwapPrimaryById) { 826 TEST_P(WindowTreeHostManagerTest, SwapPrimaryById) {
801 if (!SupportsMultipleDisplays()) 827 if (!SupportsMultipleDisplays())
802 return; 828 return;
803 const int height_offset = GetMdMaximizedWindowHeightOffset(); 829 const int height_offset = GetMdMaximizedWindowHeightOffset();
804 830
805 WindowTreeHostManager* window_tree_host_manager = 831 WindowTreeHostManager* window_tree_host_manager =
806 Shell::GetInstance()->window_tree_host_manager(); 832 Shell::GetInstance()->window_tree_host_manager();
807 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
808 833
809 UpdateDisplay("200x200,300x300"); 834 UpdateDisplay("200x200,300x300");
810 display::Display primary_display = 835 display::Display primary_display =
811 display::Screen::GetScreen()->GetPrimaryDisplay(); 836 display::Screen::GetScreen()->GetPrimaryDisplay();
812 display::Display secondary_display = ScreenUtil::GetSecondaryDisplay(); 837 display::Display secondary_display = display_manager()->GetSecondaryDisplay();
813 838
814 display_manager->SetLayoutForCurrentDisplays( 839 display_manager()->SetLayoutForCurrentDisplays(test::CreateDisplayLayout(
815 test::CreateDisplayLayout(display::DisplayPlacement::RIGHT, 50)); 840 display_manager(), display::DisplayPlacement::RIGHT, 50));
816 841
817 EXPECT_NE(primary_display.id(), secondary_display.id()); 842 EXPECT_NE(primary_display.id(), secondary_display.id());
818 aura::Window* primary_root = 843 aura::Window* primary_root =
819 window_tree_host_manager->GetRootWindowForDisplayId(primary_display.id()); 844 window_tree_host_manager->GetRootWindowForDisplayId(primary_display.id());
820 aura::Window* secondary_root = 845 aura::Window* secondary_root =
821 window_tree_host_manager->GetRootWindowForDisplayId( 846 window_tree_host_manager->GetRootWindowForDisplayId(
822 secondary_display.id()); 847 secondary_display.id());
823 aura::Window* shelf_window = 848 aura::Window* shelf_window =
824 GetPrimaryShelf()->shelf_widget()->GetNativeView(); 849 GetPrimaryShelf()->shelf_widget()->GetNativeView();
825 EXPECT_TRUE(primary_root->Contains(shelf_window)); 850 EXPECT_TRUE(primary_root->Contains(shelf_window));
826 EXPECT_FALSE(secondary_root->Contains(shelf_window)); 851 EXPECT_FALSE(secondary_root->Contains(shelf_window));
827 EXPECT_NE(primary_root, secondary_root); 852 EXPECT_NE(primary_root, secondary_root);
828 EXPECT_EQ(primary_display.id(), 853 EXPECT_EQ(primary_display.id(),
829 display::Screen::GetScreen() 854 display::Screen::GetScreen()
830 ->GetDisplayNearestPoint(gfx::Point(-100, -100)) 855 ->GetDisplayNearestPoint(gfx::Point(-100, -100))
831 .id()); 856 .id());
832 EXPECT_EQ( 857 EXPECT_EQ(
833 primary_display.id(), 858 primary_display.id(),
834 display::Screen::GetScreen()->GetDisplayNearestWindow(nullptr).id()); 859 display::Screen::GetScreen()->GetDisplayNearestWindow(nullptr).id());
835 860
836 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); 861 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString());
837 EXPECT_EQ(gfx::Rect(0, 0, 200, 153 + height_offset).ToString(), 862 EXPECT_EQ(gfx::Rect(0, 0, 200, 153 + height_offset).ToString(),
838 primary_display.work_area().ToString()); 863 primary_display.work_area().ToString());
839 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); 864 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString());
840 EXPECT_EQ(gfx::Rect(200, 0, 300, 253 + height_offset).ToString(), 865 EXPECT_EQ(gfx::Rect(200, 0, 300, 253 + height_offset).ToString(),
841 secondary_display.work_area().ToString()); 866 secondary_display.work_area().ToString());
842 EXPECT_EQ( 867 EXPECT_EQ("id=2200000001, parent=2200000000, right, 50",
843 "id=2200000001, parent=2200000000, right, 50", 868 display_manager()
844 display_manager->GetCurrentDisplayLayout().placement_list[0].ToString()); 869 ->GetCurrentDisplayLayout()
870 .placement_list[0]
871 .ToString());
845 872
846 // Switch primary and secondary by display ID. 873 // Switch primary and secondary by display ID.
847 TestObserver observer; 874 TestObserver observer;
848 window_tree_host_manager->SetPrimaryDisplayId(secondary_display.id()); 875 window_tree_host_manager->SetPrimaryDisplayId(secondary_display.id());
849 EXPECT_EQ(secondary_display.id(), 876 EXPECT_EQ(secondary_display.id(),
850 display::Screen::GetScreen()->GetPrimaryDisplay().id()); 877 display::Screen::GetScreen()->GetPrimaryDisplay().id());
851 EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id()); 878 EXPECT_EQ(primary_display.id(),
879 display_manager()->GetSecondaryDisplay().id());
852 EXPECT_LT(0, observer.CountAndReset()); 880 EXPECT_LT(0, observer.CountAndReset());
853 881
854 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( 882 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId(
855 secondary_display.id())); 883 secondary_display.id()));
856 EXPECT_EQ(secondary_root, window_tree_host_manager->GetRootWindowForDisplayId( 884 EXPECT_EQ(secondary_root, window_tree_host_manager->GetRootWindowForDisplayId(
857 primary_display.id())); 885 primary_display.id()));
858 EXPECT_TRUE(primary_root->Contains(shelf_window)); 886 EXPECT_TRUE(primary_root->Contains(shelf_window));
859 EXPECT_FALSE(secondary_root->Contains(shelf_window)); 887 EXPECT_FALSE(secondary_root->Contains(shelf_window));
860 888
861 const display::DisplayLayout& inverted_layout = 889 const display::DisplayLayout& inverted_layout =
862 display_manager->GetCurrentDisplayLayout(); 890 display_manager()->GetCurrentDisplayLayout();
863 891
864 EXPECT_EQ("id=2200000000, parent=2200000001, left, -50", 892 EXPECT_EQ("id=2200000000, parent=2200000001, left, -50",
865 inverted_layout.placement_list[0].ToString()); 893 inverted_layout.placement_list[0].ToString());
866 // Test if the bounds are correctly swapped. 894 // Test if the bounds are correctly swapped.
867 display::Display swapped_primary = 895 display::Display swapped_primary =
868 display::Screen::GetScreen()->GetPrimaryDisplay(); 896 display::Screen::GetScreen()->GetPrimaryDisplay();
869 display::Display swapped_secondary = ScreenUtil::GetSecondaryDisplay(); 897 display::Display swapped_secondary = display_manager()->GetSecondaryDisplay();
870 EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString()); 898 EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString());
871 EXPECT_EQ(gfx::Rect(0, 0, 300, 253 + height_offset).ToString(), 899 EXPECT_EQ(gfx::Rect(0, 0, 300, 253 + height_offset).ToString(),
872 swapped_primary.work_area().ToString()); 900 swapped_primary.work_area().ToString());
873 EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString()); 901 EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString());
874 EXPECT_EQ(gfx::Rect(-200, -50, 200, 153 + height_offset).ToString(), 902 EXPECT_EQ(gfx::Rect(-200, -50, 200, 153 + height_offset).ToString(),
875 swapped_secondary.work_area().ToString()); 903 swapped_secondary.work_area().ToString());
876 904
877 // Calling the same ID don't do anything. 905 // Calling the same ID don't do anything.
878 window_tree_host_manager->SetPrimaryDisplayId(secondary_display.id()); 906 window_tree_host_manager->SetPrimaryDisplayId(secondary_display.id());
879 EXPECT_EQ(0, observer.CountAndReset()); 907 EXPECT_EQ(0, observer.CountAndReset());
(...skipping 16 matching lines...) Expand all
896 primary_display.id(), 924 primary_display.id(),
897 display::Screen::GetScreen()->GetDisplayNearestWindow(nullptr).id()); 925 display::Screen::GetScreen()->GetDisplayNearestWindow(nullptr).id());
898 EXPECT_TRUE(tracker.Contains(primary_root)); 926 EXPECT_TRUE(tracker.Contains(primary_root));
899 EXPECT_FALSE(tracker.Contains(secondary_root)); 927 EXPECT_FALSE(tracker.Contains(secondary_root));
900 EXPECT_TRUE(primary_root->Contains(shelf_window)); 928 EXPECT_TRUE(primary_root->Contains(shelf_window));
901 929
902 // Adding 2nd display with the same ID. The 2nd display should become primary 930 // Adding 2nd display with the same ID. The 2nd display should become primary
903 // since secondary id is still stored as desirable_primary_id. 931 // since secondary id is still stored as desirable_primary_id.
904 std::vector<display::ManagedDisplayInfo> display_info_list; 932 std::vector<display::ManagedDisplayInfo> display_info_list;
905 display_info_list.push_back( 933 display_info_list.push_back(
906 display_manager->GetDisplayInfo(primary_display.id())); 934 display_manager()->GetDisplayInfo(primary_display.id()));
907 display_info_list.push_back( 935 display_info_list.push_back(
908 display_manager->GetDisplayInfo(secondary_display.id())); 936 display_manager()->GetDisplayInfo(secondary_display.id()));
909 937
910 display_manager->OnNativeDisplaysChanged(display_info_list); 938 display_manager()->OnNativeDisplaysChanged(display_info_list);
911 939
912 EXPECT_EQ(2, display::Screen::GetScreen()->GetNumDisplays()); 940 EXPECT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
913 EXPECT_EQ(secondary_display.id(), 941 EXPECT_EQ(secondary_display.id(),
914 display::Screen::GetScreen()->GetPrimaryDisplay().id()); 942 display::Screen::GetScreen()->GetPrimaryDisplay().id());
915 EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id()); 943 EXPECT_EQ(primary_display.id(),
944 display_manager()->GetSecondaryDisplay().id());
916 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( 945 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId(
917 secondary_display.id())); 946 secondary_display.id()));
918 EXPECT_NE(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( 947 EXPECT_NE(primary_root, window_tree_host_manager->GetRootWindowForDisplayId(
919 primary_display.id())); 948 primary_display.id()));
920 EXPECT_TRUE(primary_root->Contains(shelf_window)); 949 EXPECT_TRUE(primary_root->Contains(shelf_window));
921 950
922 // Deleting 2nd display and adding 2nd display with a different ID. The 2nd 951 // Deleting 2nd display and adding 2nd display with a different ID. The 2nd
923 // display shouldn't become primary. 952 // display shouldn't become primary.
924 UpdateDisplay("200x200"); 953 UpdateDisplay("200x200");
925 display::ManagedDisplayInfo third_display_info(secondary_display.id() + 1, 954 display::ManagedDisplayInfo third_display_info(secondary_display.id() + 1,
926 std::string(), false); 955 std::string(), false);
927 third_display_info.SetBounds(secondary_display.bounds()); 956 third_display_info.SetBounds(secondary_display.bounds());
928 ASSERT_NE(primary_display.id(), third_display_info.id()); 957 ASSERT_NE(primary_display.id(), third_display_info.id());
929 958
930 const display::ManagedDisplayInfo& primary_display_info = 959 const display::ManagedDisplayInfo& primary_display_info =
931 display_manager->GetDisplayInfo(primary_display.id()); 960 display_manager()->GetDisplayInfo(primary_display.id());
932 std::vector<display::ManagedDisplayInfo> display_info_list2; 961 std::vector<display::ManagedDisplayInfo> display_info_list2;
933 display_info_list2.push_back(primary_display_info); 962 display_info_list2.push_back(primary_display_info);
934 display_info_list2.push_back(third_display_info); 963 display_info_list2.push_back(third_display_info);
935 display_manager->OnNativeDisplaysChanged(display_info_list2); 964 display_manager()->OnNativeDisplaysChanged(display_info_list2);
936 EXPECT_EQ(2, display::Screen::GetScreen()->GetNumDisplays()); 965 EXPECT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
937 EXPECT_EQ(primary_display.id(), 966 EXPECT_EQ(primary_display.id(),
938 display::Screen::GetScreen()->GetPrimaryDisplay().id()); 967 display::Screen::GetScreen()->GetPrimaryDisplay().id());
939 EXPECT_EQ(third_display_info.id(), ScreenUtil::GetSecondaryDisplay().id()); 968 EXPECT_EQ(third_display_info.id(),
969 display_manager()->GetSecondaryDisplay().id());
940 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( 970 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId(
941 primary_display.id())); 971 primary_display.id()));
942 EXPECT_NE(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( 972 EXPECT_NE(primary_root, window_tree_host_manager->GetRootWindowForDisplayId(
943 third_display_info.id())); 973 third_display_info.id()));
944 EXPECT_TRUE(primary_root->Contains(shelf_window)); 974 EXPECT_TRUE(primary_root->Contains(shelf_window));
945 } 975 }
946 976
947 TEST_P(WindowTreeHostManagerTest, NoSwapPrimaryWithThreeDisplays) { 977 TEST_P(WindowTreeHostManagerTest, NoSwapPrimaryWithThreeDisplays) {
948 if (!SupportsMultipleDisplays()) 978 if (!SupportsMultipleDisplays())
949 return; 979 return;
950 int64_t primary = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 980 int64_t primary = display::Screen::GetScreen()->GetPrimaryDisplay().id();
951 UpdateDisplay("500x400,400x300,300x200"); 981 UpdateDisplay("500x400,400x300,300x200");
952 EXPECT_EQ(primary, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 982 EXPECT_EQ(primary, display::Screen::GetScreen()->GetPrimaryDisplay().id());
953 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId( 983 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId(
954 ScreenUtil::GetSecondaryDisplay().id()); 984 display_manager()->GetSecondaryDisplay().id());
955 EXPECT_EQ(primary, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 985 EXPECT_EQ(primary, display::Screen::GetScreen()->GetPrimaryDisplay().id());
956 } 986 }
957 987
958 TEST_P(WindowTreeHostManagerTest, OverscanInsets) { 988 TEST_P(WindowTreeHostManagerTest, OverscanInsets) {
959 if (!SupportsMultipleDisplays()) 989 if (!SupportsMultipleDisplays())
960 return; 990 return;
961 991
962 WindowTreeHostManager* window_tree_host_manager = 992 WindowTreeHostManager* window_tree_host_manager =
963 Shell::GetInstance()->window_tree_host_manager(); 993 Shell::GetInstance()->window_tree_host_manager();
964 TestEventHandler event_handler; 994 TestEventHandler event_handler;
965 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 995 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
966 996
967 UpdateDisplay("120x200,300x400*2"); 997 UpdateDisplay("120x200,300x400*2");
968 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 998 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
969 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 999 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
970 1000
971 window_tree_host_manager->SetOverscanInsets(display1.id(), 1001 window_tree_host_manager->SetOverscanInsets(display1.id(),
972 gfx::Insets(10, 15, 20, 25)); 1002 gfx::Insets(10, 15, 20, 25));
973 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString()); 1003 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString());
974 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1004 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
975 EXPECT_EQ("80,0 150x200", 1005 EXPECT_EQ("80,0 150x200",
976 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1006 display_manager()->GetSecondaryDisplay().bounds().ToString());
977 1007
978 ui::test::EventGenerator generator(root_windows[0]); 1008 ui::test::EventGenerator generator(root_windows[0]);
979 generator.MoveMouseToInHost(20, 25); 1009 generator.MoveMouseToInHost(20, 25);
980 EXPECT_EQ("5,15", event_handler.GetLocationAndReset()); 1010 EXPECT_EQ("5,15", event_handler.GetLocationAndReset());
981 1011
982 window_tree_host_manager->SetOverscanInsets(display1.id(), gfx::Insets()); 1012 window_tree_host_manager->SetOverscanInsets(display1.id(), gfx::Insets());
983 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString()); 1013 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString());
984 EXPECT_EQ("120,0 150x200", 1014 EXPECT_EQ("120,0 150x200",
985 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1015 display_manager()->GetSecondaryDisplay().bounds().ToString());
986 1016
987 generator.MoveMouseToInHost(30, 20); 1017 generator.MoveMouseToInHost(30, 20);
988 EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); 1018 EXPECT_EQ("30,20", event_handler.GetLocationAndReset());
989 1019
990 // Make sure the root window transformer uses correct scale 1020 // Make sure the root window transformer uses correct scale
991 // factor when swapping display. Test crbug.com/253690. 1021 // factor when swapping display. Test crbug.com/253690.
992 UpdateDisplay("400x300*2,600x400/o"); 1022 UpdateDisplay("400x300*2,600x400/o");
993 root_windows = Shell::GetAllRootWindows(); 1023 root_windows = Shell::GetAllRootWindows();
994 gfx::Point point; 1024 gfx::Point point;
995 Shell::GetAllRootWindows()[1]->GetHost()->GetRootTransform().TransformPoint( 1025 Shell::GetAllRootWindows()[1]->GetHost()->GetRootTransform().TransformPoint(
996 &point); 1026 &point);
997 EXPECT_EQ("15,10", point.ToString()); 1027 EXPECT_EQ("15,10", point.ToString());
998 1028
999 test::SwapPrimaryDisplay(); 1029 SwapPrimaryDisplay();
1000 point.SetPoint(0, 0); 1030 point.SetPoint(0, 0);
1001 Shell::GetAllRootWindows()[1]->GetHost()->GetRootTransform().TransformPoint( 1031 Shell::GetAllRootWindows()[1]->GetHost()->GetRootTransform().TransformPoint(
1002 &point); 1032 &point);
1003 EXPECT_EQ("15,10", point.ToString()); 1033 EXPECT_EQ("15,10", point.ToString());
1004 1034
1005 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1035 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1006 } 1036 }
1007 1037
1008 TEST_P(WindowTreeHostManagerTest, Rotate) { 1038 TEST_P(WindowTreeHostManagerTest, Rotate) {
1009 if (!SupportsMultipleDisplays()) 1039 if (!SupportsMultipleDisplays())
1010 return; 1040 return;
1011 1041
1012 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1013 TestEventHandler event_handler; 1042 TestEventHandler event_handler;
1014 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 1043 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1015 1044
1016 UpdateDisplay("120x200,300x400*2"); 1045 UpdateDisplay("120x200,300x400*2");
1017 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 1046 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
1018 int64_t display2_id = ScreenUtil::GetSecondaryDisplay().id(); 1047 int64_t display2_id = display_manager()->GetSecondaryDisplay().id();
1019 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1048 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1020 ui::test::EventGenerator generator1(root_windows[0]); 1049 ui::test::EventGenerator generator1(root_windows[0]);
1021 1050
1022 TestObserver observer; 1051 TestObserver observer;
1023 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 1052 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
1024 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1053 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
1025 EXPECT_EQ("120,0 150x200", 1054 EXPECT_EQ("120,0 150x200",
1026 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1055 display_manager()->GetSecondaryDisplay().bounds().ToString());
1027 generator1.MoveMouseToInHost(50, 40); 1056 generator1.MoveMouseToInHost(50, 40);
1028 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); 1057 EXPECT_EQ("50,40", event_handler.GetLocationAndReset());
1029 EXPECT_EQ(display::Display::ROTATE_0, 1058 EXPECT_EQ(display::Display::ROTATE_0,
1030 GetActiveDisplayRotation(display1.id())); 1059 GetActiveDisplayRotation(display1.id()));
1031 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); 1060 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id));
1032 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); 1061 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset());
1033 1062
1034 display_manager->SetDisplayRotation(display1.id(), 1063 display_manager()->SetDisplayRotation(
1035 display::Display::ROTATE_90, 1064 display1.id(), display::Display::ROTATE_90,
1036 display::Display::ROTATION_SOURCE_ACTIVE); 1065 display::Display::ROTATION_SOURCE_ACTIVE);
1037 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 1066 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
1038 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 1067 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
1039 EXPECT_EQ("200,0 150x200", 1068 EXPECT_EQ("200,0 150x200",
1040 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1069 display_manager()->GetSecondaryDisplay().bounds().ToString());
1041 generator1.MoveMouseToInHost(50, 40); 1070 generator1.MoveMouseToInHost(50, 40);
1042 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); 1071 EXPECT_EQ("40,69", event_handler.GetLocationAndReset());
1043 EXPECT_EQ(display::Display::ROTATE_90, 1072 EXPECT_EQ(display::Display::ROTATE_90,
1044 GetActiveDisplayRotation(display1.id())); 1073 GetActiveDisplayRotation(display1.id()));
1045 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); 1074 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id));
1046 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); 1075 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
1047 1076
1048 display_manager->SetLayoutForCurrentDisplays( 1077 display_manager()->SetLayoutForCurrentDisplays(test::CreateDisplayLayout(
1049 test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 50)); 1078 display_manager(), display::DisplayPlacement::BOTTOM, 50));
1050 EXPECT_EQ("50,120 150x200", 1079 EXPECT_EQ("50,120 150x200",
1051 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1080 display_manager()->GetSecondaryDisplay().bounds().ToString());
1052 1081
1053 display_manager->SetDisplayRotation(display2_id, display::Display::ROTATE_270, 1082 display_manager()->SetDisplayRotation(
1054 display::Display::ROTATION_SOURCE_ACTIVE); 1083 display2_id, display::Display::ROTATE_270,
1084 display::Display::ROTATION_SOURCE_ACTIVE);
1055 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 1085 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
1056 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 1086 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
1057 EXPECT_EQ("50,120 200x150", 1087 EXPECT_EQ("50,120 200x150",
1058 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1088 display_manager()->GetSecondaryDisplay().bounds().ToString());
1059 EXPECT_EQ(display::Display::ROTATE_90, 1089 EXPECT_EQ(display::Display::ROTATE_90,
1060 GetActiveDisplayRotation(display1.id())); 1090 GetActiveDisplayRotation(display1.id()));
1061 EXPECT_EQ(display::Display::ROTATE_270, 1091 EXPECT_EQ(display::Display::ROTATE_270,
1062 GetActiveDisplayRotation(display2_id)); 1092 GetActiveDisplayRotation(display2_id));
1063 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); 1093 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
1064 1094
1065 #if !defined(OS_WIN) 1095 #if !defined(OS_WIN)
1066 ui::test::EventGenerator generator2(root_windows[1]); 1096 ui::test::EventGenerator generator2(root_windows[1]);
1067 generator2.MoveMouseToInHost(50, 40); 1097 generator2.MoveMouseToInHost(50, 40);
1068 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); 1098 EXPECT_EQ("179,25", event_handler.GetLocationAndReset());
1069 display_manager->SetDisplayRotation(display1.id(), 1099 display_manager()->SetDisplayRotation(
1070 display::Display::ROTATE_180, 1100 display1.id(), display::Display::ROTATE_180,
1071 display::Display::ROTATION_SOURCE_ACTIVE); 1101 display::Display::ROTATION_SOURCE_ACTIVE);
1072 1102
1073 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 1103 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
1074 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 1104 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
1075 // Dislay must share at least 100, so the x's offset becomes 20. 1105 // Dislay must share at least 100, so the x's offset becomes 20.
1076 EXPECT_EQ("20,200 200x150", 1106 EXPECT_EQ("20,200 200x150",
1077 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1107 display_manager()->GetSecondaryDisplay().bounds().ToString());
1078 EXPECT_EQ(display::Display::ROTATE_180, 1108 EXPECT_EQ(display::Display::ROTATE_180,
1079 GetActiveDisplayRotation(display1.id())); 1109 GetActiveDisplayRotation(display1.id()));
1080 EXPECT_EQ(display::Display::ROTATE_270, 1110 EXPECT_EQ(display::Display::ROTATE_270,
1081 GetActiveDisplayRotation(display2_id)); 1111 GetActiveDisplayRotation(display2_id));
1082 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); 1112 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
1083 1113
1084 generator1.MoveMouseToInHost(50, 40); 1114 generator1.MoveMouseToInHost(50, 40);
1085 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); 1115 EXPECT_EQ("69,159", event_handler.GetLocationAndReset());
1086 #endif 1116 #endif
1087 1117
1088 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1118 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1089 } 1119 }
1090 1120
1091 TEST_P(WindowTreeHostManagerTest, ScaleRootWindow) { 1121 TEST_P(WindowTreeHostManagerTest, ScaleRootWindow) {
1092 if (!SupportsMultipleDisplays()) 1122 if (!SupportsMultipleDisplays())
1093 return; 1123 return;
1094 1124
1095 TestEventHandler event_handler; 1125 TestEventHandler event_handler;
1096 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 1126 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1097 1127
1098 UpdateDisplay("600x400*2@1.5,500x300"); 1128 UpdateDisplay("600x400*2@1.5,500x300");
1099 1129
1100 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 1130 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
1101 test::ScopedSetInternalDisplayId set_internal(display1.id()); 1131 test::ScopedSetInternalDisplayId set_internal(display_manager(),
1132 display1.id());
1102 1133
1103 display::Display display2 = ScreenUtil::GetSecondaryDisplay(); 1134 display::Display display2 = display_manager()->GetSecondaryDisplay();
1104 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1135 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1105 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); 1136 EXPECT_EQ("0,0 450x300", display1.bounds().ToString());
1106 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); 1137 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString());
1107 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); 1138 EXPECT_EQ("450,0 500x300", display2.bounds().ToString());
1108 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 1139 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
1109 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 1140 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
1110 1141
1111 ui::test::EventGenerator generator(root_windows[0]); 1142 ui::test::EventGenerator generator(root_windows[0]);
1112 generator.MoveMouseToInHost(599, 200); 1143 generator.MoveMouseToInHost(599, 200);
1113 EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); 1144 EXPECT_EQ("449,150", event_handler.GetLocationAndReset());
1114 1145
1115 Shell::GetInstance()->display_manager()->SetDisplayUIScale(display1.id(), 1146 display_manager()->SetDisplayUIScale(display1.id(), 1.25f);
1116 1.25f);
1117 display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 1147 display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
1118 display2 = ScreenUtil::GetSecondaryDisplay(); 1148 display2 = display_manager()->GetSecondaryDisplay();
1119 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); 1149 EXPECT_EQ("0,0 375x250", display1.bounds().ToString());
1120 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); 1150 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString());
1121 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); 1151 EXPECT_EQ("375,0 500x300", display2.bounds().ToString());
1122 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); 1152 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id()));
1123 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 1153 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
1124 1154
1125 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1155 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1126 } 1156 }
1127 1157
1128 TEST_P(WindowTreeHostManagerTest, TouchScale) { 1158 TEST_P(WindowTreeHostManagerTest, TouchScale) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 1246
1217 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1247 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1218 } 1248 }
1219 1249
1220 // Make sure that the compositor based mirroring can switch 1250 // Make sure that the compositor based mirroring can switch
1221 // from/to dock mode. 1251 // from/to dock mode.
1222 TEST_P(WindowTreeHostManagerTest, DockToSingle) { 1252 TEST_P(WindowTreeHostManagerTest, DockToSingle) {
1223 if (!SupportsMultipleDisplays()) 1253 if (!SupportsMultipleDisplays())
1224 return; 1254 return;
1225 1255
1226 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1227
1228 const int64_t internal_id = 1; 1256 const int64_t internal_id = 1;
1229 1257
1230 const display::ManagedDisplayInfo internal_display_info = 1258 const display::ManagedDisplayInfo internal_display_info =
1231 CreateDisplayInfo(internal_id, 0, display::Display::ROTATE_0); 1259 CreateDisplayInfo(internal_id, 0, display::Display::ROTATE_0);
1232 const display::ManagedDisplayInfo external_display_info = 1260 const display::ManagedDisplayInfo external_display_info =
1233 CreateDisplayInfo(2, 1, display::Display::ROTATE_90); 1261 CreateDisplayInfo(2, 1, display::Display::ROTATE_90);
1234 1262
1235 std::vector<display::ManagedDisplayInfo> display_info_list; 1263 std::vector<display::ManagedDisplayInfo> display_info_list;
1236 // Extended 1264 // Extended
1237 display_info_list.push_back(internal_display_info); 1265 display_info_list.push_back(internal_display_info);
1238 display_info_list.push_back(external_display_info); 1266 display_info_list.push_back(external_display_info);
1239 display_manager->OnNativeDisplaysChanged(display_info_list); 1267 display_manager()->OnNativeDisplaysChanged(display_info_list);
1240 const int64_t internal_display_id = 1268 const int64_t internal_display_id =
1241 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); 1269 test::DisplayManagerTestApi(display_manager())
1270 .SetFirstDisplayAsInternalDisplay();
1242 EXPECT_EQ(internal_id, internal_display_id); 1271 EXPECT_EQ(internal_id, internal_display_id);
1243 EXPECT_EQ(2U, display_manager->GetNumDisplays()); 1272 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
1244 1273
1245 // Dock mode. 1274 // Dock mode.
1246 display_info_list.clear(); 1275 display_info_list.clear();
1247 display_info_list.push_back(external_display_info); 1276 display_info_list.push_back(external_display_info);
1248 display_manager->OnNativeDisplaysChanged(display_info_list); 1277 display_manager()->OnNativeDisplaysChanged(display_info_list);
1249 EXPECT_EQ(1U, display_manager->GetNumDisplays()); 1278 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
1250 EXPECT_FALSE(Shell::GetPrimaryRootWindow() 1279 EXPECT_FALSE(Shell::GetPrimaryRootWindow()
1251 ->GetHost() 1280 ->GetHost()
1252 ->GetRootTransform() 1281 ->GetRootTransform()
1253 .IsIdentityOrIntegerTranslation()); 1282 .IsIdentityOrIntegerTranslation());
1254 1283
1255 // Switch to single mode and make sure the transform is the one 1284 // Switch to single mode and make sure the transform is the one
1256 // for the internal display. 1285 // for the internal display.
1257 display_info_list.clear(); 1286 display_info_list.clear();
1258 display_info_list.push_back(internal_display_info); 1287 display_info_list.push_back(internal_display_info);
1259 display_manager->OnNativeDisplaysChanged(display_info_list); 1288 display_manager()->OnNativeDisplaysChanged(display_info_list);
1260 EXPECT_TRUE(Shell::GetPrimaryRootWindow() 1289 EXPECT_TRUE(Shell::GetPrimaryRootWindow()
1261 ->GetHost() 1290 ->GetHost()
1262 ->GetRootTransform() 1291 ->GetRootTransform()
1263 .IsIdentityOrIntegerTranslation()); 1292 .IsIdentityOrIntegerTranslation());
1264 } 1293 }
1265 1294
1266 // Tests if switching two displays at the same time while the primary display 1295 // Tests if switching two displays at the same time while the primary display
1267 // is swapped should not cause a crash. (crbug.com/426292) 1296 // is swapped should not cause a crash. (crbug.com/426292)
1268 TEST_P(WindowTreeHostManagerTest, ReplaceSwappedPrimary) { 1297 TEST_P(WindowTreeHostManagerTest, ReplaceSwappedPrimary) {
1269 if (!SupportsMultipleDisplays()) 1298 if (!SupportsMultipleDisplays())
1270 return; 1299 return;
1271 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1272 1300
1273 const display::ManagedDisplayInfo first_display_info = 1301 const display::ManagedDisplayInfo first_display_info =
1274 CreateDisplayInfo(10, 0, display::Display::ROTATE_0); 1302 CreateDisplayInfo(10, 0, display::Display::ROTATE_0);
1275 const display::ManagedDisplayInfo second_display_info = 1303 const display::ManagedDisplayInfo second_display_info =
1276 CreateDisplayInfo(11, 1, display::Display::ROTATE_0); 1304 CreateDisplayInfo(11, 1, display::Display::ROTATE_0);
1277 1305
1278 std::vector<display::ManagedDisplayInfo> display_info_list; 1306 std::vector<display::ManagedDisplayInfo> display_info_list;
1279 // Extended 1307 // Extended
1280 display_info_list.push_back(first_display_info); 1308 display_info_list.push_back(first_display_info);
1281 display_info_list.push_back(second_display_info); 1309 display_info_list.push_back(second_display_info);
1282 display_manager->OnNativeDisplaysChanged(display_info_list); 1310 display_manager()->OnNativeDisplaysChanged(display_info_list);
1283 1311
1284 test::SwapPrimaryDisplay(); 1312 SwapPrimaryDisplay();
1285 1313
1286 EXPECT_EQ(11, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 1314 EXPECT_EQ(11, display::Screen::GetScreen()->GetPrimaryDisplay().id());
1287 1315
1288 display_info_list.clear(); 1316 display_info_list.clear();
1289 const display::ManagedDisplayInfo new_first_display_info = 1317 const display::ManagedDisplayInfo new_first_display_info =
1290 CreateDisplayInfo(20, 0, display::Display::ROTATE_0); 1318 CreateDisplayInfo(20, 0, display::Display::ROTATE_0);
1291 const display::ManagedDisplayInfo new_second_display_info = 1319 const display::ManagedDisplayInfo new_second_display_info =
1292 CreateDisplayInfo(21, 1, display::Display::ROTATE_0); 1320 CreateDisplayInfo(21, 1, display::Display::ROTATE_0);
1293 display_info_list.push_back(new_first_display_info); 1321 display_info_list.push_back(new_first_display_info);
1294 display_info_list.push_back(new_second_display_info); 1322 display_info_list.push_back(new_second_display_info);
1295 display_manager->OnNativeDisplaysChanged(display_info_list); 1323 display_manager()->OnNativeDisplaysChanged(display_info_list);
1296 1324
1297 EXPECT_EQ(20, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 1325 EXPECT_EQ(20, display::Screen::GetScreen()->GetPrimaryDisplay().id());
1298 } 1326 }
1299 1327
1300 namespace { 1328 namespace {
1301 1329
1302 class RootWindowTestObserver : public aura::WindowObserver { 1330 class RootWindowTestObserver : public aura::WindowObserver {
1303 public: 1331 public:
1304 RootWindowTestObserver() {} 1332 RootWindowTestObserver() {}
1305 ~RootWindowTestObserver() override {} 1333 ~RootWindowTestObserver() override {}
(...skipping 19 matching lines...) Expand all
1325 1353
1326 // Make sure that GetDisplayBoundsWithShelf returns the correct bounds 1354 // Make sure that GetDisplayBoundsWithShelf returns the correct bounds
1327 // when the primary display gets replaced in one of the following scenarios: 1355 // when the primary display gets replaced in one of the following scenarios:
1328 // 1) Two displays connected: a) b) 1356 // 1) Two displays connected: a) b)
1329 // 2) both are disconnected and new one with the same size as b) is connected 1357 // 2) both are disconnected and new one with the same size as b) is connected
1330 // in one configuration event. 1358 // in one configuration event.
1331 // See crbug.com/547280. 1359 // See crbug.com/547280.
1332 TEST_P(WindowTreeHostManagerTest, ReplacePrimary) { 1360 TEST_P(WindowTreeHostManagerTest, ReplacePrimary) {
1333 if (!SupportsMultipleDisplays()) 1361 if (!SupportsMultipleDisplays())
1334 return; 1362 return;
1335 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1336 1363
1337 display::ManagedDisplayInfo first_display_info = 1364 display::ManagedDisplayInfo first_display_info =
1338 CreateDisplayInfo(10, 0, display::Display::ROTATE_0); 1365 CreateDisplayInfo(10, 0, display::Display::ROTATE_0);
1339 first_display_info.SetBounds(gfx::Rect(0, 0, 400, 400)); 1366 first_display_info.SetBounds(gfx::Rect(0, 0, 400, 400));
1340 const display::ManagedDisplayInfo second_display_info = 1367 const display::ManagedDisplayInfo second_display_info =
1341 CreateDisplayInfo(11, 500, display::Display::ROTATE_0); 1368 CreateDisplayInfo(11, 500, display::Display::ROTATE_0);
1342 1369
1343 std::vector<display::ManagedDisplayInfo> display_info_list; 1370 std::vector<display::ManagedDisplayInfo> display_info_list;
1344 // Extended 1371 // Extended
1345 display_info_list.push_back(first_display_info); 1372 display_info_list.push_back(first_display_info);
1346 display_info_list.push_back(second_display_info); 1373 display_info_list.push_back(second_display_info);
1347 display_manager->OnNativeDisplaysChanged(display_info_list); 1374 display_manager()->OnNativeDisplaysChanged(display_info_list);
1348 aura::Window* primary_root = Shell::GetAllRootWindows()[0]; 1375 aura::Window* primary_root = Shell::GetAllRootWindows()[0];
1349 1376
1350 int64_t new_display_id = 20; 1377 int64_t new_display_id = 20;
1351 RootWindowTestObserver test_observer; 1378 RootWindowTestObserver test_observer;
1352 primary_root->AddObserver(&test_observer); 1379 primary_root->AddObserver(&test_observer);
1353 1380
1354 display_info_list.clear(); 1381 display_info_list.clear();
1355 const display::ManagedDisplayInfo new_first_display_info = 1382 const display::ManagedDisplayInfo new_first_display_info =
1356 CreateDisplayInfo(new_display_id, 0, display::Display::ROTATE_0); 1383 CreateDisplayInfo(new_display_id, 0, display::Display::ROTATE_0);
1357 1384
1358 display_info_list.push_back(new_first_display_info); 1385 display_info_list.push_back(new_first_display_info);
1359 display_manager->OnNativeDisplaysChanged(display_info_list); 1386 display_manager()->OnNativeDisplaysChanged(display_info_list);
1360 EXPECT_EQ("0,0 500x500", test_observer.shelf_display_bounds().ToString()); 1387 EXPECT_EQ("0,0 500x500", test_observer.shelf_display_bounds().ToString());
1361 primary_root->RemoveObserver(&test_observer); 1388 primary_root->RemoveObserver(&test_observer);
1362 } 1389 }
1363 1390
1364 TEST_P(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) { 1391 TEST_P(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) {
1365 if (!SupportsMultipleDisplays()) 1392 if (!SupportsMultipleDisplays())
1366 return; 1393 return;
1367 1394
1368 UpdateDisplay("200x200,300x300"); 1395 UpdateDisplay("200x200,300x300");
1369 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1396 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 UpdateDisplay("300x280,200x200"); 1430 UpdateDisplay("300x280,200x200");
1404 EXPECT_EQ("450,10", env->last_mouse_location().ToString()); 1431 EXPECT_EQ("450,10", env->last_mouse_location().ToString());
1405 } 1432 }
1406 1433
1407 TEST_P(WindowTreeHostManagerTest, 1434 TEST_P(WindowTreeHostManagerTest,
1408 UpdateMouseLocationAfterDisplayChange_2ndOnLeft) { 1435 UpdateMouseLocationAfterDisplayChange_2ndOnLeft) {
1409 if (!SupportsMultipleDisplays()) 1436 if (!SupportsMultipleDisplays())
1410 return; 1437 return;
1411 1438
1412 // Set the 2nd display on the left. 1439 // Set the 2nd display on the left.
1413 display::DisplayLayoutStore* layout_store = 1440 display::DisplayLayoutStore* layout_store = display_manager()->layout_store();
1414 Shell::GetInstance()->display_manager()->layout_store();
1415 display::DisplayPlacement new_default(display::DisplayPlacement::LEFT, 0); 1441 display::DisplayPlacement new_default(display::DisplayPlacement::LEFT, 0);
1416 layout_store->SetDefaultDisplayPlacement(new_default); 1442 layout_store->SetDefaultDisplayPlacement(new_default);
1417 1443
1418 UpdateDisplay("200x200,300x300"); 1444 UpdateDisplay("200x200,300x300");
1419 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1445 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1420 1446
1421 EXPECT_EQ("-300,0 300x300", 1447 EXPECT_EQ("-300,0 300x300",
1422 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 1448 display_manager()->GetSecondaryDisplay().bounds().ToString());
1423 1449
1424 aura::Env* env = aura::Env::GetInstance(); 1450 aura::Env* env = aura::Env::GetInstance();
1425 1451
1426 // Set the initial position. 1452 // Set the initial position.
1427 root_windows[0]->MoveCursorTo(gfx::Point(-150, 250)); 1453 root_windows[0]->MoveCursorTo(gfx::Point(-150, 250));
1428 EXPECT_EQ("-150,250", env->last_mouse_location().ToString()); 1454 EXPECT_EQ("-150,250", env->last_mouse_location().ToString());
1429 1455
1430 // A mouse pointer will stay in 2nd display. 1456 // A mouse pointer will stay in 2nd display.
1431 UpdateDisplay("300x300,200x300"); 1457 UpdateDisplay("300x300,200x300");
1432 EXPECT_EQ("-50,150", env->last_mouse_location().ToString()); 1458 EXPECT_EQ("-50,150", env->last_mouse_location().ToString());
(...skipping 24 matching lines...) Expand all
1457 shell->window_tree_host_manager(); 1483 shell->window_tree_host_manager();
1458 test::CursorManagerTestApi test_api(shell->cursor_manager()); 1484 test::CursorManagerTestApi test_api(shell->cursor_manager());
1459 1485
1460 window_tree_host_manager->GetPrimaryRootWindow()->MoveCursorTo( 1486 window_tree_host_manager->GetPrimaryRootWindow()->MoveCursorTo(
1461 gfx::Point(20, 50)); 1487 gfx::Point(20, 50));
1462 1488
1463 EXPECT_EQ("20,50", env->last_mouse_location().ToString()); 1489 EXPECT_EQ("20,50", env->last_mouse_location().ToString());
1464 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); 1490 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
1465 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation()); 1491 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
1466 1492
1467 test::SwapPrimaryDisplay(); 1493 SwapPrimaryDisplay();
1468 1494
1469 EXPECT_EQ("20,50", env->last_mouse_location().ToString()); 1495 EXPECT_EQ("20,50", env->last_mouse_location().ToString());
1470 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); 1496 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
1471 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation()); 1497 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
1472 } 1498 }
1473 1499
1474 // Test that the cursor moves to the other display and that its scale factor 1500 // Test that the cursor moves to the other display and that its scale factor
1475 // and rotation are updated when the primary display is disconnected. 1501 // and rotation are updated when the primary display is disconnected.
1476 TEST_P(WindowTreeHostManagerTest, 1502 TEST_P(WindowTreeHostManagerTest,
1477 UpdateMouseLocationAfterDisplayChange_PrimaryDisconnected) { 1503 UpdateMouseLocationAfterDisplayChange_PrimaryDisconnected) {
1478 if (!SupportsMultipleDisplays()) 1504 if (!SupportsMultipleDisplays())
1479 return; 1505 return;
1480 1506
1481 aura::Env* env = aura::Env::GetInstance(); 1507 aura::Env* env = aura::Env::GetInstance();
1482 Shell* shell = Shell::GetInstance(); 1508 Shell* shell = Shell::GetInstance();
1483 WindowTreeHostManager* window_tree_host_manager = 1509 WindowTreeHostManager* window_tree_host_manager =
1484 shell->window_tree_host_manager(); 1510 shell->window_tree_host_manager();
1485 test::CursorManagerTestApi test_api(shell->cursor_manager()); 1511 test::CursorManagerTestApi test_api(shell->cursor_manager());
1486 1512
1487 UpdateDisplay("300x300*2/r,200x200"); 1513 UpdateDisplay("300x300*2/r,200x200");
1488 // Swap the primary display to make it possible to remove the primary display 1514 // Swap the primary display to make it possible to remove the primary display
1489 // via UpdateDisplay(). 1515 // via UpdateDisplay().
1490 test::SwapPrimaryDisplay(); 1516 SwapPrimaryDisplay();
1491 int primary_display_id = window_tree_host_manager->GetPrimaryDisplayId(); 1517 int primary_display_id = window_tree_host_manager->GetPrimaryDisplayId();
1492 1518
1493 window_tree_host_manager->GetPrimaryRootWindow()->MoveCursorTo( 1519 window_tree_host_manager->GetPrimaryRootWindow()->MoveCursorTo(
1494 gfx::Point(20, 50)); 1520 gfx::Point(20, 50));
1495 1521
1496 EXPECT_EQ("20,50", env->last_mouse_location().ToString()); 1522 EXPECT_EQ("20,50", env->last_mouse_location().ToString());
1497 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); 1523 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
1498 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation()); 1524 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
1499 1525
1500 UpdateDisplay("300x300*2/r"); 1526 UpdateDisplay("300x300*2/r");
1501 ASSERT_NE(primary_display_id, 1527 ASSERT_NE(primary_display_id,
1502 window_tree_host_manager->GetPrimaryDisplayId()); 1528 window_tree_host_manager->GetPrimaryDisplayId());
1503 1529
1504 // Cursor should be centered on the remaining display. 1530 // Cursor should be centered on the remaining display.
1505 EXPECT_EQ("75,75", env->last_mouse_location().ToString()); 1531 EXPECT_EQ("75,75", env->last_mouse_location().ToString());
1506 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); 1532 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
1507 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation()); 1533 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
1508 } 1534 }
1509 1535
1510 // GetRootWindowForDisplayId() for removed display::Display during 1536 // GetRootWindowForDisplayId() for removed display::Display during
1511 // OnDisplayRemoved() should not cause crash. See http://crbug.com/415222 1537 // OnDisplayRemoved() should not cause crash. See http://crbug.com/415222
1512 TEST_P(WindowTreeHostManagerTest, 1538 TEST_P(WindowTreeHostManagerTest,
1513 GetRootWindowForDisplayIdDuringDisplayDisconnection) { 1539 GetRootWindowForDisplayIdDuringDisplayDisconnection) {
1514 if (!SupportsMultipleDisplays()) 1540 if (!SupportsMultipleDisplays())
1515 return; 1541 return;
1516 1542
1517 UpdateDisplay("300x300,200x200"); 1543 UpdateDisplay("300x300,200x200");
1518 aura::Window* root2 = 1544 aura::Window* root2 = Shell::GetInstance()
1519 Shell::GetInstance() 1545 ->window_tree_host_manager()
1520 ->window_tree_host_manager() 1546 ->GetRootWindowForDisplayId(
1521 ->GetRootWindowForDisplayId(ScreenUtil::GetSecondaryDisplay().id()); 1547 display_manager()->GetSecondaryDisplay().id());
1522 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( 1548 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
1523 nullptr, root2, gfx::Rect(350, 0, 100, 100)); 1549 nullptr, root2, gfx::Rect(350, 0, 100, 100));
1524 views::View* view = new views::View(); 1550 views::View* view = new views::View();
1525 widget->GetContentsView()->AddChildView(view); 1551 widget->GetContentsView()->AddChildView(view);
1526 view->SetBounds(0, 0, 100, 100); 1552 view->SetBounds(0, 0, 100, 100);
1527 widget->Show(); 1553 widget->Show();
1528 1554
1529 TestMouseWatcherListener listener; 1555 TestMouseWatcherListener listener;
1530 views::MouseWatcher watcher( 1556 views::MouseWatcher watcher(
1531 new views::MouseWatcherViewHost(view, gfx::Insets()), &listener); 1557 new views::MouseWatcherViewHost(view, gfx::Insets()), &listener);
1532 watcher.Start(); 1558 watcher.Start();
1533 1559
1534 ui::test::EventGenerator event_generator( 1560 ui::test::EventGenerator event_generator(
1535 widget->GetNativeWindow()->GetRootWindow()); 1561 widget->GetNativeWindow()->GetRootWindow());
1536 event_generator.MoveMouseToCenterOf(widget->GetNativeWindow()); 1562 event_generator.MoveMouseToCenterOf(widget->GetNativeWindow());
1537 1563
1538 UpdateDisplay("300x300"); 1564 UpdateDisplay("300x300");
1539 watcher.Stop(); 1565 watcher.Stop();
1540 1566
1541 widget->CloseNow(); 1567 widget->CloseNow();
1542 } 1568 }
1543 1569
1544 } // namespace ash 1570 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/window_tree_host_manager.cc ('k') | ash/extended_desktop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698