Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Do not check if the number of display is exactly 2.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
jmuk authored and Commit bot committed Oct 14, 2014
1 parent 214a168 commit 9afa39c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions ash/display/display_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DisplayInfo> 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.
Expand Down
2 changes: 1 addition & 1 deletion ash/screen_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9afa39c

Please sign in to comment.