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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { | 21 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { |
22 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 22 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
23 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 23 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
24 params.parent = parent; | 24 params.parent = parent; |
25 widget->Init(params); | 25 widget->Init(params); |
26 return static_cast<NativeWidgetAura*>(widget->native_widget()); | 26 return static_cast<NativeWidgetAura*>(widget->native_widget()); |
27 } | 27 } |
28 | 28 |
29 class NativeWidgetAuraTest : public testing::Test { | 29 class NativeWidgetAuraTest : public testing::Test { |
30 public: | 30 public: |
31 NativeWidgetAuraTest() : root_window_(NULL) {} | 31 NativeWidgetAuraTest() {} |
32 virtual ~NativeWidgetAuraTest() {} | 32 virtual ~NativeWidgetAuraTest() {} |
33 | 33 |
34 // testing::Test overrides: | 34 // testing::Test overrides: |
35 virtual void SetUp() OVERRIDE { | 35 virtual void SetUp() OVERRIDE { |
36 root_window_ = aura::RootWindow::GetInstance(); | 36 root_window_.reset(new aura::RootWindow); |
37 root_window_->SetBounds(gfx::Rect(0, 0, 640, 480)); | 37 root_window_->SetBounds(gfx::Rect(0, 0, 640, 480)); |
38 root_window_->SetHostSize(gfx::Size(640, 480)); | 38 root_window_->SetHostSize(gfx::Size(640, 480)); |
39 test_stacking_client_.reset( | 39 test_stacking_client_.reset( |
40 new aura::test::TestStackingClient(root_window_)); | 40 new aura::test::TestStackingClient(root_window_.get())); |
41 } | 41 } |
42 virtual void TearDown() OVERRIDE { | 42 virtual void TearDown() OVERRIDE { |
| 43 message_loop_.RunAllPending(); |
43 test_stacking_client_.reset(); | 44 test_stacking_client_.reset(); |
44 aura::RootWindow::DeleteInstance(); | 45 root_window_.reset(); |
45 message_loop_.RunAllPending(); | |
46 } | 46 } |
47 | 47 |
48 protected: | 48 protected: |
49 aura::RootWindow* root_window() { return root_window_; } | 49 aura::RootWindow* root_window() { return root_window_.get(); } |
50 | 50 |
51 private: | 51 private: |
52 MessageLoopForUI message_loop_; | 52 MessageLoopForUI message_loop_; |
53 aura::RootWindow* root_window_; | 53 scoped_ptr<aura::RootWindow> root_window_; |
54 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; | 54 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); | 56 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); |
57 }; | 57 }; |
58 | 58 |
59 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { | 59 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { |
60 // Make a parent window larger than the host represented by rootwindow. | 60 // Make a parent window larger than the host represented by rootwindow. |
61 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); | 61 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); |
62 parent->Init(ui::Layer::LAYER_NOT_DRAWN); | 62 parent->Init(ui::Layer::LAYER_NOT_DRAWN); |
63 parent->SetBounds(gfx::Rect(0, 0, 1024, 800)); | 63 parent->SetBounds(gfx::Rect(0, 0, 1024, 800)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) { | 147 TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) { |
148 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); | 148 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); |
149 root_window()->SetLayoutManager(new TestLayoutManager); | 149 root_window()->SetLayoutManager(new TestLayoutManager); |
150 scoped_ptr<TestWidget> widget(new TestWidget()); | 150 scoped_ptr<TestWidget> widget(new TestWidget()); |
151 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 151 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
152 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 152 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
153 params.parent = NULL; | 153 params.parent = NULL; |
154 params.show_state = ui::SHOW_STATE_MAXIMIZED; | 154 params.show_state = ui::SHOW_STATE_MAXIMIZED; |
155 params.bounds = gfx::Rect(10, 10, 100, 200); | 155 params.bounds = gfx::Rect(10, 10, 100, 200); |
156 widget->Init(params); | 156 widget->Init(params); |
157 aura::RootWindow::DeleteInstance(); | |
158 EXPECT_FALSE(widget->did_size_change_more_than_once()); | 157 EXPECT_FALSE(widget->did_size_change_more_than_once()); |
159 widget->CloseNow(); | 158 widget->CloseNow(); |
160 } | 159 } |
161 | 160 |
162 TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) { | 161 TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) { |
163 // Create a widget. | 162 // Create a widget. |
164 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 163 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
165 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 164 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
166 params.bounds.SetRect(10, 20, 300, 400); | 165 params.bounds.SetRect(10, 20, 300, 400); |
167 scoped_ptr<Widget> widget(new Widget()); | 166 scoped_ptr<Widget> widget(new Widget()); |
168 widget->Init(params); | 167 widget->Init(params); |
169 | 168 |
170 // For Aura, client area bounds match window bounds. | 169 // For Aura, client area bounds match window bounds. |
171 gfx::Rect client_bounds = widget->GetClientAreaScreenBounds(); | 170 gfx::Rect client_bounds = widget->GetClientAreaScreenBounds(); |
172 EXPECT_EQ(10, client_bounds.x()); | 171 EXPECT_EQ(10, client_bounds.x()); |
173 EXPECT_EQ(20, client_bounds.y()); | 172 EXPECT_EQ(20, client_bounds.y()); |
174 EXPECT_EQ(300, client_bounds.width()); | 173 EXPECT_EQ(300, client_bounds.width()); |
175 EXPECT_EQ(400, client_bounds.height()); | 174 EXPECT_EQ(400, client_bounds.height()); |
176 } | 175 } |
177 | 176 |
178 } // namespace | 177 } // namespace |
179 } // namespace views | 178 } // namespace views |
OLD | NEW |