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

Unified Diff: chrome/browser/extensions/api/system_info_display/display_info_provider_chromeos_unittest.cc

Issue 16817006: Add ability to change display settings to chrome.systemInfo.display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: increased max bounds origin Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/system_info_display/display_info_provider_chromeos_unittest.cc
diff --git a/chrome/browser/extensions/api/system_info_display/display_info_provider_chromeos_unittest.cc b/chrome/browser/extensions/api/system_info_display/display_info_provider_chromeos_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..61cd2700e14fe02158dcc514e6ffc640fe95d464
--- /dev/null
+++ b/chrome/browser/extensions/api/system_info_display/display_info_provider_chromeos_unittest.cc
@@ -0,0 +1,939 @@
+// Copyright (c) 2013 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 "chrome/browser/extensions/api/system_info_display/display_info_provider.h"
+
+#include "ash/display/display_controller.h"
+#include "ash/display/display_manager.h"
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/test/display_manager_test_api.h"
+#include "base/strings/string_number_conversions.h"
+#include "ui/gfx/display.h"
+#include "ui/gfx/rect.h"
+
+namespace extensions {
+namespace {
+
+void BindRequestDisplayInfoResult(DisplayInfo* target,
+ const DisplayInfo& result,
+ bool success) {
+ ASSERT_TRUE(success);
+ *target = result;
+}
+
+void BindSetDisplayUnitInfoResult(bool* success,
+ std::string* error,
+ bool success_in,
+ const std::string& error_in) {
+ *success = success_in;
+ *error = error_in;
+}
+
+class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase {
+ public:
+ DisplayInfoProviderChromeosTest() {}
+
+ virtual ~DisplayInfoProviderChromeosTest() {}
+
+ protected:
+ void CallRequestDisplayInfo(DisplayInfo* result) {
+ DisplayInfoProvider::GetProvider()->RequestInfo(
+ base::Bind(&BindRequestDisplayInfoResult, result));
+ RunAllPendingInMessageLoop();
+ }
+
+ void CallSetDisplayUnitInfo(
+ const std::string& display_id,
+ const api::system_info_display::SetDisplayUnitInfoParams& params,
+ bool* success,
+ std::string* error) {
+ DisplayInfoProvider::GetProvider()->SetInfo(display_id, params,
+ base::Bind(&BindSetDisplayUnitInfoResult, success, error));
+ RunAllPendingInMessageLoop();
+ }
+
+ bool DisplayExists(int64 display_id) {
+ const gfx::Display& display =
+ GetDisplayManager()->GetDisplayForId(display_id);
+ return display.id() != gfx::Display::kInvalidDisplayID;
+ }
+
+ ash::internal::DisplayManager* GetDisplayManager() {
+ return ash::Shell::GetInstance()->display_manager();
+ }
+
+ ash::DisplayController* GetDisplayController() {
+ return ash::Shell::GetInstance()->display_controller();
+ }
+
+ void ExpectBoundsEqual(const gfx::Rect& expected,
+ const api::system_info_display::Bounds& bounds,
+ const std::string& message) {
+ EXPECT_EQ(expected.x(), bounds.left) << message;
+ EXPECT_EQ(expected.y(), bounds.top) << message;
+ EXPECT_EQ(expected.width(), bounds.width) << message;
+ EXPECT_EQ(expected.height(), bounds.height) << message;
+ }
+
+ void ExpectRectEquals(const gfx::Rect& expected,
+ const gfx::Rect& value) {
+ EXPECT_EQ(expected.x(), value.x());
+ EXPECT_EQ(expected.y(), value.y());
+ EXPECT_EQ(expected.width(), value.width());
+ EXPECT_EQ(expected.height(), value.height());
+ }
+
+ void ExpectInsetsEqual(const gfx::Insets& expected,
+ const api::system_info_display::Insets& insets,
+ const std::string& message) {
+ EXPECT_EQ(expected.left(), insets.left) << message;
+ EXPECT_EQ(expected.top(), insets.top) << message;
+ EXPECT_EQ(expected.right(), insets.right) << message;
+ EXPECT_EQ(expected.bottom(), insets.bottom) << message;
+
+ }
+};
+
+TEST_F(DisplayInfoProviderChromeosTest, GetBasic) {
+ UpdateDisplay("500x600,400x520");
+ DisplayInfo result;
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ int64 display_id;
+ ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id))
+ << "Display id must be convertable to integer: " << result[0]->id;
+
+ ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
+ ExpectBoundsEqual(gfx::Rect(0, 0, 500, 600), result[0]->bounds,
+ "Display 0 bounds");
+ ExpectInsetsEqual(gfx::Insets(0, 0, 0 , 0), result[0]->overscan,
+ "Display 0 overscan");
+ EXPECT_EQ(0, result[0]->rotation);
+ EXPECT_TRUE(result[0]->is_primary);
+ EXPECT_EQ(96, result[0]->dpi_x);
+ EXPECT_EQ(96, result[0]->dpi_y);
+ EXPECT_TRUE(result[0]->mirroring_source_id.empty());
+ EXPECT_TRUE(result[0]->is_enabled);
+
+ ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id))
+ << "Display id must be convertable to integer: " << result[0]->id;
+
+ ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
+ EXPECT_EQ(GetDisplayManager()->GetDisplayNameForId(display_id),
+ result[1]->name);
+ // The second display is positioned left of the primary display, whose width
+ // is 500.
+ ExpectBoundsEqual(gfx::Rect(500, 0, 400, 520), result[1]->bounds,
+ "Display 1 bounds");
+ ExpectInsetsEqual(gfx::Insets(0, 0, 0 , 0), result[1]->overscan,
+ "Display 1 overscan");
+ EXPECT_EQ(0, result[1]->rotation);
+ EXPECT_FALSE(result[1]->is_primary);
+ EXPECT_EQ(96, result[1]->dpi_x);
+ EXPECT_EQ(96, result[1]->dpi_y);
+ EXPECT_TRUE(result[1]->mirroring_source_id.empty());
+ EXPECT_TRUE(result[1]->is_enabled);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, GetRotation) {
+ UpdateDisplay("500x600/r");
+ DisplayInfo result;
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(1u, result.size());
+
+ int64 display_id;
+ ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id))
+ << "Display id must be convertable to integer: " << result[0]->id;
+
+ ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
+ ExpectBoundsEqual(gfx::Rect(0, 0, 600, 500), result[0]->bounds,
+ "Display 0 bounds");
+ EXPECT_EQ(90, result[0]->rotation);
+
+ GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_270);
+
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(1u, result.size());
+
+ EXPECT_EQ(base::Int64ToString(display_id), result[0]->id);
+ ExpectBoundsEqual(gfx::Rect(0, 0, 600, 500), result[0]->bounds,
+ "Display 0 bounds");
+ EXPECT_EQ(270, result[0]->rotation);
+
+ GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_180);
+
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(1u, result.size());
+
+ EXPECT_EQ(base::Int64ToString(display_id), result[0]->id);
+ ExpectBoundsEqual(gfx::Rect(0, 0, 500, 600), result[0]->bounds,
+ "Display 0 bounds");
+ EXPECT_EQ(180, result[0]->rotation);
+
+ GetDisplayManager()->SetDisplayRotation(display_id, gfx::Display::ROTATE_0);
+
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(1u, result.size());
+
+ EXPECT_EQ(base::Int64ToString(display_id), result[0]->id);
+ ExpectBoundsEqual(gfx::Rect(0, 0, 500, 600), result[0]->bounds,
+ "Display 0 bounds");
+ EXPECT_EQ(0, result[0]->rotation);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, GetHiDPI) {
+ UpdateDisplay("500x600,400x520*2");
+ DisplayInfo result;
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ ExpectBoundsEqual(gfx::Rect(0, 0, 500, 600), result[0]->bounds,
+ "Display 0 bounds");
+ EXPECT_EQ(96, result[0]->dpi_x);
+ EXPECT_EQ(96, result[0]->dpi_y);
+
+ ExpectBoundsEqual(gfx::Rect(500, 0, 200, 260), result[1]->bounds,
+ "Display 1 bounds");
+ EXPECT_EQ(2 * 96, result[1]->dpi_x);
+ EXPECT_EQ(2 * 96, result[1]->dpi_y);
+
+ GetDisplayController()->SwapPrimaryDisplay();
+
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ ExpectBoundsEqual(gfx::Rect(-500, 0, 500, 600), result[0]->bounds,
+ "Display 0 bounds after primary swap");
+ EXPECT_EQ(96, result[0]->dpi_x);
+ EXPECT_EQ(96, result[0]->dpi_y);
+
+ ExpectBoundsEqual(gfx::Rect(0, 0, 200, 260), result[1]->bounds,
+ "Display 1 bounds after primary swap");
+ EXPECT_EQ(2 * 96, result[1]->dpi_x);
+ EXPECT_EQ(2 * 96, result[1]->dpi_y);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, GetVisibleArea) {
+ UpdateDisplay("640x720*2/o, 400x520/o");
+ DisplayInfo result;
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ int64 display_id;
+ ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id))
+ << "Display id must be convertable to integer: " << result[1]->id;
+ ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
+
+ // Default overscan is 5%.
+ ExpectBoundsEqual(gfx::Rect(304, 0, 380, 494), result[1]->bounds,
+ "Display 1.1 bounds");
+ ExpectInsetsEqual(gfx::Insets(13, 10, 13 , 10), result[1]->overscan,
+ "Display 1.1 overscan");
+
+ GetDisplayManager()->SetOverscanInsets(display_id,
+ gfx::Insets(20, 30, 50, 60));
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ EXPECT_EQ(base::Int64ToString(display_id), result[1]->id);
+ ExpectBoundsEqual(gfx::Rect(304, 0, 310, 450), result[1]->bounds,
+ "Display 1.2 bounds");
+ ExpectInsetsEqual(gfx::Insets(20, 30, 50 , 60), result[1]->overscan,
+ "Display 1.2 overscan");
+
+ // Set insets for the primary screen. Note that it has 2x scale.
+ ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id))
+ << "Display id must be convertable to integer: " << result[0]->id;
+ ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
+
+ ExpectBoundsEqual(gfx::Rect(0, 0, 304, 342), result[0]->bounds,
+ "Display 0.1 bounds");
+ ExpectInsetsEqual(gfx::Insets(9, 8, 9 , 8), result[0]->overscan,
+ "Display 0.1 overscan");
+
+ GetDisplayManager()->SetOverscanInsets(display_id,
+ gfx::Insets(10, 20, 30, 40));
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ EXPECT_EQ(base::Int64ToString(display_id), result[0]->id);
+ ExpectBoundsEqual(gfx::Rect(0, 0, 260, 320), result[0]->bounds,
+ "Display 0.2 bounds");
+ ExpectInsetsEqual(gfx::Insets(10, 20, 30 , 40), result[0]->overscan,
+ "Display 0.2 overscan");
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, GetMirroring) {
+ UpdateDisplay("600x600, 400x520/o");
+ DisplayInfo result;
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+
+ int64 display_id_primary;
+ ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id_primary))
+ << "Display id must be convertable to integer: " << result[0]->id;
+ ASSERT_TRUE(DisplayExists(display_id_primary))
+ << display_id_primary << " not found";
+
+ int64 display_id_secondary;
+ ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id_secondary))
+ << "Display id must be convertable to integer: " << result[1]->id;
+ ASSERT_TRUE(DisplayExists(display_id_secondary))
+ << display_id_secondary << " not found";
+
+ ASSERT_FALSE(GetDisplayManager()->IsMirrored());
+ EXPECT_TRUE(result[0]->mirroring_source_id.empty());
+ EXPECT_TRUE(result[1]->mirroring_source_id.empty());
+
+ GetDisplayManager()->SetMirrorMode(true);
+ ASSERT_TRUE(GetDisplayManager()->IsMirrored());
+
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(1u, result.size());
+ EXPECT_EQ(base::Int64ToString(display_id_primary), result[0]->id);
+ EXPECT_EQ(base::Int64ToString(display_id_secondary),
+ result[0]->mirroring_source_id);
+
+ GetDisplayManager()->SetMirrorMode(false);
+ ASSERT_FALSE(GetDisplayManager()->IsMirrored());
+
+ CallRequestDisplayInfo(&result);
+
+ ASSERT_EQ(2u, result.size());
+ EXPECT_EQ(base::Int64ToString(display_id_primary), result[0]->id);
+ EXPECT_TRUE(result[0]->mirroring_source_id.empty());
+ EXPECT_EQ(base::Int64ToString(display_id_secondary),result[1]->id);
+ EXPECT_TRUE(result[1]->mirroring_source_id.empty());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, GetBounds) {
+ UpdateDisplay("600x600, 400x520");
+ GetDisplayController()->SetLayoutForCurrentDisplays(
+ ash::DisplayLayout::FromInts(ash::DisplayLayout::LEFT, -40));
+
+ DisplayInfo result;
+ CallRequestDisplayInfo(&result);
+ ASSERT_EQ(2u, result.size());
+ ExpectBoundsEqual(gfx::Rect(0, 0, 600, 600), result[0]->bounds,
+ "Display 0 bounds");
+ ExpectBoundsEqual(gfx::Rect(-400, -40, 400, 520), result[1]->bounds,
+ "Display 1 bounds");
+
+ GetDisplayController()->SetLayoutForCurrentDisplays(
+ ash::DisplayLayout::FromInts(ash::DisplayLayout::TOP, 40));
+
+ CallRequestDisplayInfo(&result);
+ ASSERT_EQ(2u, result.size());
+ ExpectBoundsEqual(gfx::Rect(0, 0, 600, 600), result[0]->bounds,
+ "Display 0 bounds");
+ ExpectBoundsEqual(gfx::Rect(40, -520, 400, 520), result[1]->bounds,
+ "Display 1 bounds");
+
+ GetDisplayController()->SetLayoutForCurrentDisplays(
+ ash::DisplayLayout::FromInts(ash::DisplayLayout::BOTTOM, 80));
+
+ CallRequestDisplayInfo(&result);
+ ASSERT_EQ(2u, result.size());
+ ExpectBoundsEqual(gfx::Rect(0, 0, 600, 600), result[0]->bounds,
+ "Display 0 bounds");
+ ExpectBoundsEqual(gfx::Rect(80, 600, 400, 520), result[1]->bounds,
+ "Display 1 bounds");
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftExact) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(-520));
+ params.bounds_origin_y.reset(new int(50));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(-520, 50, 520, 400), secondary->bounds());
oshima 2013/06/13 19:12:40 Just FYI: following pattern makes it easy to read
tbarzic 2013/06/13 20:58:15 ok, changing to this pattern..
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginRightExact) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(1200));
+ params.bounds_origin_y.reset(new int(100));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 100, 520, 400), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopExact) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(1100));
+ params.bounds_origin_y.reset(new int(-400));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1100, -400, 520, 400), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginBottomExact) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(-350));
+ params.bounds_origin_y.reset(new int(600));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(-350, 600, 520, 400), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSameCenter) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(340));
+ params.bounds_origin_y.reset(new int(100));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 100, 520, 400), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftOutside) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(-1040));
+ params.bounds_origin_y.reset(new int(100));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(-520, 100, 520, 400), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopOutside) {
+ UpdateDisplay("1200x600,520x400");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(-360));
+ params.bounds_origin_y.reset(new int(-301));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(-360, -400, 520, 400), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest,
+ SetBoundsOriginLeftButSharesBottomSide) {
+ UpdateDisplay("1200x600,1000x100");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(-650));
+ params.bounds_origin_y.reset(new int(700));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(-650, 600, 1000, 100), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest,
+ SetBoundsOriginRightButSharesTopSide) {
+ UpdateDisplay("1200x600,1000x100");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(850));
+ params.bounds_origin_y.reset(new int(-150));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(850, -100, 1000, 100), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest,
+ SetBoundsOriginTopButSharesLeftSide) {
+ UpdateDisplay("1200x600,1000x100/l");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(-150));
+ params.bounds_origin_y.reset(new int(-650));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(-100, -650, 100, 1000), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest,
+ SetBoundsOriginBottomButSharesRightSide) {
+ UpdateDisplay("1200x600,1000x100/l");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(1350));
+ params.bounds_origin_y.reset(new int(450));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 450, 100, 1000), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginPrimaryHiDPI) {
+ UpdateDisplay("1200x600*2,500x500");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(250));
+ params.bounds_origin_y.reset(new int(-100));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(600, -100, 500, 500), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSecondaryHiDPI) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(450));
+ params.bounds_origin_y.reset(new int(-100));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(450, -500, 300, 500), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBounds) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(0x200001));
+ params.bounds_origin_y.reset(new int(-100));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ ASSERT_EQ("Bounds origin x out of bounds.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBoundsNegative) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(300));
+ params.bounds_origin_y.reset(new int(-0x200001));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ ASSERT_EQ("Bounds origin y out of bounds.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginMaxValues) {
+ UpdateDisplay("1200x4600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(200000));
+ params.bounds_origin_y.reset(new int(10));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 10, 300, 500), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOnPrimary) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(300));
+ params.is_primary.reset(new bool(true));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ ASSERT_EQ("Bounds origin not allowed for the primary display.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+ // The operation failed because the primary property would be set before
+ // setting bounds. The primary display shouldn't have been changed, though.
+ EXPECT_NE(ash::DisplayController::GetPrimaryDisplay().id(), secondary->id());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginWithMirroring) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ const gfx::Display& primary = GetDisplayController()->GetPrimaryDisplay();
+
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.bounds_origin_x.reset(new int(300));
+ params.mirroring_source_id.reset(
+ new std::string(base::Int64ToString(primary.id())));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ ASSERT_EQ("No other parameter should be set alongside mirroringSourceId.",
+ error);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetRotation) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.rotation.reset(new int(90));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 500, 300), secondary->bounds());
+ EXPECT_EQ(gfx::Display::ROTATE_90, secondary->rotation());
+
+ params.rotation.reset(new int(270));
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 500, 300), secondary->bounds());
+ EXPECT_EQ(gfx::Display::ROTATE_270, secondary->rotation());
+
+ params.rotation.reset(new int(180));
+ // Switch primary display.
+ params.is_primary.reset(new bool(true));
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(0, 0, 300, 500), secondary->bounds());
+ EXPECT_EQ(gfx::Display::ROTATE_180, secondary->rotation());
+ EXPECT_EQ(ash::DisplayController::GetPrimaryDisplay().id(), secondary->id());
+
+ params.rotation.reset(new int(0));
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(0, 0, 300, 500), secondary->bounds());
+ EXPECT_EQ(gfx::Display::ROTATE_0, secondary->rotation());
+ EXPECT_EQ(ash::DisplayController::GetPrimaryDisplay().id(), secondary->id());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.rotation.reset(new int(91));
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Invalid rotation.", error);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetNegativeOverscan) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.overscan.reset(new api::system_info_display::Insets);
+ params.overscan->left= -10;
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Negative overscan not allowed.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+
+ params.overscan->left= 0;
+ params.overscan->right = -200;
+
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Negative overscan not allowed.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+
+ params.overscan->right= 0;
+ params.overscan->top = -300;
+
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Negative overscan not allowed.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+
+ params.overscan->right= 0;
+ params.overscan->top = -1000;
+
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Negative overscan not allowed.", error);
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+
+ params.overscan->right= 0;
+ params.overscan->top = 0;
+
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 300, 500), secondary->bounds());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanHorizontalBounds) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.overscan.reset(new api::system_info_display::Insets);
+ // Horizontal overscan is 151, which would make the bounds width 149.
+ params.overscan->left= 50;
+ params.overscan->top = 10;
+ params.overscan->right = 101;
+ params.overscan->bottom = 20;
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Horizontal overscan is more than half of the screen width.",
+ error);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanVerticalBounds) {
+ UpdateDisplay("1200x600,600x1000");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.overscan.reset(new api::system_info_display::Insets);
+ // Vertical overscan is 501, which would make the bounds height 499.
+ params.overscan->left= 20;
+ params.overscan->top = 250;
+ params.overscan->right = 101;
+ params.overscan->bottom = 251;
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Vertical overscan is more than half of the screen height.",
+ error);
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetOverscan) {
+ UpdateDisplay("1200x600,600x1000*2");
+
+ const gfx::Display* secondary = GetDisplayController()->GetSecondaryDisplay();
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.overscan.reset(new api::system_info_display::Insets);
+ params.overscan->left= 20;
+ params.overscan->top = 199;
+ params.overscan->right = 130;
+ params.overscan->bottom = 51;
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(secondary->id()), params,
+ &success, &error);
+
+ ASSERT_TRUE(success);
+ EXPECT_TRUE(error.empty());
+
+ ExpectRectEquals(gfx::Rect(1200, 0, 150, 250), secondary->bounds());
+ const gfx::Insets overscan =
+ GetDisplayManager()->GetOverscanInsets(secondary->id());
+
+ EXPECT_EQ(20, overscan.left());
+ EXPECT_EQ(199, overscan.top());
+ EXPECT_EQ(130, overscan.right());
+ EXPECT_EQ(51, overscan.bottom());
+}
+
+TEST_F(DisplayInfoProviderChromeosTest, SetOverscanForInternal) {
+ UpdateDisplay("1200x600,600x1000*2");
+ const int64 internal_display_id =
+ ash::test::DisplayManagerTestApi(GetDisplayManager()).
+ SetFirstDisplayAsInternalDisplay();
+
+ api::system_info_display::SetDisplayUnitInfoParams params;
+ params.overscan.reset(new api::system_info_display::Insets);
+ // Vertical overscan is 501, which would make the bounds height 499.
+ params.overscan->left= 20;
+ params.overscan->top = 20;
+ params.overscan->right = 20;
+ params.overscan->bottom = 20;
+
+ bool success = false;
+ std::string error;
+ CallSetDisplayUnitInfo(base::Int64ToString(internal_display_id), params,
+ &success, &error);
+
+ ASSERT_FALSE(success);
+ EXPECT_EQ("Overscan changes not allowed for the internal monitor.",
+ error);
+}
+
+} // namespace
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698