OLD | NEW |
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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
| 7 #include "ash/display/display_info.h" |
7 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
8 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
9 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
10 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
13 #include "ash/test/cursor_manager_test_api.h" | 14 #include "ash/test/cursor_manager_test_api.h" |
14 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/test/event_generator.h" |
16 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
| 19 #include "ui/base/events/event_handler.h" |
17 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
18 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
19 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
20 | 23 |
21 namespace ash { | 24 namespace ash { |
22 namespace test { | 25 namespace test { |
23 namespace { | 26 namespace { |
24 | 27 |
25 class TestObserver : public DisplayController::Observer { | 28 class TestObserver : public DisplayController::Observer { |
26 public: | 29 public: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 public: | 79 public: |
77 virtual void TearDown() OVERRIDE { | 80 virtual void TearDown() OVERRIDE { |
78 test::AshTestBase::TearDown(); | 81 test::AshTestBase::TearDown(); |
79 // Make sure that primary display is accessible after shutdown. | 82 // Make sure that primary display is accessible after shutdown. |
80 gfx::Display primary = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 83 gfx::Display primary = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
81 EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); | 84 EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); |
82 EXPECT_EQ(2, gfx::Screen::GetNativeScreen()->GetNumDisplays()); | 85 EXPECT_EQ(2, gfx::Screen::GetNativeScreen()->GetNumDisplays()); |
83 } | 86 } |
84 }; | 87 }; |
85 | 88 |
| 89 class TestEventHandler : public ui::EventHandler { |
| 90 public: |
| 91 TestEventHandler() : target_root_(NULL) {} |
| 92 virtual ~TestEventHandler() {} |
| 93 |
| 94 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 95 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 96 // Only record when the target is the background which covers |
| 97 // entire root window. |
| 98 if (target->name() != "DesktopBackgroundView") |
| 99 return; |
| 100 mouse_location_ = event->location(); |
| 101 target_root_ = target->GetRootWindow(); |
| 102 event->StopPropagation(); |
| 103 } |
| 104 |
| 105 std::string GetLocationAndReset() { |
| 106 std::string result = mouse_location_.ToString(); |
| 107 mouse_location_.SetPoint(0, 0); |
| 108 target_root_ = NULL; |
| 109 return result; |
| 110 } |
| 111 |
| 112 private: |
| 113 gfx::Point mouse_location_; |
| 114 aura::RootWindow* target_root_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
| 117 }; |
| 118 |
86 } // namespace | 119 } // namespace |
87 | 120 |
88 typedef test::AshTestBase DisplayControllerTest; | 121 typedef test::AshTestBase DisplayControllerTest; |
89 | 122 |
90 TEST_F(DisplayControllerShutdownTest, Shutdown) { | 123 TEST_F(DisplayControllerShutdownTest, Shutdown) { |
91 UpdateDisplay("444x333, 200x200"); | 124 UpdateDisplay("444x333, 200x200"); |
92 } | 125 } |
93 | 126 |
94 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { | 127 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { |
95 TestObserver observer; | 128 TestObserver observer; |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 EXPECT_EQ("300x400", root_windows[1]->GetHostSize().ToString()); | 563 EXPECT_EQ("300x400", root_windows[1]->GetHostSize().ToString()); |
531 | 564 |
532 UpdateDisplay("100+200-100x200,300+500-200x300"); | 565 UpdateDisplay("100+200-100x200,300+500-200x300"); |
533 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 566 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
534 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); | 567 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); |
535 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); | 568 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); |
536 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); | 569 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); |
537 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); | 570 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); |
538 } | 571 } |
539 | 572 |
| 573 TEST_F(DisplayControllerTest, OverscanInsets) { |
| 574 DisplayController* display_controller = |
| 575 Shell::GetInstance()->display_controller(); |
| 576 TestEventHandler event_handler; |
| 577 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 578 |
| 579 UpdateDisplay("120x200,300x400*2"); |
| 580 gfx::Display display1 = |
| 581 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 582 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 583 |
| 584 display_controller->SetOverscanInsets(display1.id(), |
| 585 gfx::Insets(10, 15, 20, 25)); |
| 586 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString()); |
| 587 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
| 588 EXPECT_EQ("80,0 150x200", |
| 589 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 590 |
| 591 aura::test::EventGenerator generator(root_windows[0]); |
| 592 generator.MoveMouseTo(20, 25); |
| 593 EXPECT_EQ("5,15", event_handler.GetLocationAndReset()); |
| 594 |
| 595 display_controller->ClearCustomOverscanInsets(display1.id()); |
| 596 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString()); |
| 597 EXPECT_EQ("120,0 150x200", |
| 598 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 599 |
| 600 generator.MoveMouseTo(30, 20); |
| 601 EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); |
| 602 |
| 603 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 604 } |
| 605 |
| 606 TEST_F(DisplayControllerTest, Rotate) { |
| 607 DisplayController* display_controller = |
| 608 Shell::GetInstance()->display_controller(); |
| 609 internal::DisplayManager* display_manager = |
| 610 Shell::GetInstance()->display_manager(); |
| 611 TestEventHandler event_handler; |
| 612 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 613 |
| 614 UpdateDisplay("120x200,300x400*2"); |
| 615 gfx::Display display1 = |
| 616 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 617 int64 display2_id = ScreenAsh::GetSecondaryDisplay().id(); |
| 618 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 619 aura::test::EventGenerator generator1(root_windows[0]); |
| 620 |
| 621 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
| 622 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
| 623 EXPECT_EQ("120,0 150x200", |
| 624 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 625 generator1.MoveMouseTo(50, 40); |
| 626 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); |
| 627 |
| 628 display_manager->SetDisplayRotation(display1.id(), |
| 629 internal::DisplayInfo::Rotate90); |
| 630 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
| 631 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
| 632 EXPECT_EQ("200,0 150x200", |
| 633 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 634 generator1.MoveMouseTo(50, 40); |
| 635 EXPECT_EQ("40,70", event_handler.GetLocationAndReset()); |
| 636 |
| 637 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); |
| 638 display_controller->SetLayoutForCurrentDisplays(display_layout); |
| 639 EXPECT_EQ("50,120 150x200", |
| 640 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 641 |
| 642 display_manager->SetDisplayRotation(display2_id, |
| 643 internal::DisplayInfo::Rotate270); |
| 644 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
| 645 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
| 646 EXPECT_EQ("50,120 200x150", |
| 647 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 648 |
| 649 aura::test::EventGenerator generator2(root_windows[1]); |
| 650 generator2.MoveMouseTo(50, 40); |
| 651 EXPECT_EQ("180,25", event_handler.GetLocationAndReset()); |
| 652 display_manager->SetDisplayRotation(display1.id(), |
| 653 internal::DisplayInfo::Rotate180); |
| 654 |
| 655 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
| 656 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
| 657 // Dislay must share at least 100, so the x's offset becomes 20. |
| 658 EXPECT_EQ("20,200 200x150", |
| 659 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 660 |
| 661 generator1.MoveMouseTo(50, 40); |
| 662 EXPECT_EQ("70,160", event_handler.GetLocationAndReset()); |
| 663 |
| 664 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 665 } |
| 666 |
540 } // namespace test | 667 } // namespace test |
541 } // namespace ash | 668 } // namespace ash |
OLD | NEW |