Index: components/constrained_window/constrained_window_views_unittest.cc |
diff --git a/components/constrained_window/constrained_window_views_unittest.cc b/components/constrained_window/constrained_window_views_unittest.cc |
index a0dd9dfddc3cca626e77cba1198e509f81d0cd0c..47af53a3e271373d7e96a63c477b229ba7eaa8b2 100644 |
--- a/components/constrained_window/constrained_window_views_unittest.cc |
+++ b/components/constrained_window/constrained_window_views_unittest.cc |
@@ -5,10 +5,13 @@ |
#include "components/constrained_window/constrained_window_views.h" |
#include <memory> |
+#include <vector> |
#include "base/macros.h" |
#include "components/constrained_window/constrained_window_views_client.h" |
#include "components/web_modal/test_web_contents_modal_dialog_host.h" |
+#include "ui/display/display.h" |
+#include "ui/display/screen.h" |
#include "ui/gfx/geometry/point.h" |
#include "ui/gfx/geometry/rect.h" |
#include "ui/gfx/geometry/size.h" |
@@ -228,4 +231,36 @@ TEST_F(ConstrainedWindowViewsTest, NullModalParent) { |
widget->CloseNow(); |
} |
+// Make sure dialogs presented off-screen are properly clamped to the nearest |
+// screen. |
+TEST_F(ConstrainedWindowViewsTest, ClampDialogToNearestDisplay) { |
+ // First, make sure the host and dialog are sized and positioned. |
+ UpdateWebContentsModalDialogPosition(dialog(), dialog_host()); |
+ |
+ const display::Screen* screen = display::Screen::GetScreen(); |
+ const display::Display display = screen->GetPrimaryDisplay(); |
+ // Within the tests there is only 1 display. Error if that ever changes. |
+ EXPECT_EQ(screen->GetNumDisplays(), 1); |
+ const gfx::Rect extents = display.work_area(); |
+ |
+ // Move the host completely off the screen. |
+ views::Widget* host_widget = |
+ views::Widget::GetWidgetForNativeView(dialog_host()->GetHostView()); |
+ gfx::Rect host_bounds = host_widget->GetWindowBoundsInScreen(); |
+ host_bounds.set_origin(gfx::Point(extents.right(), extents.bottom())); |
+ host_widget->SetBounds(host_bounds); |
+ |
+ // Make sure the host is fully off the screen. |
+ EXPECT_FALSE(extents.Intersects(host_widget->GetWindowBoundsInScreen())); |
+ |
+ // Now reposition the modal dialog into the display. |
+ UpdateWebContentsModalDialogPosition(dialog(), dialog_host()); |
+ |
+ const gfx::Rect dialog_bounds = dialog()->GetRootView()->GetBoundsInScreen(); |
+ |
+ // As long as the dialog intersects the display, it has been moved to be |
+ // visible. Due to the constraints set, it may extend off the display. |
msw
2016/12/15 21:44:56
Can you explain what constraints you're referring
kylix_rd
2016/12/15 21:57:56
The default dialog constraints (min/max size) setu
msw
2016/12/15 22:17:40
It's a little silly that the test's SetUp makes th
kylix_rd
2016/12/15 22:21:53
I agree. However, out of the abundance of caution,
|
+ EXPECT_TRUE(extents.Intersects(dialog_bounds)); |
+} |
+ |
} // namespace constrained_window |