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

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

Powered by Google App Engine
This is Rietveld 408576698