Commit d1be868e authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

fix WindowSizerTest failure on Mash

The test fails because of checking browser's root window with
Shell's root window -- this is actually checking the display
for the browser window. This CL applies the same fix for
TabDragController.

BUG=883523
TEST=interactive_ui_tests --enable-features=SingleProcessMash

Change-Id: I8a53b15216c665c8c0f34ebfced0b22b97e93875
Reviewed-on: https://chromium-review.googlesource.com/1246064
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594801}
parent 5b92c936
......@@ -89,6 +89,7 @@
using content::WebContents;
using display::Display;
using ui_test_utils::GetDisplays;
namespace test {
......@@ -1909,24 +1910,6 @@ void DragSingleTabToSeparateWindowInSecondDisplayStep2(
base::Bind(&DragSingleTabToSeparateWindowInSecondDisplayStep3, test)));
}
// Returns the secondary display from the screen. It should fail and crash
// if there is no such display.
Display GetSecondaryDisplay(display::Screen* screen) {
for (const auto& iter : screen->GetAllDisplays()) {
if (iter.id() != screen->GetPrimaryDisplay().id())
return iter;
}
NOTREACHED();
return Display();
}
// Returns the pair of displays -- the first one is the primary display and the
// second one is the other display.
std::pair<Display, Display> GetDisplays(display::Screen* screen) {
return std::make_pair(screen->GetPrimaryDisplay(),
GetSecondaryDisplay(screen));
}
} // namespace
// Drags from browser to a second display and releases input.
......@@ -1965,7 +1948,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
if (input_source() == INPUT_SOURCE_MOUSE) {
display::Screen* screen = display::Screen::GetScreen();
EXPECT_EQ(
GetSecondaryDisplay(screen).id(),
ui_test_utils::GetSecondaryDisplay(screen).id(),
screen
->GetDisplayNearestWindow(new_browser->window()->GetNativeWindow())
.id());
......@@ -2016,7 +1999,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
// Move the second browser to the second display.
display::Screen* screen = display::Screen::GetScreen();
Display second_display = GetSecondaryDisplay(screen);
Display second_display = ui_test_utils::GetSecondaryDisplay(screen);
browser2->window()->SetBounds(second_display.work_area());
EXPECT_EQ(
second_display.id(),
......@@ -2118,7 +2101,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
// Move both browsers to be side by side on the second display.
display::Screen* screen = display::Screen::GetScreen();
Display second_display = GetSecondaryDisplay(screen);
Display second_display = ui_test_utils::GetSecondaryDisplay(screen);
gfx::Rect work_area = second_display.work_area();
work_area.set_width(work_area.width() / 2);
browser()->window()->SetBounds(work_area);
......
......@@ -16,6 +16,7 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "ui/events/test/event_generator.h"
......@@ -120,9 +121,15 @@ IN_PROC_BROWSER_TEST_F(WindowSizerTest, OpenBrowserUsingShelfItem) {
OpenBrowserUsingShelfOnRootWindow(root_windows[1]);
// A new browser window should be opened on the 2nd display.
display::Screen* screen = display::Screen::GetScreen();
std::pair<display::Display, display::Display> displays =
ui_test_utils::GetDisplays(screen);
EXPECT_EQ(1u, browser_list->size());
EXPECT_EQ(root_windows[1],
browser_list->get(0)->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(displays.second.id(),
screen
->GetDisplayNearestWindow(
browser_list->get(0)->window()->GetNativeWindow())
.id());
EXPECT_EQ(root_windows[1], ash::Shell::GetRootWindowForNewWindows());
// Close the browser window so that clicking the icon creates a new window.
......@@ -133,8 +140,11 @@ IN_PROC_BROWSER_TEST_F(WindowSizerTest, OpenBrowserUsingShelfItem) {
// A new browser window should be opened on the 1st display.
EXPECT_EQ(1u, browser_list->size());
EXPECT_EQ(root_windows[0],
browser_list->get(0)->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(displays.first.id(),
screen
->GetDisplayNearestWindow(
browser_list->get(0)->window()->GetNativeWindow())
.id());
EXPECT_EQ(root_windows[0], ash::Shell::GetRootWindowForNewWindows());
}
......@@ -155,9 +165,15 @@ IN_PROC_BROWSER_TEST_F(WindowSizerTest, OpenBrowserUsingContextMenu) {
OpenBrowserUsingContextMenuOnRootWindow(root_windows[1]);
// A new browser window should be opened on the 2nd display.
display::Screen* screen = display::Screen::GetScreen();
std::pair<display::Display, display::Display> displays =
ui_test_utils::GetDisplays(screen);
ASSERT_EQ(1u, browser_list->size());
EXPECT_EQ(root_windows[1],
browser_list->get(0)->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(displays.second.id(),
screen
->GetDisplayNearestWindow(
browser_list->get(0)->window()->GetNativeWindow())
.id());
EXPECT_EQ(root_windows[1], ash::Shell::GetRootWindowForNewWindows());
CloseBrowserSynchronously(browser_list->get(0));
......@@ -165,8 +181,11 @@ IN_PROC_BROWSER_TEST_F(WindowSizerTest, OpenBrowserUsingContextMenu) {
// A new browser window should be opened on the 1st display.
ASSERT_EQ(1u, browser_list->size());
EXPECT_EQ(root_windows[0],
browser_list->get(0)->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(displays.first.id(),
screen
->GetDisplayNearestWindow(
browser_list->get(0)->window()->GetNativeWindow())
.id());
EXPECT_EQ(root_windows[0], ash::Shell::GetRootWindowForNewWindows());
}
......
......@@ -12,6 +12,8 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace ui_test_utils {
......@@ -214,4 +216,19 @@ void ClickTask(ui_controls::MouseButton button,
} // namespace internal
display::Display GetSecondaryDisplay(display::Screen* screen) {
for (const auto& iter : screen->GetAllDisplays()) {
if (iter.id() != screen->GetPrimaryDisplay().id())
return iter;
}
NOTREACHED();
return display::Display();
}
std::pair<display::Display, display::Display> GetDisplays(
display::Screen* screen) {
return std::make_pair(screen->GetPrimaryDisplay(),
GetSecondaryDisplay(screen));
}
} // namespace ui_test_utils
......@@ -15,6 +15,11 @@
#include "ui/base/test/ui_controls.h"
#include "ui/events/event_constants.h"
namespace display {
class Display;
class Screen;
} // namespace display
namespace gfx {
class Point;
}
......@@ -215,6 +220,15 @@ void ClickTask(ui_controls::MouseButton button,
} // namespace internal
// Returns the secondary display from the screen. DCHECKs if there is no such
// display.
display::Display GetSecondaryDisplay(display::Screen* screen);
// Returns the pair of displays -- the first one is the primary display and the
// second one is the other display.
std::pair<display::Display, display::Display> GetDisplays(
display::Screen* screen);
} // namespace ui_test_utils
#endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment