| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "testing/gtest/include/gtest/gtest.h" | |
| 6 #include "ui/views/test/views_test_base.h" | |
| 7 #include "views/controls/native/native_view_host.h" | |
| 8 #include "views/view.h" | |
| 9 #include "views/widget/native_widget_private.h" | |
| 10 #include "views/widget/native_widget_test_utils.h" | |
| 11 #include "views/widget/widget.h" | |
| 12 | |
| 13 namespace views { | |
| 14 | |
| 15 class ScopedTestWidget { | |
| 16 public: | |
| 17 ScopedTestWidget(internal::NativeWidgetPrivate* native_widget) | |
| 18 : native_widget_(native_widget) { | |
| 19 } | |
| 20 ~ScopedTestWidget() { | |
| 21 // |CloseNow| deletes both |native_widget_| and its associated | |
| 22 // |Widget|. | |
| 23 native_widget_->GetWidget()->CloseNow(); | |
| 24 } | |
| 25 | |
| 26 internal::NativeWidgetPrivate* operator->() const { | |
| 27 return native_widget_; | |
| 28 } | |
| 29 internal::NativeWidgetPrivate* get() const { return native_widget_; } | |
| 30 | |
| 31 private: | |
| 32 internal::NativeWidgetPrivate* native_widget_; | |
| 33 DISALLOW_COPY_AND_ASSIGN(ScopedTestWidget); | |
| 34 }; | |
| 35 | |
| 36 class NativeWidgetTest : public ViewsTestBase { | |
| 37 public: | |
| 38 NativeWidgetTest() {} | |
| 39 virtual ~NativeWidgetTest() {} | |
| 40 | |
| 41 private: | |
| 42 DISALLOW_COPY_AND_ASSIGN(NativeWidgetTest); | |
| 43 }; | |
| 44 | |
| 45 TEST_F(NativeWidgetTest, CreateNativeWidget) { | |
| 46 ScopedTestWidget widget(internal::CreateNativeWidget()); | |
| 47 EXPECT_TRUE(widget->GetWidget()->GetNativeView() != NULL); | |
| 48 } | |
| 49 | |
| 50 TEST_F(NativeWidgetTest, GetNativeWidgetForNativeView) { | |
| 51 ScopedTestWidget widget(internal::CreateNativeWidget()); | |
| 52 EXPECT_EQ(widget.get(), | |
| 53 internal::NativeWidgetPrivate::GetNativeWidgetForNativeView( | |
| 54 widget->GetWidget()->GetNativeView())); | |
| 55 } | |
| 56 | |
| 57 // |widget| has the toplevel NativeWidget. | |
| 58 TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) { | |
| 59 ScopedTestWidget widget(internal::CreateNativeWidget()); | |
| 60 EXPECT_EQ(widget.get(), | |
| 61 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( | |
| 62 widget->GetWidget()->GetNativeView())); | |
| 63 } | |
| 64 | |
| 65 // |toplevel_widget| has the toplevel NativeWidget. | |
| 66 TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) { | |
| 67 ScopedTestWidget toplevel_widget(internal::CreateNativeWidget()); | |
| 68 | |
| 69 // |toplevel_widget| owns |child_host|. | |
| 70 NativeViewHost* child_host = new NativeViewHost; | |
| 71 toplevel_widget->GetWidget()->SetContentsView(child_host); | |
| 72 | |
| 73 // |child_host| owns |child_widget|. | |
| 74 internal::NativeWidgetPrivate* child_widget = | |
| 75 internal::CreateNativeSubWidget(); | |
| 76 child_host->Attach(child_widget->GetWidget()->GetNativeView()); | |
| 77 | |
| 78 EXPECT_EQ(toplevel_widget.get(), | |
| 79 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( | |
| 80 child_widget->GetWidget()->GetNativeView())); | |
| 81 } | |
| 82 | |
| 83 } // namespace views | |
| OLD | NEW |