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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #include "base/mac/scoped_nsautorelease_pool.h" 8 #include "base/mac/scoped_nsautorelease_pool.h"
9 #include "base/mac/sdk_forward_declarations.h" 9 #include "base/mac/sdk_forward_declarations.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/compositor/test/no_transport_image_transport_factory.h " 12 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
13 #include "content/browser/frame_host/render_widget_host_view_guest.h"
13 #include "content/browser/gpu/compositor_util.h" 14 #include "content/browser/gpu/compositor_util.h"
14 #include "content/browser/renderer_host/render_widget_host_delegate.h" 15 #include "content/browser/renderer_host/render_widget_host_delegate.h"
15 #include "content/common/gpu/gpu_messages.h" 16 #include "content/common/gpu/gpu_messages.h"
16 #include "content/common/input_messages.h" 17 #include "content/common/input_messages.h"
17 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
18 #include "content/public/browser/notification_types.h" 19 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_widget_host_view_mac_delegate.h" 20 #include "content/public/browser/render_widget_host_view_mac_delegate.h"
20 #include "content/public/test/mock_render_process_host.h" 21 #include "content/public/test/mock_render_process_host.h"
21 #include "content/public/test/test_browser_context.h" 22 #include "content/public/test/test_browser_context.h"
22 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // stored view in |TearDown()|. 179 // stored view in |TearDown()|.
179 old_rwhv_ = rvh()->GetView(); 180 old_rwhv_ = rvh()->GetView();
180 181
181 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|. 182 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|.
182 rwhv_mac_ = new RenderWidgetHostViewMac(rvh()); 183 rwhv_mac_ = new RenderWidgetHostViewMac(rvh());
183 rwhv_cocoa_.reset([rwhv_mac_->cocoa_view() retain]); 184 rwhv_cocoa_.reset([rwhv_mac_->cocoa_view() retain]);
184 } 185 }
185 virtual void TearDown() { 186 virtual void TearDown() {
186 // Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs. 187 // Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs.
187 rwhv_cocoa_.reset(); 188 rwhv_cocoa_.reset();
188 pool_.Recycle(); 189 RecycleAndWait();
189 base::MessageLoop::current()->RunUntilIdle();
190 pool_.Recycle();
191 190
192 // See comment in SetUp(). 191 // See comment in SetUp().
193 test_rvh()->SetView(static_cast<RenderWidgetHostViewBase*>(old_rwhv_)); 192 test_rvh()->SetView(static_cast<RenderWidgetHostViewBase*>(old_rwhv_));
194 193
195 if (IsDelegatedRendererEnabled()) 194 if (IsDelegatedRendererEnabled())
196 ImageTransportFactory::Terminate(); 195 ImageTransportFactory::Terminate();
197 RenderViewHostImplTestHarness::TearDown(); 196 RenderViewHostImplTestHarness::TearDown();
198 } 197 }
198
199 void RecycleAndWait() {
200 pool_.Recycle();
201 base::MessageLoop::current()->RunUntilIdle();
202 pool_.Recycle();
203 }
204
205 void CheckGuestView() {
206 // Intentionally empty.
207 }
199 protected: 208 protected:
200 private: 209 private:
201 // This class isn't derived from PlatformTest. 210 // This class isn't derived from PlatformTest.
202 base::mac::ScopedNSAutoreleasePool pool_; 211 base::mac::ScopedNSAutoreleasePool pool_;
203 212
204 RenderWidgetHostView* old_rwhv_; 213 RenderWidgetHostView* old_rwhv_;
205 214
206 protected: 215 protected:
207 RenderWidgetHostViewMac* rwhv_mac_; 216 RenderWidgetHostViewMac* rwhv_mac_;
208 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_; 217 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_;
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 new InputHostMsg_HandleInputEvent_ACK(0, unhandled_ack)); 785 new InputHostMsg_HandleInputEvent_ACK(0, unhandled_ack));
777 host->OnMessageReceived(*response2); 786 host->OnMessageReceived(*response2);
778 787
779 // Check that the view delegate ignored the empty unhandled wheel event. 788 // Check that the view delegate ignored the empty unhandled wheel event.
780 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); 789 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived);
781 790
782 // Clean up. 791 // Clean up.
783 host->Shutdown(); 792 host->Shutdown();
784 } 793 }
785 794
795 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted
796 // before RWH), we clean up properly and don't leak the RWHVGuest.
797 TEST_F(RenderWidgetHostViewMacTest, GuestViewDoesNotLeak) {
798 MockRenderWidgetHostDelegate delegate;
799 TestBrowserContext browser_context;
800 MockRenderProcessHost* process_host =
801 new MockRenderProcessHost(&browser_context);
802
803 // Owned by its |cocoa_view()|.
804 MockRenderWidgetHostImpl* rwh = new MockRenderWidgetHostImpl(
805 &delegate, process_host, MSG_ROUTING_NONE);
806 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh);
807
808 // Add a delegate to the view.
809 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate(
810 [[MockRenderWidgetHostViewMacDelegate alloc] init]);
811 view->SetDelegate(view_delegate.get());
812
813 base::WeakPtr<RenderWidgetHostViewBase> guest_rwhv_weak =
814 (new RenderWidgetHostViewGuest(
815 rwh, NULL, view->GetWeakPtr()))->GetWeakPtr();
816
817 // Remove the cocoa_view() so |view| also goes away before |rwh|.
818 {
819 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa;
820 rwhv_cocoa.reset([view->cocoa_view() retain]);
821 }
822 RecycleAndWait();
823
824 // Clean up.
825 rwh->Shutdown();
826
827 // PostTask so |guest_rwhv_weak| gets a chance to delete itself.
828 content::BrowserThread::PostTask(
829 content::BrowserThread::UI, FROM_HERE,
830 base::Bind(&RenderWidgetHostViewMacTest::CheckGuestView,
831 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.
832 base::RunLoop().RunUntilIdle();
833 ASSERT_FALSE(guest_rwhv_weak.get());
834 }
835
786 } // namespace content 836 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698