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

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: rebase 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
« no previous file with comments | « ash/display/display_controller.cc ('k') | ash/display/display_info.h » ('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/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 73
71 void SetSecondaryDisplayLayout(DisplayLayout::Position position) { 74 void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
72 SetSecondaryDisplayLayoutAndOffset(position, 0); 75 SetSecondaryDisplayLayoutAndOffset(position, 0);
73 } 76 }
74 77
75 class DisplayControllerShutdownTest : public test::AshTestBase { 78 class DisplayControllerShutdownTest : public test::AshTestBase {
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 = Shell::GetScreen()->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, Shell::GetScreen()->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
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 #if defined(OS_WIN)
574 // TODO(oshima): Windows does not supoprts insets.
575 #define MAYBE_OverscanInsets DISABLED_OverscanInsets
576 #else
577 #define MAYBE_OverscanInsets OverscanInsets
578 #endif
579
580 TEST_F(DisplayControllerTest, MAYBE_OverscanInsets) {
581 DisplayController* display_controller =
582 Shell::GetInstance()->display_controller();
583 TestEventHandler event_handler;
584 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
585
586 UpdateDisplay("120x200,300x400*2");
587 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
588 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
589
590 display_controller->SetOverscanInsets(display1.id(),
591 gfx::Insets(10, 15, 20, 25));
592 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString());
593 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
594 EXPECT_EQ("80,0 150x200",
595 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
596
597 aura::test::EventGenerator generator(root_windows[0]);
598 generator.MoveMouseTo(20, 25);
599 EXPECT_EQ("5,15", event_handler.GetLocationAndReset());
600
601 display_controller->ClearCustomOverscanInsets(display1.id());
602 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString());
603 EXPECT_EQ("120,0 150x200",
604 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
605
606 generator.MoveMouseTo(30, 20);
607 EXPECT_EQ("30,20", event_handler.GetLocationAndReset());
608
609 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
610 }
611
612 #if defined(OS_WIN)
613 // On Win8 bots, the host window can't be resized and
614 // SetTransform updates the window using the orignal host window
615 // size.
616 #define MAYBE_Rotate DISABLED_Rotate
617 #else
618 #define MAYBE_Rotate Rotate
619 #endif
620
621 TEST_F(DisplayControllerTest, MAYBE_Rotate) {
622 DisplayController* display_controller =
623 Shell::GetInstance()->display_controller();
624 internal::DisplayManager* display_manager =
625 Shell::GetInstance()->display_manager();
626 TestEventHandler event_handler;
627 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
628
629 UpdateDisplay("120x200,300x400*2");
630 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
631 int64 display2_id = ScreenAsh::GetSecondaryDisplay().id();
632 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
633 aura::test::EventGenerator generator1(root_windows[0]);
634
635 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
636 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
637 EXPECT_EQ("120,0 150x200",
638 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
639 generator1.MoveMouseTo(50, 40);
640 EXPECT_EQ("50,40", event_handler.GetLocationAndReset());
641
642 display_manager->SetDisplayRotation(display1.id(),
643 internal::DisplayInfo::ROTATE_90);
644 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
645 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
646 EXPECT_EQ("200,0 150x200",
647 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
648 generator1.MoveMouseTo(50, 40);
649 EXPECT_EQ("40,70", event_handler.GetLocationAndReset());
650
651 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50);
652 display_controller->SetLayoutForCurrentDisplays(display_layout);
653 EXPECT_EQ("50,120 150x200",
654 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
655
656 display_manager->SetDisplayRotation(display2_id,
657 internal::DisplayInfo::ROTATE_270);
658 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
659 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
660 EXPECT_EQ("50,120 200x150",
661 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
662
663 aura::test::EventGenerator generator2(root_windows[1]);
664 generator2.MoveMouseTo(50, 40);
665 EXPECT_EQ("180,25", event_handler.GetLocationAndReset());
666 display_manager->SetDisplayRotation(display1.id(),
667 internal::DisplayInfo::ROTATE_180);
668
669 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
670 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
671 // Dislay must share at least 100, so the x's offset becomes 20.
672 EXPECT_EQ("20,200 200x150",
673 ScreenAsh::GetSecondaryDisplay().bounds().ToString());
674
675 generator1.MoveMouseTo(50, 40);
676 EXPECT_EQ("70,160", event_handler.GetLocationAndReset());
677
678 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
679 }
680
540 } // namespace test 681 } // namespace test
541 } // namespace ash 682 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.cc ('k') | ash/display/display_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698