blob: bb1cd8b08ac6221a7eaacd759b39408032da9289 [file] [log] [blame]
Ben Murdoch558790d2013-07-30 15:19:42 +01001// 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.
4
5#include "ui/views/test/views_test_base.h"
6#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
7#include "ui/views/widget/widget.h"
8#include "ui/views/window/dialog_delegate.h"
9
10namespace views {
11
12typedef ViewsTestBase DesktopScreenPositionClientTest;
13
14// Verifies setting the bounds of a dialog parented to a Widget with a
15// DesktopNativeWidgetAura is positioned correctly.
16TEST_F(DesktopScreenPositionClientTest, PositionDialog) {
17 Widget parent_widget;
18 Widget::InitParams init_params =
19 CreateParams(Widget::InitParams::TYPE_WINDOW);
20 init_params.bounds = gfx::Rect(10, 11, 200, 200);
21 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
22 init_params.native_widget = new DesktopNativeWidgetAura(&parent_widget);
23 parent_widget.Init(init_params);
24 // parent_widget.Show();
25
26 // Owned by |dialog|.
27 DialogDelegateView* dialog_delegate_view = new DialogDelegateView;
28 // Owned by |parent_widget|.
29 Widget* dialog = DialogDelegate::CreateDialogWidget(
30 dialog_delegate_view,
31 NULL,
32 parent_widget.GetNativeView());
33 dialog->SetBounds(gfx::Rect(11, 12, 200, 200));
34 EXPECT_EQ("11,12", dialog->GetWindowBoundsInScreen().origin().ToString());
35}
36
Ben Murdochbb1529c2013-08-08 10:24:53 +010037// Verifies that setting the bounds of a control parented to something other
38// than the root window is positioned correctly.
39TEST_F(DesktopScreenPositionClientTest, PositionControlWithNonRootParent) {
40 Widget widget1;
41 Widget widget2;
42 Widget widget3;
43 gfx::Point origin = gfx::Point(16, 16);
44
45 // Use a custom frame type. By default we will choose a native frame when
46 // aero glass is enabled, and this complicates the logic surrounding origin
47 // computation, making it difficult to compute the expected origin location.
48 widget1.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM);
49 widget2.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM);
50 widget3.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM);
51
52 // Create 3 windows. A root window, an arbitrary window parented to the root
53 // but NOT positioned at (0,0) relative to the root, and then a third window
54 // parented to the second, also not positioned at (0,0).
55 Widget::InitParams params1 =
56 CreateParams(Widget::InitParams::TYPE_WINDOW);
57 params1.bounds = gfx::Rect(origin, gfx::Size(700, 600));
58 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
59 params1.native_widget = new DesktopNativeWidgetAura(&widget1);
60 widget1.Init(params1);
61
62 Widget::InitParams params2 =
63 CreateParams(Widget::InitParams::TYPE_WINDOW);
64 params2.bounds = gfx::Rect(origin, gfx::Size(600, 500));
65 params2.parent = widget1.GetNativeView();
66 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
67 params2.child = true;
68 widget2.Init(params2);
69
70 Widget::InitParams params3 =
71 CreateParams(Widget::InitParams::TYPE_CONTROL);
72 params3.parent = widget2.GetNativeView();
73 params3.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
74 params3.child = true;
75 params3.bounds = gfx::Rect(origin, gfx::Size(500, 400));
76 widget3.Init(params3);
77
78 // The origin of the 3rd window should be the sum of all parent origins.
79 gfx::Point expected_origin(origin.x() * 3, origin.y() * 3);
80 gfx::Rect expected_bounds(expected_origin, gfx::Size(500, 400));
81 gfx::Rect actual_bounds(widget3.GetWindowBoundsInScreen());
82 EXPECT_EQ(expected_bounds.ToString(), actual_bounds.ToString());
83}
84
Ben Murdoch558790d2013-07-30 15:19:42 +010085} // namespace views