1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/test/views_test_base.h"
6 #include "ui/views/test/widget_test.h"
7 #include "ui/views/widget/widget.h"
8 #include "ui/views/window/dialog_delegate.h"
12 typedef ViewsTestBase DesktopScreenPositionClientTest
;
14 // Verifies setting the bounds of a dialog parented to a Widget with a
15 // PlatformDesktopNativeWidget is positioned correctly.
16 TEST_F(DesktopScreenPositionClientTest
, PositionDialog
) {
18 Widget::InitParams params
= CreateParams(Widget::InitParams::TYPE_WINDOW
);
19 params
.bounds
= gfx::Rect(10, 11, 200, 200);
20 params
.ownership
= Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
21 params
.native_widget
= new PlatformDesktopNativeWidget(&parent_widget
);
22 parent_widget
.Init(params
);
25 DialogDelegateView
* dialog_delegate_view
= new DialogDelegateView
;
26 // Owned by |parent_widget|.
27 Widget
* dialog
= DialogDelegate::CreateDialogWidget(
28 dialog_delegate_view
, NULL
, parent_widget
.GetNativeView());
29 dialog
->SetBounds(gfx::Rect(11, 12, 200, 200));
30 EXPECT_EQ("11,12", dialog
->GetWindowBoundsInScreen().origin().ToString());
33 // Verifies that setting the bounds of a control parented to something other
34 // than the root window is positioned correctly.
35 TEST_F(DesktopScreenPositionClientTest
, PositionControlWithNonRootParent
) {
39 gfx::Point origin
= gfx::Point(16, 16);
41 // Use a custom frame type. By default we will choose a native frame when
42 // aero glass is enabled, and this complicates the logic surrounding origin
43 // computation, making it difficult to compute the expected origin location.
44 widget1
.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM
);
45 widget2
.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM
);
46 widget3
.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM
);
48 // Create 3 windows. A root window, an arbitrary window parented to the root
49 // but NOT positioned at (0,0) relative to the root, and then a third window
50 // parented to the second, also not positioned at (0,0).
51 Widget::InitParams params1
=
52 CreateParams(Widget::InitParams::TYPE_WINDOW
);
53 params1
.bounds
= gfx::Rect(origin
, gfx::Size(700, 600));
54 params1
.ownership
= Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
55 params1
.native_widget
= new PlatformDesktopNativeWidget(&widget1
);
56 widget1
.Init(params1
);
58 Widget::InitParams params2
=
59 CreateParams(Widget::InitParams::TYPE_WINDOW
);
60 params2
.bounds
= gfx::Rect(origin
, gfx::Size(600, 500));
61 params2
.parent
= widget1
.GetNativeView();
62 params2
.ownership
= Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
64 widget2
.Init(params2
);
66 Widget::InitParams params3
=
67 CreateParams(Widget::InitParams::TYPE_CONTROL
);
68 params3
.parent
= widget2
.GetNativeView();
69 params3
.ownership
= Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
71 params3
.bounds
= gfx::Rect(origin
, gfx::Size(500, 400));
72 widget3
.Init(params3
);
74 // The origin of the 3rd window should be the sum of all parent origins.
75 gfx::Point
expected_origin(origin
.x() * 3, origin
.y() * 3);
76 gfx::Rect
expected_bounds(expected_origin
, gfx::Size(500, 400));
77 gfx::Rect
actual_bounds(widget3
.GetWindowBoundsInScreen());
78 EXPECT_EQ(expected_bounds
.ToString(), actual_bounds
.ToString());