Index: ash/display/display_controller_unittest.cc |
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc |
index f1eb85914efce8e0c7a8a416cc51c5bb9cd30ebf..f99b49c3570d3b472306b242a2e5b386f6c183a9 100644 |
--- a/ash/display/display_controller_unittest.cc |
+++ b/ash/display/display_controller_unittest.cc |
@@ -4,6 +4,7 @@ |
#include "ash/display/display_controller.h" |
+#include "ash/display/display_info.h" |
#include "ash/display/display_manager.h" |
#include "ash/launcher/launcher.h" |
#include "ash/screen_ash.h" |
@@ -12,7 +13,9 @@ |
#include "ash/test/cursor_manager_test_api.h" |
#include "ui/aura/env.h" |
#include "ui/aura/root_window.h" |
+#include "ui/aura/test/event_generator.h" |
#include "ui/aura/window_tracker.h" |
+#include "ui/base/events/event_handler.h" |
#include "ui/gfx/display.h" |
#include "ui/gfx/screen.h" |
#include "ui/views/widget/widget.h" |
@@ -76,12 +79,42 @@ class DisplayControllerShutdownTest : public test::AshTestBase { |
virtual void TearDown() OVERRIDE { |
test::AshTestBase::TearDown(); |
// Make sure that primary display is accessible after shutdown. |
- gfx::Display primary = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
+ gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay(); |
EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); |
- EXPECT_EQ(2, gfx::Screen::GetNativeScreen()->GetNumDisplays()); |
+ EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
} |
}; |
+class TestEventHandler : public ui::EventHandler { |
+ public: |
+ TestEventHandler() : target_root_(NULL) {} |
+ virtual ~TestEventHandler() {} |
+ |
+ virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
+ aura::Window* target = static_cast<aura::Window*>(event->target()); |
+ // Only record when the target is the background which covers |
+ // entire root window. |
+ if (target->name() != "DesktopBackgroundView") |
+ return; |
+ mouse_location_ = event->location(); |
+ target_root_ = target->GetRootWindow(); |
+ event->StopPropagation(); |
+ } |
+ |
+ std::string GetLocationAndReset() { |
+ std::string result = mouse_location_.ToString(); |
+ mouse_location_.SetPoint(0, 0); |
+ target_root_ = NULL; |
+ return result; |
+ } |
+ |
+ private: |
+ gfx::Point mouse_location_; |
+ aura::RootWindow* target_root_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
+}; |
+ |
} // namespace |
typedef test::AshTestBase DisplayControllerTest; |
@@ -536,5 +569,113 @@ TEST_F(DisplayControllerTest, MAYBE_UpdateDisplayWithHostOrigin) { |
EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); |
} |
+#if defined(OS_WIN) |
+// TODO(oshima): Windows does not supoprts insets. |
+#define MAYBE_OverscanInsets DISABLED_OverscanInsets |
+#else |
+#define MAYBE_OverscanInsets OverscanInsets |
+#endif |
+ |
+TEST_F(DisplayControllerTest, MAYBE_OverscanInsets) { |
+ DisplayController* display_controller = |
+ Shell::GetInstance()->display_controller(); |
+ TestEventHandler event_handler; |
+ Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
+ |
+ UpdateDisplay("120x200,300x400*2"); |
+ gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
+ |
+ display_controller->SetOverscanInsets(display1.id(), |
+ gfx::Insets(10, 15, 20, 25)); |
+ EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString()); |
+ EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
+ EXPECT_EQ("80,0 150x200", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ |
+ aura::test::EventGenerator generator(root_windows[0]); |
+ generator.MoveMouseTo(20, 25); |
+ EXPECT_EQ("5,15", event_handler.GetLocationAndReset()); |
+ |
+ display_controller->ClearCustomOverscanInsets(display1.id()); |
+ EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString()); |
+ EXPECT_EQ("120,0 150x200", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ |
+ generator.MoveMouseTo(30, 20); |
+ EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); |
+ |
+ Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
+} |
+ |
+#if defined(OS_WIN) |
+// On Win8 bots, the host window can't be resized and |
+// SetTransform updates the window using the orignal host window |
+// size. |
+#define MAYBE_Rotate DISABLED_Rotate |
+#else |
+#define MAYBE_Rotate Rotate |
+#endif |
+ |
+TEST_F(DisplayControllerTest, MAYBE_Rotate) { |
+ DisplayController* display_controller = |
+ Shell::GetInstance()->display_controller(); |
+ internal::DisplayManager* display_manager = |
+ Shell::GetInstance()->display_manager(); |
+ TestEventHandler event_handler; |
+ Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
+ |
+ UpdateDisplay("120x200,300x400*2"); |
+ gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
+ int64 display2_id = ScreenAsh::GetSecondaryDisplay().id(); |
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
+ aura::test::EventGenerator generator1(root_windows[0]); |
+ |
+ EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
+ EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
+ EXPECT_EQ("120,0 150x200", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ generator1.MoveMouseTo(50, 40); |
+ EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); |
+ |
+ display_manager->SetDisplayRotation(display1.id(), |
+ internal::DisplayInfo::Rotate90); |
+ EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
+ EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
+ EXPECT_EQ("200,0 150x200", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ generator1.MoveMouseTo(50, 40); |
+ EXPECT_EQ("40,70", event_handler.GetLocationAndReset()); |
+ |
+ DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); |
+ display_controller->SetLayoutForCurrentDisplays(display_layout); |
+ EXPECT_EQ("50,120 150x200", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ |
+ display_manager->SetDisplayRotation(display2_id, |
+ internal::DisplayInfo::Rotate270); |
+ EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
+ EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
+ EXPECT_EQ("50,120 200x150", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ |
+ aura::test::EventGenerator generator2(root_windows[1]); |
+ generator2.MoveMouseTo(50, 40); |
+ EXPECT_EQ("180,25", event_handler.GetLocationAndReset()); |
+ display_manager->SetDisplayRotation(display1.id(), |
+ internal::DisplayInfo::Rotate180); |
+ |
+ EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
+ EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
+ // Dislay must share at least 100, so the x's offset becomes 20. |
+ EXPECT_EQ("20,200 200x150", |
+ ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
+ |
+ generator1.MoveMouseTo(50, 40); |
+ EXPECT_EQ("70,160", event_handler.GetLocationAndReset()); |
+ |
+ Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
+} |
+ |
} // namespace test |
} // namespace ash |