Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Unified Diff: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm

Issue 647613002: Fix RenderWidgetHostViewGuest leak. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add is_guest_view_hack_ to RWHV Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
diff --git a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
index 2df6c19e113c35fd2bbc83301303f4e0018c484f..6174baad0cffc60420ac9928facffe4d0dc89531 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
@@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/compositor/test/no_transport_image_transport_factory.h"
+#include "content/browser/frame_host/render_widget_host_view_guest.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/common/gpu/gpu_messages.h"
@@ -185,9 +186,7 @@ class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness {
virtual void TearDown() {
// Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs.
rwhv_cocoa_.reset();
- pool_.Recycle();
- base::MessageLoop::current()->RunUntilIdle();
- pool_.Recycle();
+ RecycleAndWait();
// See comment in SetUp().
test_rvh()->SetView(static_cast<RenderWidgetHostViewBase*>(old_rwhv_));
@@ -196,6 +195,16 @@ class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness {
ImageTransportFactory::Terminate();
RenderViewHostImplTestHarness::TearDown();
}
+
+ void RecycleAndWait() {
+ pool_.Recycle();
+ base::MessageLoop::current()->RunUntilIdle();
+ pool_.Recycle();
+ }
+
+ void CheckGuestView() {
+ // Intentionally empty.
+ }
protected:
private:
// This class isn't derived from PlatformTest.
@@ -783,4 +792,45 @@ TEST_F(RenderWidgetHostViewMacTest, IgnoreEmptyUnhandledWheelEvent) {
host->Shutdown();
}
+// Tests that when view initiated shutdown happens (i.e. RWHView is deleted
+// before RWH), we clean up properly and don't leak the RWHVGuest.
+TEST_F(RenderWidgetHostViewMacTest, GuestViewDoesNotLeak) {
+ MockRenderWidgetHostDelegate delegate;
+ TestBrowserContext browser_context;
+ MockRenderProcessHost* process_host =
+ new MockRenderProcessHost(&browser_context);
+
+ // Owned by its |cocoa_view()|.
+ MockRenderWidgetHostImpl* rwh = new MockRenderWidgetHostImpl(
+ &delegate, process_host, MSG_ROUTING_NONE);
+ RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh);
+
+ // Add a delegate to the view.
+ base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate(
+ [[MockRenderWidgetHostViewMacDelegate alloc] init]);
+ view->SetDelegate(view_delegate.get());
+
+ base::WeakPtr<RenderWidgetHostViewBase> guest_rwhv_weak =
+ (new RenderWidgetHostViewGuest(
+ rwh, NULL, view->GetWeakPtr()))->GetWeakPtr();
+
+ // Remove the cocoa_view() so |view| also goes away before |rwh|.
+ {
+ base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa;
+ rwhv_cocoa.reset([view->cocoa_view() retain]);
+ }
+ RecycleAndWait();
+
+ // Clean up.
+ rwh->Shutdown();
+
+ // PostTask so |guest_rwhv_weak| gets a chance to delete itself.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&RenderWidgetHostViewMacTest::CheckGuestView,
+ base::Unretained(this)));
piman 2014/10/14 23:48:06 nit: how about creating a RunLoop and posting its
lazyboy 2014/10/15 04:50:11 Done this one.
+ base::RunLoop().RunUntilIdle();
+ ASSERT_FALSE(guest_rwhv_weak.get());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698