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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/aura/client/aura_constants.h" | 12 #include "ui/aura/client/aura_constants.h" |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
16 #include "ui/aura/test/aura_test_helper.h" | |
17 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
18 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
19 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
20 #include "ui/views/layout/fill_layout.h" | 19 #include "ui/views/layout/fill_layout.h" |
| 20 #include "ui/views/test/views_test_base.h" |
21 #include "ui/views/widget/root_view.h" | 21 #include "ui/views/widget/root_view.h" |
22 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
23 | 23 |
24 namespace views { | 24 namespace views { |
25 namespace { | 25 namespace { |
26 | 26 |
27 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { | 27 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { |
28 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 28 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
29 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 29 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
30 params.parent = parent; | 30 params.parent = parent; |
31 widget->Init(params); | 31 widget->Init(params); |
32 return static_cast<NativeWidgetAura*>(widget->native_widget()); | 32 return static_cast<NativeWidgetAura*>(widget->native_widget()); |
33 } | 33 } |
34 | 34 |
35 class NativeWidgetAuraTest : public testing::Test { | 35 class NativeWidgetAuraTest : public ViewsTestBase { |
36 public: | 36 public: |
37 NativeWidgetAuraTest() {} | 37 NativeWidgetAuraTest() {} |
38 virtual ~NativeWidgetAuraTest() {} | 38 virtual ~NativeWidgetAuraTest() {} |
39 | 39 |
40 // testing::Test overrides: | 40 // testing::Test overrides: |
41 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
42 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 42 ViewsTestBase::SetUp(); |
43 aura_test_helper_->SetUp(); | |
44 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); | 43 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); |
45 dispatcher()->SetHostSize(gfx::Size(640, 480)); | 44 dispatcher()->SetHostSize(gfx::Size(640, 480)); |
46 } | 45 } |
47 virtual void TearDown() OVERRIDE { | |
48 message_loop_.RunUntilIdle(); | |
49 aura_test_helper_->TearDown(); | |
50 } | |
51 | 46 |
52 protected: | 47 protected: |
53 aura::Window* root_window() { return aura_test_helper_->root_window(); } | 48 aura::Window* root_window() { return GetContext(); } |
54 aura::RootWindow* dispatcher() { return aura_test_helper_->dispatcher(); } | 49 aura::RootWindow* dispatcher() { return root_window()->GetDispatcher(); } |
55 | 50 |
56 private: | 51 private: |
57 base::MessageLoopForUI message_loop_; | |
58 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); | 52 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); |
61 }; | 53 }; |
62 | 54 |
63 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { | 55 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { |
64 // Make a parent window larger than the host represented by rootwindow. | 56 // Make a parent window larger than the host represented by rootwindow. |
65 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); | 57 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); |
66 parent->Init(ui::LAYER_NOT_DRAWN); | 58 parent->Init(ui::LAYER_NOT_DRAWN); |
67 parent->SetBounds(gfx::Rect(0, 0, 1024, 800)); | 59 parent->SetBounds(gfx::Rect(0, 0, 1024, 800)); |
68 scoped_ptr<Widget> widget(new Widget()); | 60 scoped_ptr<Widget> widget(new Widget()); |
69 NativeWidgetAura* window = Init(parent.get(), widget.get()); | 61 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 scoped_ptr<Widget> widget(new Widget()); | 396 scoped_ptr<Widget> widget(new Widget()); |
405 NativeWidgetAura* window = Init(parent.get(), widget.get()); | 397 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
406 window->Show(); | 398 window->Show(); |
407 window->Close(); | 399 window->Close(); |
408 base::MessageLoop::current()->RunUntilIdle(); | 400 base::MessageLoop::current()->RunUntilIdle(); |
409 widget->GetNativeTheme(); // Shouldn't crash. | 401 widget->GetNativeTheme(); // Shouldn't crash. |
410 } | 402 } |
411 | 403 |
412 } // namespace | 404 } // namespace |
413 } // namespace views | 405 } // namespace views |
OLD | NEW |