Make ViewsTestHelpers DCHECK that all Widgets are destroyed before unit test tear...
commit71b440acbb273cd8fcc22a587b4604038cfd3a1e
authortapted <tapted@chromium.org>
Thu, 18 Jun 2015 02:54:09 +0000 (17 19:54 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 18 Jun 2015 02:55:47 +0000 (18 02:55 +0000)
treebc6bd5a8f39e21fdd70840c124736effc677b676
parent6e6b751edaef93725d8ecd8142c32704bfe422e7
Make ViewsTestHelpers DCHECK that all Widgets are destroyed before unit test tear down

Running custom_button_unittest.cc on Mac resulted in some use-after-free
errors.

The problem: Widgets hold on to a Compositor. If they are not all closed
when the ContextFactory is torn down by ViewsTestBase, then bad stuff
happens when the Widget is closed afterwards (e.g. by
scoped_ptr<Widget>s on the test harness with WIDGET_OWNS_NATIVE_WIDGET).

Since many tests do not try to create Desktop Aura widgets, they
will instead create Ash-style Widgets that are owned by the RootWindow.
These get automatically destroyed when the RootWindow is torn down by
AuraTestHelper. However, on Mac there are only desktop widgets, so any
unclosed widgets remain "unowned". A browser_test can rely on
Widget::CloseAllSecondaryWidgets(), but not a unit_test.

This CL adds a check to ViewsTestHelperMac to anticipate these
use-after-frees. The same check is added to ViewsTestHelperAura to help
tests detect these errors before going through the CQ.

Tests that were not closing Widgets are updated. Most unit tests did
already close their Widgets. For the majority of those that were not, it
seems accidental.

BUG=412234

Review URL: https://codereview.chromium.org/1180623007

Cr-Commit-Position: refs/heads/master@{#334985}
17 files changed:
chrome/browser/ui/views/desktop_media_picker_views_unittest.cc
ui/chromeos/ime/candidate_window_view_unittest.cc
ui/message_center/views/message_popup_collection_unittest.cc
ui/views/controls/button/custom_button_unittest.cc
ui/views/controls/native/native_view_host_aura_unittest.cc
ui/views/controls/native/native_view_host_test_base.cc
ui/views/controls/native/native_view_host_test_base.h
ui/views/test/views_test_helper_aura.cc
ui/views/test/views_test_helper_mac.h
ui/views/test/views_test_helper_mac.mm
ui/views/touchui/touch_selection_menu_runner_views_unittest.cc
ui/views/view_unittest.cc
ui/views/view_unittest_aura.cc
ui/views/widget/native_widget_mac_unittest.mm
ui/views/widget/native_widget_unittest.cc
ui/views/widget/widget_unittest.cc
ui/views/window/dialog_delegate_unittest.cc