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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 class MockWindowObserver : public aura::WindowObserver { | 319 class MockWindowObserver : public aura::WindowObserver { |
319 public: | 320 public: |
320 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); | 321 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); |
321 }; | 322 }; |
322 | 323 |
323 } // namespace | 324 } // namespace |
324 | 325 |
325 class RenderWidgetHostViewAuraTest : public testing::Test { | 326 class RenderWidgetHostViewAuraTest : public testing::Test { |
326 public: | 327 public: |
327 RenderWidgetHostViewAuraTest() | 328 RenderWidgetHostViewAuraTest() |
328 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 329 : widget_host_uses_shutdown_to_destroy_(false), |
| 330 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
329 | 331 |
330 void SetUpEnvironment() { | 332 void SetUpEnvironment() { |
331 ImageTransportFactory::InitializeForUnitTests( | 333 ImageTransportFactory::InitializeForUnitTests( |
332 scoped_ptr<ImageTransportFactory>( | 334 scoped_ptr<ImageTransportFactory>( |
333 new NoTransportImageTransportFactory)); | 335 new NoTransportImageTransportFactory)); |
334 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 336 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
335 aura_test_helper_->SetUp( | 337 aura_test_helper_->SetUp( |
336 ImageTransportFactory::GetInstance()->GetContextFactory()); | 338 ImageTransportFactory::GetInstance()->GetContextFactory()); |
337 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 339 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
338 | 340 |
(...skipping 14 matching lines...) Expand all Loading... |
353 &delegate_, process_host_, MSG_ROUTING_NONE, false); | 355 &delegate_, process_host_, MSG_ROUTING_NONE, false); |
354 widget_host_->Init(); | 356 widget_host_->Init(); |
355 view_ = new FakeRenderWidgetHostViewAura(widget_host_); | 357 view_ = new FakeRenderWidgetHostViewAura(widget_host_); |
356 } | 358 } |
357 | 359 |
358 void TearDownEnvironment() { | 360 void TearDownEnvironment() { |
359 sink_ = NULL; | 361 sink_ = NULL; |
360 process_host_ = NULL; | 362 process_host_ = NULL; |
361 if (view_) | 363 if (view_) |
362 view_->Destroy(); | 364 view_->Destroy(); |
363 delete widget_host_; | 365 |
| 366 if (widget_host_uses_shutdown_to_destroy_) |
| 367 widget_host_->Shutdown(); |
| 368 else |
| 369 delete widget_host_; |
364 | 370 |
365 parent_view_->Destroy(); | 371 parent_view_->Destroy(); |
366 delete parent_host_; | 372 delete parent_host_; |
367 | 373 |
368 browser_context_.reset(); | 374 browser_context_.reset(); |
369 aura_test_helper_->TearDown(); | 375 aura_test_helper_->TearDown(); |
370 | 376 |
371 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 377 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
372 message_loop_.RunUntilIdle(); | 378 message_loop_.RunUntilIdle(); |
373 ImageTransportFactory::Terminate(); | 379 ImageTransportFactory::Terminate(); |
374 } | 380 } |
375 | 381 |
376 virtual void SetUp() { SetUpEnvironment(); } | 382 virtual void SetUp() { SetUpEnvironment(); } |
377 | 383 |
378 virtual void TearDown() { TearDownEnvironment(); } | 384 virtual void TearDown() { TearDownEnvironment(); } |
379 | 385 |
| 386 void set_widget_host_uses_shutdown_to_destroy(bool use) { |
| 387 widget_host_uses_shutdown_to_destroy_ = use; |
| 388 } |
| 389 |
380 protected: | 390 protected: |
| 391 // If true, the calls RWH::Shutdown() instead of deleting RWH. |
| 392 bool widget_host_uses_shutdown_to_destroy_; |
| 393 |
381 base::MessageLoopForUI message_loop_; | 394 base::MessageLoopForUI message_loop_; |
382 BrowserThreadImpl browser_thread_for_ui_; | 395 BrowserThreadImpl browser_thread_for_ui_; |
383 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 396 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
384 scoped_ptr<BrowserContext> browser_context_; | 397 scoped_ptr<BrowserContext> browser_context_; |
385 MockRenderWidgetHostDelegate delegate_; | 398 MockRenderWidgetHostDelegate delegate_; |
386 MockRenderProcessHost* process_host_; | 399 MockRenderProcessHost* process_host_; |
387 | 400 |
388 // Tests should set these to NULL if they've already triggered their | 401 // Tests should set these to NULL if they've already triggered their |
389 // destruction. | 402 // destruction. |
390 RenderWidgetHostImpl* parent_host_; | 403 RenderWidgetHostImpl* parent_host_; |
391 RenderWidgetHostViewAura* parent_view_; | 404 RenderWidgetHostViewAura* parent_view_; |
392 | 405 |
393 // Tests should set these to NULL if they've already triggered their | 406 // Tests should set these to NULL if they've already triggered their |
394 // destruction. | 407 // destruction. |
395 RenderWidgetHostImpl* widget_host_; | 408 RenderWidgetHostImpl* widget_host_; |
396 FakeRenderWidgetHostViewAura* view_; | 409 FakeRenderWidgetHostViewAura* view_; |
397 | 410 |
398 IPC::TestSink* sink_; | 411 IPC::TestSink* sink_; |
399 | 412 |
400 private: | 413 private: |
401 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 414 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
402 }; | 415 }; |
403 | 416 |
| 417 // Helper class to instantiate RenderWidgetHostViewGuest which is backed |
| 418 // by an aura platform view. |
| 419 class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest { |
| 420 public: |
| 421 RenderWidgetHostViewGuestAuraTest() { |
| 422 // Use RWH::Shutdown to destroy RWH, instead of deleting. |
| 423 // This will ensure that the RenderWidgetHostViewGuest is not leaked and |
| 424 // is deleted properly upon RWH going away. |
| 425 set_widget_host_uses_shutdown_to_destroy(true); |
| 426 } |
| 427 |
| 428 // We explicitly invoke SetUp to allow gesture debounce customization. |
| 429 virtual void SetUp() { |
| 430 RenderWidgetHostViewAuraTest::SetUp(); |
| 431 |
| 432 guest_view_weak_ = (new RenderWidgetHostViewGuest( |
| 433 widget_host_, NULL, view_->GetWeakPtr()))->GetWeakPtr(); |
| 434 } |
| 435 |
| 436 virtual void TearDown() { |
| 437 // Internal override to do nothing, we clean up ourselves in the test body. |
| 438 // This helps us test that |guest_view_weak_| does not leak. |
| 439 } |
| 440 |
| 441 protected: |
| 442 base::WeakPtr<RenderWidgetHostViewBase> guest_view_weak_; |
| 443 |
| 444 private: |
| 445 |
| 446 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest); |
| 447 }; |
| 448 |
404 class RenderWidgetHostViewAuraOverscrollTest | 449 class RenderWidgetHostViewAuraOverscrollTest |
405 : public RenderWidgetHostViewAuraTest { | 450 : public RenderWidgetHostViewAuraTest { |
406 public: | 451 public: |
407 RenderWidgetHostViewAuraOverscrollTest() {} | 452 RenderWidgetHostViewAuraOverscrollTest() {} |
408 | 453 |
409 // We explicitly invoke SetUp to allow gesture debounce customization. | 454 // We explicitly invoke SetUp to allow gesture debounce customization. |
410 virtual void SetUp() {} | 455 virtual void SetUp() {} |
411 | 456 |
412 protected: | 457 protected: |
413 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) { | 458 void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) { |
(...skipping 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2847 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); | 2892 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
2848 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); | 2893 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
2849 | 2894 |
2850 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 2895 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
2851 blink::WebGestureDeviceTouchscreen); | 2896 blink::WebGestureDeviceTouchscreen); |
2852 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); | 2897 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
2853 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); | 2898 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
2854 EXPECT_EQ(3U, sink_->message_count()); | 2899 EXPECT_EQ(3U, sink_->message_count()); |
2855 } | 2900 } |
2856 | 2901 |
| 2902 // Tests that when view initiated shutdown happens (i.e. RWHView is deleted |
| 2903 // before RWH), we clean up properly and don't leak the RWHVGuest. |
| 2904 TEST_F(RenderWidgetHostViewGuestAuraTest, GuestViewDoesNotLeak) { |
| 2905 TearDownEnvironment(); |
| 2906 ASSERT_FALSE(guest_view_weak_.get()); |
| 2907 } |
| 2908 |
2857 } // namespace content | 2909 } // namespace content |
OLD | NEW |