| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "views/test/views_test_base.h" | 6 #include "views/test/views_test_base.h" |
| 7 #include "views/view.h" | 7 #include "views/view.h" |
| 8 #include "views/controls/native/native_view_host.h" | 8 #include "views/controls/native/native_view_host.h" |
| 9 #include "views/widget/native_widget_private.h" | 9 #include "views/widget/native_widget_private.h" |
| 10 #include "views/widget/widget.h" | 10 #include "views/widget/widget.h" |
| 11 #include "views/widget/native_widget_test_utils.h" | 11 #include "views/widget/native_widget_test_utils.h" |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 | 14 |
| 15 class ScopedTestWidget { | 15 class ScopedTestWidget { |
| 16 public: | 16 public: |
| 17 ScopedTestWidget(internal::NativeWidgetPrivate* native_widget) | 17 ScopedTestWidget(internal::NativeWidgetPrivate* native_widget) |
| 18 : native_widget_(native_widget) { | 18 : native_widget_(native_widget) { |
| 19 } | 19 } |
| 20 ~ScopedTestWidget() { | 20 ~ScopedTestWidget() { |
| 21 // |CloseNow| deletes both |native_widget_| and its associated |
| 22 // |Widget|. |
| 21 native_widget_->GetWidget()->CloseNow(); | 23 native_widget_->GetWidget()->CloseNow(); |
| 22 } | 24 } |
| 23 | 25 |
| 24 internal::NativeWidgetPrivate* operator->() const { | 26 internal::NativeWidgetPrivate* operator->() const { |
| 25 return native_widget_.get(); | 27 return native_widget_; |
| 26 } | 28 } |
| 27 internal::NativeWidgetPrivate* get() const { return native_widget_.get(); } | 29 internal::NativeWidgetPrivate* get() const { return native_widget_; } |
| 28 | 30 |
| 29 private: | 31 private: |
| 30 scoped_ptr<internal::NativeWidgetPrivate> native_widget_; | 32 internal::NativeWidgetPrivate* native_widget_; |
| 31 DISALLOW_COPY_AND_ASSIGN(ScopedTestWidget); | 33 DISALLOW_COPY_AND_ASSIGN(ScopedTestWidget); |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 class NativeWidgetTest : public ViewsTestBase { | 36 class NativeWidgetTest : public ViewsTestBase { |
| 35 public: | 37 public: |
| 36 NativeWidgetTest() {} | 38 NativeWidgetTest() {} |
| 37 virtual ~NativeWidgetTest() {} | 39 virtual ~NativeWidgetTest() {} |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(NativeWidgetTest); | 42 DISALLOW_COPY_AND_ASSIGN(NativeWidgetTest); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 // |widget| has the toplevel NativeWidget. | 57 // |widget| has the toplevel NativeWidget. |
| 56 TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) { | 58 TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) { |
| 57 ScopedTestWidget widget(internal::CreateNativeWidget()); | 59 ScopedTestWidget widget(internal::CreateNativeWidget()); |
| 58 EXPECT_EQ(widget.get(), | 60 EXPECT_EQ(widget.get(), |
| 59 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( | 61 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( |
| 60 widget->GetWidget()->GetNativeView())); | 62 widget->GetWidget()->GetNativeView())); |
| 61 } | 63 } |
| 62 | 64 |
| 63 // |toplevel_widget| has the toplevel NativeWidget. | 65 // |toplevel_widget| has the toplevel NativeWidget. |
| 64 TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) { | 66 TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) { |
| 65 ScopedTestWidget child_widget(internal::CreateNativeWidgetWithParent(NULL)); | |
| 66 ScopedTestWidget toplevel_widget(internal::CreateNativeWidget()); | 67 ScopedTestWidget toplevel_widget(internal::CreateNativeWidget()); |
| 67 | 68 |
| 69 // |toplevel_widget| owns |child_host|. |
| 68 NativeViewHost* child_host = new NativeViewHost; | 70 NativeViewHost* child_host = new NativeViewHost; |
| 69 toplevel_widget->GetWidget()->SetContentsView(child_host); | 71 toplevel_widget->GetWidget()->SetContentsView(child_host); |
| 72 |
| 73 // |child_host| owns |child_widget|. |
| 74 internal::NativeWidgetPrivate* child_widget = |
| 75 internal::CreateNativeSubWidget(); |
| 70 child_host->Attach(child_widget->GetWidget()->GetNativeView()); | 76 child_host->Attach(child_widget->GetWidget()->GetNativeView()); |
| 71 | 77 |
| 72 EXPECT_EQ(toplevel_widget.get(), | 78 EXPECT_EQ(toplevel_widget.get(), |
| 73 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( | 79 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( |
| 74 child_widget->GetWidget()->GetNativeView())); | 80 child_widget->GetWidget()->GetNativeView())); |
| 75 } | 81 } |
| 76 | 82 |
| 77 } // namespace views | 83 } // namespace views |
| OLD | NEW |