| OLD | NEW |
| 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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/compositor_frame.h" |
| 14 #include "cc/output/compositor_frame_metadata.h" | 14 #include "cc/output/compositor_frame_metadata.h" |
| 15 #include "cc/output/copy_output_request.h" | 15 #include "cc/output/copy_output_request.h" |
| 16 #include "cc/surfaces/surface.h" | 16 #include "cc/surfaces/surface.h" |
| 17 #include "cc/surfaces/surface_manager.h" | 17 #include "cc/surfaces/surface_manager.h" |
| 18 #include "content/browser/browser_thread_impl.h" | 18 #include "content/browser/browser_thread_impl.h" |
| 19 #include "content/browser/compositor/resize_lock.h" | 19 #include "content/browser/compositor/resize_lock.h" |
| 20 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 20 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| 21 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 21 #include "content/browser/renderer_host/overscroll_controller.h" | 22 #include "content/browser/renderer_host/overscroll_controller.h" |
| 22 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 23 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 24 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 24 #include "content/browser/renderer_host/render_widget_host_impl.h" | 25 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 25 #include "content/common/gpu/client/gl_helper.h" | 26 #include "content/common/gpu/client/gl_helper.h" |
| 26 #include "content/common/gpu/gpu_messages.h" | 27 #include "content/common/gpu/gpu_messages.h" |
| 27 #include "content/common/host_shared_bitmap_manager.h" | 28 #include "content/common/host_shared_bitmap_manager.h" |
| 28 #include "content/common/input/synthetic_web_input_event_builders.h" | 29 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 29 #include "content/common/input_messages.h" | 30 #include "content/common/input_messages.h" |
| 30 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 callback.Run(success); | 215 callback.Run(success); |
| 215 } | 216 } |
| 216 | 217 |
| 217 private: | 218 private: |
| 218 gfx::Size size_; | 219 gfx::Size size_; |
| 219 base::Callback<void(bool)> callback_; | 220 base::Callback<void(bool)> callback_; |
| 220 }; | 221 }; |
| 221 | 222 |
| 222 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { | 223 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { |
| 223 public: | 224 public: |
| 224 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) | 225 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget, |
| 225 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} | 226 bool is_guest_view_hack) |
| 227 : RenderWidgetHostViewAura(widget, is_guest_view_hack), |
| 228 has_resize_lock_(false) {} |
| 226 | 229 |
| 227 virtual ~FakeRenderWidgetHostViewAura() {} | 230 virtual ~FakeRenderWidgetHostViewAura() {} |
| 228 | 231 |
| 229 virtual scoped_ptr<ResizeLock> CreateResizeLock( | 232 virtual scoped_ptr<ResizeLock> CreateResizeLock( |
| 230 bool defer_compositor_lock) override { | 233 bool defer_compositor_lock) override { |
| 231 gfx::Size desired_size = window()->bounds().size(); | 234 gfx::Size desired_size = window()->bounds().size(); |
| 232 return scoped_ptr<ResizeLock>( | 235 return scoped_ptr<ResizeLock>( |
| 233 new FakeResizeLock(desired_size, defer_compositor_lock)); | 236 new FakeResizeLock(desired_size, defer_compositor_lock)); |
| 234 } | 237 } |
| 235 | 238 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 class MockWindowObserver : public aura::WindowObserver { | 321 class MockWindowObserver : public aura::WindowObserver { |
| 319 public: | 322 public: |
| 320 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); | 323 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); |
| 321 }; | 324 }; |
| 322 | 325 |
| 323 } // namespace | 326 } // namespace |
| 324 | 327 |
| 325 class RenderWidgetHostViewAuraTest : public testing::Test { | 328 class RenderWidgetHostViewAuraTest : public testing::Test { |
| 326 public: | 329 public: |
| 327 RenderWidgetHostViewAuraTest() | 330 RenderWidgetHostViewAuraTest() |
| 328 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 331 : widget_host_uses_shutdown_to_destroy_(false), |
| 332 is_guest_view_hack_(false), |
| 333 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
| 329 | 334 |
| 330 void SetUpEnvironment() { | 335 void SetUpEnvironment() { |
| 331 ImageTransportFactory::InitializeForUnitTests( | 336 ImageTransportFactory::InitializeForUnitTests( |
| 332 scoped_ptr<ImageTransportFactory>( | 337 scoped_ptr<ImageTransportFactory>( |
| 333 new NoTransportImageTransportFactory)); | 338 new NoTransportImageTransportFactory)); |
| 334 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 339 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
| 335 aura_test_helper_->SetUp( | 340 aura_test_helper_->SetUp( |
| 336 ImageTransportFactory::GetInstance()->GetContextFactory()); | 341 ImageTransportFactory::GetInstance()->GetContextFactory()); |
| 337 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 342 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
| 338 | 343 |
| 339 browser_context_.reset(new TestBrowserContext); | 344 browser_context_.reset(new TestBrowserContext); |
| 340 process_host_ = new MockRenderProcessHost(browser_context_.get()); | 345 process_host_ = new MockRenderProcessHost(browser_context_.get()); |
| 341 | 346 |
| 342 sink_ = &process_host_->sink(); | 347 sink_ = &process_host_->sink(); |
| 343 | 348 |
| 344 parent_host_ = new RenderWidgetHostImpl( | 349 parent_host_ = new RenderWidgetHostImpl( |
| 345 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 350 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
| 346 parent_view_ = new RenderWidgetHostViewAura(parent_host_); | 351 parent_view_ = new RenderWidgetHostViewAura(parent_host_, |
| 352 is_guest_view_hack_); |
| 347 parent_view_->InitAsChild(NULL); | 353 parent_view_->InitAsChild(NULL); |
| 348 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), | 354 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), |
| 349 aura_test_helper_->root_window(), | 355 aura_test_helper_->root_window(), |
| 350 gfx::Rect()); | 356 gfx::Rect()); |
| 351 | 357 |
| 352 widget_host_ = new RenderWidgetHostImpl( | 358 widget_host_ = new RenderWidgetHostImpl( |
| 353 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 359 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
| 354 widget_host_->Init(); | 360 widget_host_->Init(); |
| 355 view_ = new FakeRenderWidgetHostViewAura(widget_host_); | 361 view_ = new FakeRenderWidgetHostViewAura(widget_host_, is_guest_view_hack_); |
| 356 } | 362 } |
| 357 | 363 |
| 358 void TearDownEnvironment() { | 364 void TearDownEnvironment() { |
| 359 sink_ = NULL; | 365 sink_ = NULL; |
| 360 process_host_ = NULL; | 366 process_host_ = NULL; |
| 361 if (view_) | 367 if (view_) |
| 362 view_->Destroy(); | 368 view_->Destroy(); |
| 363 delete widget_host_; | 369 |
| 370 if (widget_host_uses_shutdown_to_destroy_) |
| 371 widget_host_->Shutdown(); |
| 372 else |
| 373 delete widget_host_; |
| 364 | 374 |
| 365 parent_view_->Destroy(); | 375 parent_view_->Destroy(); |
| 366 delete parent_host_; | 376 delete parent_host_; |
| 367 | 377 |
| 368 browser_context_.reset(); | 378 browser_context_.reset(); |
| 369 aura_test_helper_->TearDown(); | 379 aura_test_helper_->TearDown(); |
| 370 | 380 |
| 371 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 381 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
| 372 message_loop_.RunUntilIdle(); | 382 message_loop_.RunUntilIdle(); |
| 373 ImageTransportFactory::Terminate(); | 383 ImageTransportFactory::Terminate(); |
| 374 } | 384 } |
| 375 | 385 |
| 376 virtual void SetUp() { SetUpEnvironment(); } | 386 virtual void SetUp() override { SetUpEnvironment(); } |
| 377 | 387 |
| 378 virtual void TearDown() { TearDownEnvironment(); } | 388 virtual void TearDown() override { TearDownEnvironment(); } |
| 389 |
| 390 void set_widget_host_uses_shutdown_to_destroy(bool use) { |
| 391 widget_host_uses_shutdown_to_destroy_ = use; |
| 392 } |
| 379 | 393 |
| 380 protected: | 394 protected: |
| 395 // If true, then calls RWH::Shutdown() instead of deleting RWH. |
| 396 bool widget_host_uses_shutdown_to_destroy_; |
| 397 |
| 398 bool is_guest_view_hack_; |
| 399 |
| 381 base::MessageLoopForUI message_loop_; | 400 base::MessageLoopForUI message_loop_; |
| 382 BrowserThreadImpl browser_thread_for_ui_; | 401 BrowserThreadImpl browser_thread_for_ui_; |
| 383 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 402 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 384 scoped_ptr<BrowserContext> browser_context_; | 403 scoped_ptr<BrowserContext> browser_context_; |
| 385 MockRenderWidgetHostDelegate delegate_; | 404 MockRenderWidgetHostDelegate delegate_; |
| 386 MockRenderProcessHost* process_host_; | 405 MockRenderProcessHost* process_host_; |
| 387 | 406 |
| 388 // Tests should set these to NULL if they've already triggered their | 407 // Tests should set these to NULL if they've already triggered their |
| 389 // destruction. | 408 // destruction. |
| 390 RenderWidgetHostImpl* parent_host_; | 409 RenderWidgetHostImpl* parent_host_; |
| 391 RenderWidgetHostViewAura* parent_view_; | 410 RenderWidgetHostViewAura* parent_view_; |
| 392 | 411 |
| 393 // Tests should set these to NULL if they've already triggered their | 412 // Tests should set these to NULL if they've already triggered their |
| 394 // destruction. | 413 // destruction. |
| 395 RenderWidgetHostImpl* widget_host_; | 414 RenderWidgetHostImpl* widget_host_; |
| 396 FakeRenderWidgetHostViewAura* view_; | 415 FakeRenderWidgetHostViewAura* view_; |
| 397 | 416 |
| 398 IPC::TestSink* sink_; | 417 IPC::TestSink* sink_; |
| 399 | 418 |
| 400 private: | 419 private: |
| 401 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 420 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
| 402 }; | 421 }; |
| 403 | 422 |
| 423 // Helper class to instantiate RenderWidgetHostViewGuest which is backed |
| 424 // by an aura platform view. |
| 425 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { |
| 426 public: |
| 427 RenderWidgetHostViewGuestAuraTest() { |
| 428 // Use RWH::Shutdown to destroy RWH, instead of deleting. |
| 429 // This will ensure that the RenderWidgetHostViewGuest is not leaked and |
| 430 // is deleted properly upon RWH going away. |
| 431 set_widget_host_uses_shutdown_to_destroy(true); |
| 432 } |
| 433 |
| 434 // We explicitly invoke SetUp to allow gesture debounce customization. |
| 435 virtual void SetUp() { |
| 436 is_guest_view_hack_ = true; |
| 437 |
| 438 RenderWidgetHostViewAuraTest::SetUp(); |
| 439 |
| 440 guest_view_weak_ = (new RenderWidgetHostViewGuest( |
| 441 widget_host_, NULL, view_->GetWeakPtr()))->GetWeakPtr(); |
| 442 } |
| 443 |
| 444 virtual void TearDown() { |
| 445 // Internal override to do nothing, we clean up ourselves in the test body. |
| 446 // This helps us test that |guest_view_weak_| does not leak. |
| 447 } |
| 448 |
| 449 protected: |
| 450 base::WeakPtr<RenderWidgetHostViewBase> guest_view_weak_; |
| 451 |
| 452 private: |
| 453 |
| 454 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest); |
| 455 }; |
| 456 |
| 404 class RenderWidgetHostViewAuraOverscrollTest | 457 class RenderWidgetHostViewAuraOverscrollTest |
| 405 : public RenderWidgetHostViewAuraTest { | 458 : public RenderWidgetHostViewAuraTest { |
| 406 public: | 459 public: |
| 407 RenderWidgetHostViewAuraOverscrollTest() {} | 460 RenderWidgetHostViewAuraOverscrollTest() {} |
| 408 | 461 |
| 409 // We explicitly invoke SetUp to allow gesture debounce customization. | 462 // We explicitly invoke SetUp to allow gesture debounce customization. |
| 410 virtual void SetUp() {} | 463 virtual void SetUp() {} |
| 411 | 464 |
| 412 protected: | 465 protected: |
| 413 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) { | 466 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) { |
| (...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 scoped_ptr<RenderWidgetHostImpl * []> hosts( | 1625 scoped_ptr<RenderWidgetHostImpl * []> hosts( |
| 1573 new RenderWidgetHostImpl* [renderer_count]); | 1626 new RenderWidgetHostImpl* [renderer_count]); |
| 1574 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( | 1627 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( |
| 1575 new FakeRenderWidgetHostViewAura* [renderer_count]); | 1628 new FakeRenderWidgetHostViewAura* [renderer_count]); |
| 1576 | 1629 |
| 1577 // Create a bunch of renderers. | 1630 // Create a bunch of renderers. |
| 1578 for (size_t i = 0; i < renderer_count; ++i) { | 1631 for (size_t i = 0; i < renderer_count; ++i) { |
| 1579 hosts[i] = new RenderWidgetHostImpl( | 1632 hosts[i] = new RenderWidgetHostImpl( |
| 1580 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 1633 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
| 1581 hosts[i]->Init(); | 1634 hosts[i]->Init(); |
| 1582 views[i] = new FakeRenderWidgetHostViewAura(hosts[i]); | 1635 views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false); |
| 1583 views[i]->InitAsChild(NULL); | 1636 views[i]->InitAsChild(NULL); |
| 1584 aura::client::ParentWindowWithContext( | 1637 aura::client::ParentWindowWithContext( |
| 1585 views[i]->GetNativeView(), | 1638 views[i]->GetNativeView(), |
| 1586 parent_view_->GetNativeView()->GetRootWindow(), | 1639 parent_view_->GetNativeView()->GetRootWindow(), |
| 1587 gfx::Rect()); | 1640 gfx::Rect()); |
| 1588 views[i]->SetSize(view_rect.size()); | 1641 views[i]->SetSize(view_rect.size()); |
| 1589 } | 1642 } |
| 1590 | 1643 |
| 1591 // Make each renderer visible, and swap a frame on it, then make it invisible. | 1644 // Make each renderer visible, and swap a frame on it, then make it invisible. |
| 1592 for (size_t i = 0; i < renderer_count; ++i) { | 1645 for (size_t i = 0; i < renderer_count; ++i) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 scoped_ptr<RenderWidgetHostImpl * []> hosts( | 1787 scoped_ptr<RenderWidgetHostImpl * []> hosts( |
| 1735 new RenderWidgetHostImpl* [renderer_count]); | 1788 new RenderWidgetHostImpl* [renderer_count]); |
| 1736 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( | 1789 scoped_ptr<FakeRenderWidgetHostViewAura * []> views( |
| 1737 new FakeRenderWidgetHostViewAura* [renderer_count]); | 1790 new FakeRenderWidgetHostViewAura* [renderer_count]); |
| 1738 | 1791 |
| 1739 // Create a bunch of renderers. | 1792 // Create a bunch of renderers. |
| 1740 for (size_t i = 0; i < renderer_count; ++i) { | 1793 for (size_t i = 0; i < renderer_count; ++i) { |
| 1741 hosts[i] = new RenderWidgetHostImpl( | 1794 hosts[i] = new RenderWidgetHostImpl( |
| 1742 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 1795 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
| 1743 hosts[i]->Init(); | 1796 hosts[i]->Init(); |
| 1744 views[i] = new FakeRenderWidgetHostViewAura(hosts[i]); | 1797 views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false); |
| 1745 views[i]->InitAsChild(NULL); | 1798 views[i]->InitAsChild(NULL); |
| 1746 aura::client::ParentWindowWithContext( | 1799 aura::client::ParentWindowWithContext( |
| 1747 views[i]->GetNativeView(), | 1800 views[i]->GetNativeView(), |
| 1748 parent_view_->GetNativeView()->GetRootWindow(), | 1801 parent_view_->GetNativeView()->GetRootWindow(), |
| 1749 gfx::Rect()); | 1802 gfx::Rect()); |
| 1750 views[i]->SetSize(view_rect.size()); | 1803 views[i]->SetSize(view_rect.size()); |
| 1751 } | 1804 } |
| 1752 | 1805 |
| 1753 // Make each renderer visible and swap a frame on it. No eviction should | 1806 // Make each renderer visible and swap a frame on it. No eviction should |
| 1754 // occur because all frames are visible. | 1807 // occur because all frames are visible. |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2847 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); | 2900 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2848 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); | 2901 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2849 | 2902 |
| 2850 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 2903 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2851 blink::WebGestureDeviceTouchscreen); | 2904 blink::WebGestureDeviceTouchscreen); |
| 2852 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); | 2905 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2853 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); | 2906 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2854 EXPECT_EQ(3U, sink_->message_count()); | 2907 EXPECT_EQ(3U, sink_->message_count()); |
| 2855 } | 2908 } |
| 2856 | 2909 |
| 2910 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted |
| 2911 // before RWH), we clean up properly and don't leak the RWHVGuest. |
| 2912 TEST_F(RenderWidgetHostViewGuestAuraTest, GuestViewDoesNotLeak) { |
| 2913 TearDownEnvironment(); |
| 2914 ASSERT_FALSE(guest_view_weak_.get()); |
| 2915 } |
| 2916 |
| 2857 } // namespace content | 2917 } // namespace content |
| OLD | NEW |