diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 23:58:32 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-28 23:58:32 +0000 |
commit | 7bb8f443297e0ef3e09c298a58adc6aebdf8a53f (patch) | |
tree | 45fcc9719addee55adb3f3bffffe6fcaa481f99e /ash/display/display_manager_unittest.cc | |
parent | b969b0a804a1278bcb1828b94809b74e2b6f34d4 (diff) | |
download | chromium_src-7bb8f443297e0ef3e09c298a58adc6aebdf8a53f.zip chromium_src-7bb8f443297e0ef3e09c298a58adc6aebdf8a53f.tar.gz chromium_src-7bb8f443297e0ef3e09c298a58adc6aebdf8a53f.tar.bz2 |
Refactor DisplayInfo/Display - 3rd try
This is a first step to fix overscan issue and implement
screen rotation.
* remove bounds_in_pixel from gfx::Display
* promote DisplayInfo to separate class/file
* All display information is now generated in display_change_observer_x11.cc.
almost no X11 depenency in display_manager.cc
(I'll move FindInternalDisplayID out from display_manager.cc once https://codereview.chromium.org/12217120/ is landed)
This makes testing more consistent with real environment.
* Add DisplayManager::ClearCustomOverscanInsets so that
you can reset the insets to default value.
* Removed obsolete AshTestBase::ChangeDisplayConfig
BUG=174721,119268
TEST=covered by test
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=185178
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=185230
Review URL: https://chromiumcodereview.appspot.com/12218045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display/display_manager_unittest.cc')
-rw-r--r-- | ash/display/display_manager_unittest.cc | 221 |
1 files changed, 128 insertions, 93 deletions
diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index 43e2593..b3bba2c 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -8,6 +8,7 @@ #include "ash/screen_ash.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/test/display_manager_test_api.h" #include "base/format_macros.h" #include "base/stringprintf.h" #include "ui/aura/env.h" @@ -65,10 +66,22 @@ class DisplayManagerTest : public test::AshTestBase, return root_window_destroyed_; } + const DisplayInfo& GetDisplayInfo(const gfx::Display& display) { + return display_manager()->GetDisplayInfo(display); + } + + const DisplayInfo& GetDisplayInfoAt(int index) { + return GetDisplayInfo(*display_manager()->GetDisplayAt(index)); + } + const gfx::Display& FindDisplayForId(int64 id) { return display_manager()->FindDisplayForId(id); } + const DisplayInfo& FindDisplayInfoForId(int64 id) { + return GetDisplayInfo(display_manager()->FindDisplayForId(id)); + } + // aura::DisplayObserver overrides: virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { changed_.push_back(display); @@ -110,7 +123,8 @@ TEST_F(DisplayManagerTest, NativeDisplayTest) { EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); // Secondary display is on right. EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString()); - EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString()); + EXPECT_EQ("0,501 400x400", + GetDisplayInfo(added()[0]).bounds_in_pixel().ToString()); reset(); // Delete secondary. @@ -132,7 +146,8 @@ TEST_F(DisplayManagerTest, NativeDisplayTest) { EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); // Secondary display is on right. EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString()); - EXPECT_EQ("1002,0 600x400", added()[0].bounds_in_pixel().ToString()); + EXPECT_EQ("1002,0 600x400", + GetDisplayInfo(added()[0]).bounds_in_pixel().ToString()); reset(); // Secondary removed, primary changed. @@ -144,7 +159,7 @@ TEST_F(DisplayManagerTest, NativeDisplayTest) { reset(); // # of display can go to zero when screen is off. - const vector<gfx::Display> empty; + const vector<DisplayInfo> empty; display_manager()->OnNativeDisplaysChanged(empty); EXPECT_EQ(1U, display_manager()->GetNumDisplays()); EXPECT_EQ("0 0 0", GetCountSummary()); @@ -160,7 +175,8 @@ TEST_F(DisplayManagerTest, NativeDisplayTest) { EXPECT_EQ("1 0 0", GetCountSummary()); EXPECT_FALSE(root_window_destroyed()); EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString()); - EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString()); + EXPECT_EQ("100,100 500x400", + GetDisplayInfo(changed()[0]).bounds_in_pixel().ToString()); reset(); // Go back to zero and wake up with multiple displays. @@ -178,7 +194,7 @@ TEST_F(DisplayManagerTest, NativeDisplayTest) { EXPECT_EQ("1000,0 600x400", display_manager()->GetDisplayAt(1)->bounds().ToString()); EXPECT_EQ("1000,1000 600x400", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); reset(); } @@ -207,74 +223,75 @@ TEST_F(DisplayManagerTest, OverscanInsetsTest) { UpdateDisplay("0+0-500x500,0+501-400x400"); reset(); ASSERT_EQ(2u, display_manager()->GetNumDisplays()); - gfx::Display display1(*display_manager()->GetDisplayAt(0)); - gfx::Display display2(*display_manager()->GetDisplayAt(1)); - + const DisplayInfo& display_info1 = GetDisplayInfoAt(0); + const DisplayInfo& display_info2 = GetDisplayInfoAt(1); display_manager()->SetOverscanInsets( - display2.id(), gfx::Insets(13, 12, 11, 10)); + display_info2.id(), gfx::Insets(13, 12, 11, 10)); + std::vector<gfx::Display> changed_displays = changed(); EXPECT_EQ(1u, changed_displays.size()); - EXPECT_EQ(display2.id(), changed_displays[0].id()); + EXPECT_EQ(display_info2.id(), changed_displays[0].id()); EXPECT_EQ("0,0 500x500", - display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(0).bounds_in_pixel().ToString()); EXPECT_EQ("12,514 378x376", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); // Make sure that SetOverscanInsets() is idempotent. - display_manager()->SetOverscanInsets(display1.id(), gfx::Insets()); + display_manager()->SetOverscanInsets(display_info1.id(), gfx::Insets()); display_manager()->SetOverscanInsets( - display2.id(), gfx::Insets(13, 12, 11, 10)); + display_info2.id(), gfx::Insets(13, 12, 11, 10)); EXPECT_EQ("0,0 500x500", - display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(0).bounds_in_pixel().ToString()); EXPECT_EQ("12,514 378x376", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); display_manager()->SetOverscanInsets( - display2.id(), gfx::Insets(10, 11, 12, 13)); + display_info2.id(), gfx::Insets(10, 11, 12, 13)); EXPECT_EQ("0,0 500x500", - display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(0).bounds_in_pixel().ToString()); EXPECT_EQ("11,511 376x378", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); // Recreate a new 2nd display. It won't apply the overscan inset because the // new display has a different ID. UpdateDisplay("0+0-500x500"); UpdateDisplay("0+0-500x500,0+501-400x400"); EXPECT_EQ("0,0 500x500", - display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(0).bounds_in_pixel().ToString()); EXPECT_EQ("0,501 400x400", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); // Recreate the displays with the same ID. It should apply the overscan // inset. UpdateDisplay("0+0-500x500"); - std::vector<gfx::Display> displays; - displays.push_back(display1); - displays.push_back(display2); - display_manager()->OnNativeDisplaysChanged(displays); - EXPECT_EQ("0,0 500x500", - display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + std::vector<DisplayInfo> display_info_list; + display_info_list.push_back(display_info1); + display_info_list.push_back(display_info2); + display_manager()->OnNativeDisplaysChanged(display_info_list); + EXPECT_EQ("1,1 500x500", + GetDisplayInfoAt(0).bounds_in_pixel().ToString()); EXPECT_EQ("11,511 376x378", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); // HiDPI but overscan display. The specified insets size should be doubled. - UpdateDisplay("0+0-500x500"); UpdateDisplay("0+0-500x500,0+501-400x400*2"); display_manager()->SetOverscanInsets( display_manager()->GetDisplayAt(1)->id(), gfx::Insets(4, 5, 6, 7)); EXPECT_EQ("0,0 500x500", - display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(0).bounds_in_pixel().ToString()); EXPECT_EQ("10,509 376x380", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); EXPECT_EQ("188x190", display_manager()->GetDisplayAt(1)->size().ToString()); // Make sure switching primary display applies the overscan offset only once. ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay( ScreenAsh::GetSecondaryDisplay()); EXPECT_EQ("0,0 500x500", - ScreenAsh::GetSecondaryDisplay().bounds_in_pixel().ToString()); - EXPECT_EQ("10,509 376x380", gfx::Screen::GetNativeScreen()-> - GetPrimaryDisplay().bounds_in_pixel().ToString()); + GetDisplayInfo(ScreenAsh::GetSecondaryDisplay()). + bounds_in_pixel().ToString()); + EXPECT_EQ("10,509 376x380", + GetDisplayInfo(gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()). + bounds_in_pixel().ToString()); } TEST_F(DisplayManagerTest, ZeroOverscanInsets) { @@ -311,84 +328,93 @@ TEST_F(DisplayManagerTest, TestDeviceScaleOnlyChange) { Shell::GetPrimaryRootWindow()->bounds().size().ToString()); } +DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) { + DisplayInfo info(id, std::string(), false); + info.SetBounds(bounds); + return info; +} + TEST_F(DisplayManagerTest, TestNativeDisplaysChanged) { const int64 internal_display_id = - display_manager()->SetFirstDisplayAsInternalDisplayForTest(); - const gfx::Display native_display(internal_display_id, - gfx::Rect(0, 0, 500, 500)); - const gfx::Display external_display(10, gfx::Rect(1, 1, 100, 100)); + test::DisplayManagerTestApi(display_manager()). + SetFirstDisplayAsInternalDisplay(); + const DisplayInfo native_display_info = + CreateDisplayInfo(internal_display_id, gfx::Rect(0, 0, 500, 500)); + const DisplayInfo external_display_info = + CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100)); EXPECT_EQ(1U, display_manager()->GetNumDisplays()); std::string default_bounds = display_manager()->GetDisplayAt(0)->bounds().ToString(); - std::vector<gfx::Display> displays; + std::vector<DisplayInfo> display_info_list; // Primary disconnected. - display_manager()->OnNativeDisplaysChanged(displays); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(1U, display_manager()->GetNumDisplays()); EXPECT_EQ(default_bounds, display_manager()->GetDisplayAt(0)->bounds().ToString()); // External connected while primary was disconnected. - displays.push_back(external_display); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.push_back(external_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); + EXPECT_EQ(default_bounds, FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("1,1 100x100", - FindDisplayForId(10).bounds_in_pixel().ToString()); + FindDisplayInfoForId(10).bounds_in_pixel().ToString()); // Primary connected, with different bounds. - displays.clear(); - displays.push_back(native_display); - displays.push_back(external_display); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.clear(); + display_info_list.push_back(native_display_info); + display_info_list.push_back(external_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); EXPECT_EQ("0,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("1,1 100x100", - FindDisplayForId(10).bounds_in_pixel().ToString()); + FindDisplayInfoForId(10).bounds_in_pixel().ToString()); // Turn off primary. - displays.clear(); - displays.push_back(external_display); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.clear(); + display_info_list.push_back(external_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); EXPECT_EQ("0,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("1,1 100x100", - FindDisplayForId(10).bounds_in_pixel().ToString()); + FindDisplayInfoForId(10).bounds_in_pixel().ToString()); // Emulate suspend. - displays.clear(); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.clear(); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); EXPECT_EQ("0,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("1,1 100x100", - FindDisplayForId(10).bounds_in_pixel().ToString()); + FindDisplayInfoForId(10).bounds_in_pixel().ToString()); // External display has disconnected then resumed. - displays.push_back(native_display); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.push_back(native_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(1U, display_manager()->GetNumDisplays()); EXPECT_EQ("0,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); // External display was changed during suspend. - displays.push_back(external_display); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.push_back(external_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); // suspend... - displays.clear(); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.clear(); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); // and resume with different external display. - displays.push_back(native_display); - displays.push_back(gfx::Display(11, gfx::Rect(1, 1, 100, 100))); - display_manager()->OnNativeDisplaysChanged(displays); + display_info_list.push_back(native_display_info); + display_info_list.push_back(CreateDisplayInfo(11, gfx::Rect(1, 1, 100, 100))); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); } @@ -406,17 +432,18 @@ TEST_F(DisplayManagerTest, MAYBE_TestNativeDisplaysChangedNoInternal) { EXPECT_EQ(1U, display_manager()->GetNumDisplays()); // Don't change the display info if all displays are disconnected. - std::vector<gfx::Display> displays; - display_manager()->OnNativeDisplaysChanged(displays); + std::vector<DisplayInfo> display_info_list; + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(1U, display_manager()->GetNumDisplays()); // Connect another display which will become primary. - const gfx::Display external_display(10, gfx::Rect(1, 1, 100, 100)); - displays.push_back(external_display); - display_manager()->OnNativeDisplaysChanged(displays); + const DisplayInfo external_display_info = + CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100)); + display_info_list.push_back(external_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(1U, display_manager()->GetNumDisplays()); EXPECT_EQ("1,1 100x100", - FindDisplayForId(10).bounds_in_pixel().ToString()); + FindDisplayInfoForId(10).bounds_in_pixel().ToString()); EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHostSize().ToString()); } @@ -496,29 +523,31 @@ TEST_F(DisplayManagerTest, EnsurePointerInDisplays_2ndOnLeft) { TEST_F(DisplayManagerTest, NativeDisplaysChangedAfterPrimaryChange) { const int64 internal_display_id = - display_manager()->SetFirstDisplayAsInternalDisplayForTest(); - const gfx::Display native_display(internal_display_id, - gfx::Rect(0, 0, 500, 500)); - const gfx::Display secondary_display(10, gfx::Rect(1, 1, 100, 100)); - - std::vector<gfx::Display> displays; - displays.push_back(native_display); - displays.push_back(secondary_display); - display_manager()->OnNativeDisplaysChanged(displays); + test::DisplayManagerTestApi(display_manager()). + SetFirstDisplayAsInternalDisplay(); + const DisplayInfo native_display_info = + CreateDisplayInfo(internal_display_id, gfx::Rect(0, 0, 500, 500)); + const DisplayInfo secondary_display_info = + CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100)); + + std::vector<DisplayInfo> display_info_list; + display_info_list.push_back(native_display_info); + display_info_list.push_back(secondary_display_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2U, display_manager()->GetNumDisplays()); EXPECT_EQ("0,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("500,0 100x100", FindDisplayForId(10).bounds().ToString()); ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay( - secondary_display); + FindDisplayForId(secondary_display_info.id())); EXPECT_EQ("-500,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("0,0 100x100", FindDisplayForId(10).bounds().ToString()); // OnNativeDisplaysChanged may change the display bounds. Here makes sure // nothing changed if the exactly same displays are specified. - display_manager()->OnNativeDisplaysChanged(displays); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ("-500,0 500x500", FindDisplayForId(internal_display_id).bounds().ToString()); EXPECT_EQ("0,0 100x100", FindDisplayForId(10).bounds().ToString()); @@ -527,29 +556,35 @@ TEST_F(DisplayManagerTest, NativeDisplaysChangedAfterPrimaryChange) { TEST_F(DisplayManagerTest, AutomaticOverscanInsets) { UpdateDisplay("200x200,400x400"); - std::vector<gfx::Display> displays; - displays.push_back(*display_manager()->GetDisplayAt(0)); - displays.push_back(*display_manager()->GetDisplayAt(1)); - int64 id = displays[1].id(); - display_manager()->SetHasOverscanFlagForTest(id, true); - - display_manager()->OnNativeDisplaysChanged(displays); + std::vector<DisplayInfo> display_info_list; + display_info_list.push_back(GetDisplayInfoAt(0)); + display_info_list.push_back(GetDisplayInfoAt(1)); + display_info_list[1].set_has_overscan_for_test(true); + int64 id = display_info_list[1].id(); + // SetDefaultOverscanInsets(&display_info_list[1]); + display_manager()->OnNativeDisplaysChanged(display_info_list); // It has overscan insets, although SetOverscanInsets() isn't called. EXPECT_EQ("11,211 380x380", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); // If custom overscan insets is specified, the specified value is used. display_manager()->SetOverscanInsets(id, gfx::Insets(5, 6, 7, 8)); - display_manager()->OnNativeDisplaysChanged(displays); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ("7,206 386x388", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); // Do not overscan even though it has 'has_overscan' flag, if the custom // insets is empty. display_manager()->SetOverscanInsets(id, gfx::Insets()); - display_manager()->OnNativeDisplaysChanged(displays); + display_manager()->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ("1,201 400x400", - display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); + + // Clearing the custom overscan should set the bounds to + // original. + display_manager()->ClearCustomOverscanInsets(id); + EXPECT_EQ("11,211 380x380", + GetDisplayInfoAt(1).bounds_in_pixel().ToString()); } } // namespace internal |