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

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

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

Powered by Google App Engine
This is Rietveld 408576698