diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 18:13:02 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 18:13:02 +0000 |
commit | 31ef2a843d82cc26d00f4d49a6d277ea4bff5817 (patch) | |
tree | 2d38620751838520df742f6a949ac2ab2d450da7 /views/widget | |
parent | 0f9aa0321fd8e7f37e1ca940e26c0ae80cc5ca26 (diff) | |
download | chromium_src-31ef2a843d82cc26d00f4d49a6d277ea4bff5817.zip chromium_src-31ef2a843d82cc26d00f4d49a6d277ea4bff5817.tar.gz chromium_src-31ef2a843d82cc26d00f4d49a6d277ea4bff5817.tar.bz2 |
Views views_unittests native widget tests leak
Eliminates leaks from NativeWidgetTest.*. Adds additional test target to valgrind wrapper script. Refactors native_widget_test_utils_{gtk|win}.cc to avoid duplication.
BUG=87805
TEST=tools/valgrind/chrome_tests.sh views --gtest_filter=NativeWidgetTest.*
Review URL: http://codereview.chromium.org/7272044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90979 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/native_widget_test_utils.h | 6 | ||||
-rw-r--r-- | views/widget/native_widget_test_utils_gtk.cc | 26 | ||||
-rw-r--r-- | views/widget/native_widget_test_utils_win.cc | 28 | ||||
-rw-r--r-- | views/widget/native_widget_unittest.cc | 14 |
4 files changed, 38 insertions, 36 deletions
diff --git a/views/widget/native_widget_test_utils.h b/views/widget/native_widget_test_utils.h index 2499a76..cd51d38 100644 --- a/views/widget/native_widget_test_utils.h +++ b/views/widget/native_widget_test_utils.h @@ -11,10 +11,10 @@ class View; namespace internal { class NativeWidgetPrivate; -// Create dummy Widgets for use in testing. +// Create dummy widgets for use in testing. Caller owns the returned +// |NativeWidgetPrivate| object which, in turn, owns the associated Widget. NativeWidgetPrivate* CreateNativeWidget(); -NativeWidgetPrivate* CreateNativeWidgetWithContents(View* contents_view); -NativeWidgetPrivate* CreateNativeWidgetWithParent(NativeWidgetPrivate* parent); +NativeWidgetPrivate* CreateNativeSubWidget(); } // namespace internal } // namespace views diff --git a/views/widget/native_widget_test_utils_gtk.cc b/views/widget/native_widget_test_utils_gtk.cc index dbb1529..3217f99 100644 --- a/views/widget/native_widget_test_utils_gtk.cc +++ b/views/widget/native_widget_test_utils_gtk.cc @@ -11,27 +11,25 @@ namespace views { namespace internal { -NativeWidgetPrivate* CreateNativeWidget() { - return CreateNativeWidgetWithContents(new View); -} +namespace { -NativeWidgetPrivate* CreateNativeWidgetWithContents(View* contents_view) { +NativeWidgetPrivate* CreateNativeWidgetOfType(Widget::InitParams::Type type) { Widget* widget = new Widget; - Widget::InitParams params(Widget::InitParams::TYPE_POPUP); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + Widget::InitParams params(type); + params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; params.bounds = gfx::Rect(10, 10, 200, 200); widget->Init(params); return widget->native_widget_private(); } -NativeWidgetPrivate* CreateNativeWidgetWithParent(NativeWidgetPrivate* parent) { - Widget* widget = new Widget; - Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.parent = parent ? parent->GetWidget()->GetNativeView() : NULL; - params.bounds = gfx::Rect(10, 10, 200, 200); - widget->Init(params); - return widget->native_widget_private(); +} // namespace + +NativeWidgetPrivate* CreateNativeWidget() { + return CreateNativeWidgetOfType(Widget::InitParams::TYPE_POPUP); +} + +NativeWidgetPrivate* CreateNativeSubWidget() { + return CreateNativeWidgetOfType(Widget::InitParams::TYPE_CONTROL); } } // namespace internal diff --git a/views/widget/native_widget_test_utils_win.cc b/views/widget/native_widget_test_utils_win.cc index b6a4184..7e8926a 100644 --- a/views/widget/native_widget_test_utils_win.cc +++ b/views/widget/native_widget_test_utils_win.cc @@ -11,28 +11,26 @@ namespace views { namespace internal { -NativeWidgetPrivate* CreateNativeWidget() { - return CreateNativeWidgetWithContents(new View); -} +namespace { -NativeWidgetPrivate* CreateNativeWidgetWithContents(View* contents_view) { +NativeWidgetPrivate* CreateNativeWidgetOfType(Widget::InitParams::Type type) { Widget* widget = new Widget; - Widget::InitParams params(Widget::InitParams::TYPE_POPUP); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + Widget::InitParams params(type); + params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; + params.child = false; // Implicitly set to true by ctor with TYPE_CONTROL. params.bounds = gfx::Rect(10, 10, 200, 200); widget->Init(params); return widget->native_widget_private(); } -NativeWidgetPrivate* CreateNativeWidgetWithParent(NativeWidgetPrivate* parent) { - Widget* widget = new Widget; - Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.child = false; // Implicitly set to true by ctor with TYPE_CONTROL. - params.parent = parent ? parent->GetWidget()->GetNativeView() : NULL; - params.bounds = gfx::Rect(10, 10, 200, 200); - widget->Init(params); - return widget->native_widget_private(); +} // namespace + +NativeWidgetPrivate* CreateNativeWidget() { + return CreateNativeWidgetOfType(Widget::InitParams::TYPE_POPUP); +} + +NativeWidgetPrivate* CreateNativeSubWidget() { + return CreateNativeWidgetOfType(Widget::InitParams::TYPE_CONTROL); } } // namespace internal diff --git a/views/widget/native_widget_unittest.cc b/views/widget/native_widget_unittest.cc index 158f7c6..9c7218d 100644 --- a/views/widget/native_widget_unittest.cc +++ b/views/widget/native_widget_unittest.cc @@ -18,16 +18,18 @@ class ScopedTestWidget { : native_widget_(native_widget) { } ~ScopedTestWidget() { + // |CloseNow| deletes both |native_widget_| and its associated + // |Widget|. native_widget_->GetWidget()->CloseNow(); } internal::NativeWidgetPrivate* operator->() const { - return native_widget_.get(); + return native_widget_; } - internal::NativeWidgetPrivate* get() const { return native_widget_.get(); } + internal::NativeWidgetPrivate* get() const { return native_widget_; } private: - scoped_ptr<internal::NativeWidgetPrivate> native_widget_; + internal::NativeWidgetPrivate* native_widget_; DISALLOW_COPY_AND_ASSIGN(ScopedTestWidget); }; @@ -62,11 +64,15 @@ TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) { // |toplevel_widget| has the toplevel NativeWidget. TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) { - ScopedTestWidget child_widget(internal::CreateNativeWidgetWithParent(NULL)); ScopedTestWidget toplevel_widget(internal::CreateNativeWidget()); + // |toplevel_widget| owns |child_host|. NativeViewHost* child_host = new NativeViewHost; toplevel_widget->GetWidget()->SetContentsView(child_host); + + // |child_host| owns |child_widget|. + internal::NativeWidgetPrivate* child_widget = + internal::CreateNativeSubWidget(); child_host->Attach(child_widget->GetWidget()->GetNativeView()); EXPECT_EQ(toplevel_widget.get(), |