| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/test/views_test_base.h" | 5 #include "ui/views/test/views_test_base.h" |
| 6 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 6 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 7 #include "ui/views/widget/widget.h" | 7 #include "ui/views/widget/widget.h" |
| 8 #include "ui/views/window/dialog_delegate.h" | 8 #include "ui/views/window/dialog_delegate.h" |
| 9 | 9 |
| 10 namespace views { | 10 namespace views { |
| 11 | 11 |
| 12 typedef ViewsTestBase DesktopScreenPositionClientTest; | 12 typedef ViewsTestBase DesktopScreenPositionClientTest; |
| 13 | 13 |
| 14 // Verifies setting the bounds of a dialog parented to a Widget with a | 14 // Verifies setting the bounds of a dialog parented to a Widget with a |
| 15 // DesktopNativeWidgetAura is positioned correctly. | 15 // DesktopNativeWidgetAura is positioned correctly. |
| 16 TEST_F(DesktopScreenPositionClientTest, PositionDialog) { | 16 TEST_F(DesktopScreenPositionClientTest, PositionDialog) { |
| 17 Widget parent_widget; | 17 Widget parent_widget; |
| 18 Widget::InitParams init_params = | 18 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 19 CreateParams(Widget::InitParams::TYPE_WINDOW); | 19 params.bounds = gfx::Rect(10, 11, 200, 200); |
| 20 init_params.bounds = gfx::Rect(10, 11, 200, 200); | 20 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 21 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 21 params.native_widget = new DesktopNativeWidgetAura(&parent_widget); |
| 22 init_params.native_widget = new DesktopNativeWidgetAura(&parent_widget); | 22 parent_widget.Init(params); |
| 23 parent_widget.Init(init_params); | |
| 24 // parent_widget.Show(); | |
| 25 | 23 |
| 26 // Owned by |dialog|. | 24 // Owned by |dialog|. |
| 27 DialogDelegateView* dialog_delegate_view = new DialogDelegateView; | 25 DialogDelegateView* dialog_delegate_view = new DialogDelegateView; |
| 28 // Owned by |parent_widget|. | 26 // Owned by |parent_widget|. |
| 29 Widget* dialog = DialogDelegate::CreateDialogWidget( | 27 Widget* dialog = DialogDelegate::CreateDialogWidget( |
| 30 dialog_delegate_view, | 28 dialog_delegate_view, NULL, parent_widget.GetNativeView()); |
| 31 NULL, | |
| 32 parent_widget.GetNativeView()); | |
| 33 dialog->SetBounds(gfx::Rect(11, 12, 200, 200)); | 29 dialog->SetBounds(gfx::Rect(11, 12, 200, 200)); |
| 34 EXPECT_EQ("11,12", dialog->GetWindowBoundsInScreen().origin().ToString()); | 30 EXPECT_EQ("11,12", dialog->GetWindowBoundsInScreen().origin().ToString()); |
| 35 } | 31 } |
| 36 | 32 |
| 37 // Verifies that setting the bounds of a control parented to something other | 33 // Verifies that setting the bounds of a control parented to something other |
| 38 // than the root window is positioned correctly. | 34 // than the root window is positioned correctly. |
| 39 TEST_F(DesktopScreenPositionClientTest, PositionControlWithNonRootParent) { | 35 TEST_F(DesktopScreenPositionClientTest, PositionControlWithNonRootParent) { |
| 40 Widget widget1; | 36 Widget widget1; |
| 41 Widget widget2; | 37 Widget widget2; |
| 42 Widget widget3; | 38 Widget widget3; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 widget3.Init(params3); | 72 widget3.Init(params3); |
| 77 | 73 |
| 78 // The origin of the 3rd window should be the sum of all parent origins. | 74 // 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); | 75 gfx::Point expected_origin(origin.x() * 3, origin.y() * 3); |
| 80 gfx::Rect expected_bounds(expected_origin, gfx::Size(500, 400)); | 76 gfx::Rect expected_bounds(expected_origin, gfx::Size(500, 400)); |
| 81 gfx::Rect actual_bounds(widget3.GetWindowBoundsInScreen()); | 77 gfx::Rect actual_bounds(widget3.GetWindowBoundsInScreen()); |
| 82 EXPECT_EQ(expected_bounds.ToString(), actual_bounds.ToString()); | 78 EXPECT_EQ(expected_bounds.ToString(), actual_bounds.ToString()); |
| 83 } | 79 } |
| 84 | 80 |
| 85 } // namespace views | 81 } // namespace views |
| OLD | NEW |