OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 window->GetNativeWindow()->bounds()); | 74 window->GetNativeWindow()->bounds()); |
75 widget->CloseNow(); | 75 widget->CloseNow(); |
76 } | 76 } |
77 | 77 |
78 TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) { | 78 TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) { |
79 // Make a parent window smaller than the host represented by rootwindow. | 79 // Make a parent window smaller than the host represented by rootwindow. |
80 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); | 80 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); |
81 parent->Init(ui::LAYER_NOT_DRAWN); | 81 parent->Init(ui::LAYER_NOT_DRAWN); |
82 parent->SetBounds(gfx::Rect(0, 0, 480, 320)); | 82 parent->SetBounds(gfx::Rect(0, 0, 480, 320)); |
83 scoped_ptr<Widget> widget(new Widget()); | 83 scoped_ptr<Widget> widget(new Widget()); |
84 NativeWidgetAura* window = Init(parent.get(), widget.get()); | 84 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
85 | 85 |
86 window->CenterWindow(gfx::Size(100, 100)); | 86 window->CenterWindow(gfx::Size(100, 100)); |
87 EXPECT_EQ(gfx::Rect( (480 - 100) / 2, | 87 EXPECT_EQ(gfx::Rect( (480 - 100) / 2, |
88 (320 - 100) / 2, | 88 (320 - 100) / 2, |
89 100, 100), | 89 100, 100), |
90 window->GetNativeWindow()->bounds()); | 90 window->GetNativeWindow()->bounds()); |
91 widget->CloseNow(); | 91 widget->CloseNow(); |
92 } | 92 } |
93 | 93 |
| 94 // Verifies CenterWindow() constrains to parent size. |
| 95 TEST_F(NativeWidgetAuraTest, CenterWindowSmallParentNotAtOrigin) { |
| 96 // Make a parent window smaller than the host represented by rootwindow and |
| 97 // offset it slightly from the origin. |
| 98 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); |
| 99 parent->Init(ui::LAYER_NOT_DRAWN); |
| 100 parent->SetBounds(gfx::Rect(20, 40, 480, 320)); |
| 101 scoped_ptr<Widget> widget(new Widget()); |
| 102 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
| 103 window->CenterWindow(gfx::Size(500, 600)); |
| 104 |
| 105 // |window| should be no bigger than |parent|. |
| 106 EXPECT_EQ("20,40 480x320", window->GetNativeWindow()->bounds().ToString()); |
| 107 widget->CloseNow(); |
| 108 } |
| 109 |
94 // Used by ShowMaximizedDoesntBounceAround. See it for details. | 110 // Used by ShowMaximizedDoesntBounceAround. See it for details. |
95 class TestLayoutManager : public aura::LayoutManager { | 111 class TestLayoutManager : public aura::LayoutManager { |
96 public: | 112 public: |
97 TestLayoutManager() {} | 113 TestLayoutManager() {} |
98 | 114 |
99 virtual void OnWindowResized() OVERRIDE { | 115 virtual void OnWindowResized() OVERRIDE { |
100 } | 116 } |
101 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | 117 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
102 // This simulates what happens when adding a maximized window. | 118 // This simulates what happens when adding a maximized window. |
103 SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300)); | 119 SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300)); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 parent->GetNativeWindow()->GetEventHandlerForPoint( | 366 parent->GetNativeWindow()->GetEventHandlerForPoint( |
351 gfx::Point(20, 20))); | 367 gfx::Point(20, 20))); |
352 | 368 |
353 // Work around for bug in NativeWidgetAura. | 369 // Work around for bug in NativeWidgetAura. |
354 // TODO: fix bug and remove this. | 370 // TODO: fix bug and remove this. |
355 parent->Close(); | 371 parent->Close(); |
356 } | 372 } |
357 | 373 |
358 } // namespace | 374 } // namespace |
359 } // namespace views | 375 } // namespace views |
OLD | NEW |