Index: ash/monitor/monitor_controller_unittest.cc |
diff --git a/ash/monitor/monitor_controller_unittest.cc b/ash/monitor/monitor_controller_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..16d3545f0f82c12865fc775bf67889ad70644215 |
--- /dev/null |
+++ b/ash/monitor/monitor_controller_unittest.cc |
@@ -0,0 +1,121 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/monitor/monitor_controller.h" |
+ |
+#include "ash/shell.h" |
+#include "ash/test/ash_test_base.h" |
+#include "ui/aura/root_window.h" |
+#include "ui/gfx/display.h" |
+#include "ui/gfx/screen.h" |
+ |
+#include "ui/aura/env.h" |
+#include "ui/aura/monitor_manager.h" |
+ |
+namespace ash { |
+namespace test { |
+namespace { |
+ |
+gfx::Display GetPrimaryDisplay() { |
+ return gfx::Screen::GetDisplayNearestWindow( |
+ Shell::GetAllRootWindows()[0]); |
+} |
+ |
+gfx::Display GetSecondaryDisplay() { |
+ return gfx::Screen::GetDisplayNearestWindow( |
+ Shell::GetAllRootWindows()[1]); |
+} |
+ |
+} // namespace |
+ |
+class MonitorControllerTest : public test::AshTestBase { |
+ public: |
+ MonitorControllerTest() {} |
+ virtual ~MonitorControllerTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ internal::MonitorController::SetExtendedDesktopEnabled(true); |
+ internal::MonitorController::SetVirtualScreenCoordinatesEnabled(true); |
+ AshTestBase::SetUp(); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ AshTestBase::TearDown(); |
+ internal::MonitorController::SetExtendedDesktopEnabled(false); |
+ internal::MonitorController::SetVirtualScreenCoordinatesEnabled(false); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(MonitorControllerTest); |
+}; |
+ |
+TEST_F(MonitorControllerTest, SecondaryDisplayLayout) { |
+ UpdateMonitor("0+0-500x500,0+0-400x400"); |
+ gfx::Display* secondary_display = |
+ aura::Env::GetInstance()->monitor_manager()->GetDisplayAt(1); |
+ gfx::Insets insets(5, 5, 5, 5); |
+ secondary_display->UpdateWorkAreaFromInsets(insets); |
+ |
+ // Default layout is LEFT. |
+ EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
+ |
+ // Layout the secondary display to the bottom of the primary. |
+ Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout( |
+ internal::MonitorController::BOTTOM); |
+ EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
+ |
+ // Layout the secondary display to the left of the primary. |
+ Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout( |
+ internal::MonitorController::LEFT); |
+ EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
+ |
+ // Layout the secondary display to the top of the primary. |
+ Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout( |
+ internal::MonitorController::TOP); |
+ EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); |
+} |
+ |
+TEST_F(MonitorControllerTest, BoundsUpdated) { |
+ Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout( |
+ internal::MonitorController::BOTTOM); |
+ UpdateMonitor("0+0-500x500,0+0-400x400"); |
+ gfx::Display* secondary_display = |
+ aura::Env::GetInstance()->monitor_manager()->GetDisplayAt(1); |
+ gfx::Insets insets(5, 5, 5, 5); |
+ secondary_display->UpdateWorkAreaFromInsets(insets); |
+ |
+ EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
+ |
+ UpdateMonitor("0+0-600x600,0+0-400x400"); |
+ EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("0,600 400x400", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("5,605 390x390", GetSecondaryDisplay().work_area().ToString()); |
+ |
+ UpdateMonitor("0+0-600x600,0+0-500x500"); |
+ EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("0,600 500x500", GetSecondaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("5,605 490x490", GetSecondaryDisplay().work_area().ToString()); |
+ |
+ UpdateMonitor("0+0-600x600"); |
+ EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
+ |
+ UpdateMonitor("0+0-700x700,0+0-1000x1000"); |
+ ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); |
+ EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); |
+ EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); |
+} |
+ |
+} // namespace test |
+} // namespace ash |