From 9afa39c161c8ffd23cb8fbcbedd344dc7d9f4fc4 Mon Sep 17 00:00:00 2001 From: mukai Date: Tue, 14 Oct 2014 14:28:25 -0700 Subject: Do not check if the number of display is exactly 2. When a display removal and a display add happens at the same time, the number of display is actually 3 during the display removal event. Therefore the check is too strict. BUG=414394 R=oshima@chromium.org TEST=the new test case covers Review URL: https://codereview.chromium.org/650403002 Cr-Commit-Position: refs/heads/master@{#299553} --- ash/display/display_manager_unittest.cc | 30 ++++++++++++++++++++++++++++++ ash/screen_util.cc | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index aa2330c..1ce0045 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -572,6 +572,36 @@ TEST_F(DisplayManagerTest, TestNativeDisplaysChanged) { EXPECT_FALSE(display_manager()->IsMirrored()); } +// Make sure crash does not happen if add and remove happens at the same time. +// See: crbug.com/414394 +TEST_F(DisplayManagerTest, DisplayAddRemoveAtTheSameTime) { + if (!SupportsMultipleDisplays()) + return; + + UpdateDisplay("100+0-500x500,0+501-400x400"); + + const int64 primary_id = DisplayController::GetPrimaryDisplayId(); + const int64 secondary_id = ScreenUtil::GetSecondaryDisplay().id(); + + DisplayInfo primary_info = display_manager()->GetDisplayInfo(primary_id); + DisplayInfo secondary_info = display_manager()->GetDisplayInfo(secondary_id); + + // An id which is different from primary and secondary. + const int64 third_id = primary_id + secondary_id; + + DisplayInfo third_info = + CreateDisplayInfo(third_id, gfx::Rect(0, 0, 600, 600)); + + std::vector display_info_list; + display_info_list.push_back(third_info); + display_info_list.push_back(secondary_info); + display_manager()->OnNativeDisplaysChanged(display_info_list); + + EXPECT_EQ(third_id, DisplayController::GetPrimaryDisplayId()); + EXPECT_EQ("600x600", GetDisplayForId(third_id).size().ToString()); + EXPECT_EQ(secondary_id, ScreenUtil::GetSecondaryDisplay().id()); +} + #if defined(OS_WIN) // TODO(scottmg): RootWindow doesn't get resized on Windows // Ash. http://crbug.com/247916. diff --git a/ash/screen_util.cc b/ash/screen_util.cc index a412d70..0e19b9d 100644 --- a/ash/screen_util.cc +++ b/ash/screen_util.cc @@ -73,7 +73,7 @@ gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window, // static const gfx::Display& ScreenUtil::GetSecondaryDisplay() { DisplayManager* display_manager = GetDisplayManager(); - CHECK_EQ(2U, display_manager->GetNumDisplays()); + CHECK_LE(2U, display_manager->GetNumDisplays()); return display_manager->GetDisplayAt(0).id() == Shell::GetScreen()->GetPrimaryDisplay().id() ? display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); -- cgit v1.1