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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "cc/surfaces/surface_manager.h" | 24 #include "cc/surfaces/surface_manager.h" |
25 #include "content/browser/browser_thread_impl.h" | 25 #include "content/browser/browser_thread_impl.h" |
26 #include "content/browser/compositor/resize_lock.h" | 26 #include "content/browser/compositor/resize_lock.h" |
27 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 27 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
28 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 28 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
29 #include "content/browser/gpu/compositor_util.h" | 29 #include "content/browser/gpu/compositor_util.h" |
30 #include "content/browser/renderer_host/input/input_router.h" | 30 #include "content/browser/renderer_host/input/input_router.h" |
31 #include "content/browser/renderer_host/input/web_input_event_util.h" | 31 #include "content/browser/renderer_host/input/web_input_event_util.h" |
32 #include "content/browser/renderer_host/overscroll_controller.h" | 32 #include "content/browser/renderer_host/overscroll_controller.h" |
33 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 33 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
| 34 #include "content/browser/renderer_host/render_view_host_factory.h" |
34 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 35 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
35 #include "content/browser/renderer_host/render_widget_host_impl.h" | 36 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 37 #include "content/browser/web_contents/web_contents_view_aura.h" |
36 #include "content/common/gpu/client/gl_helper.h" | 38 #include "content/common/gpu/client/gl_helper.h" |
37 #include "content/common/gpu/gpu_messages.h" | 39 #include "content/common/gpu/gpu_messages.h" |
38 #include "content/common/host_shared_bitmap_manager.h" | 40 #include "content/common/host_shared_bitmap_manager.h" |
39 #include "content/common/input/synthetic_web_input_event_builders.h" | 41 #include "content/common/input/synthetic_web_input_event_builders.h" |
40 #include "content/common/input_messages.h" | 42 #include "content/common/input_messages.h" |
41 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
42 #include "content/public/browser/render_widget_host_view.h" | 44 #include "content/public/browser/render_widget_host_view.h" |
43 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 45 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 46 #include "content/public/browser/web_contents_view_delegate.h" |
| 47 #include "content/public/common/context_menu_params.h" |
44 #include "content/public/test/mock_render_process_host.h" | 48 #include "content/public/test/mock_render_process_host.h" |
45 #include "content/public/test/test_browser_context.h" | 49 #include "content/public/test/test_browser_context.h" |
| 50 #include "content/test/test_render_view_host.h" |
| 51 #include "content/test/test_web_contents.h" |
46 #include "ipc/ipc_test_sink.h" | 52 #include "ipc/ipc_test_sink.h" |
47 #include "testing/gmock/include/gmock/gmock.h" | 53 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "ui/aura/client/aura_constants.h" | 55 #include "ui/aura/client/aura_constants.h" |
50 #include "ui/aura/client/screen_position_client.h" | 56 #include "ui/aura/client/screen_position_client.h" |
51 #include "ui/aura/client/window_tree_client.h" | 57 #include "ui/aura/client/window_tree_client.h" |
52 #include "ui/aura/env.h" | 58 #include "ui/aura/env.h" |
53 #include "ui/aura/layout_manager.h" | 59 #include "ui/aura/layout_manager.h" |
54 #include "ui/aura/test/aura_test_helper.h" | 60 #include "ui/aura/test/aura_test_helper.h" |
55 #include "ui/aura/test/aura_test_utils.h" | 61 #include "ui/aura/test/aura_test_utils.h" |
(...skipping 3582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3638 ViewMsg_SetSurfaceIdNamespace::Param params; | 3644 ViewMsg_SetSurfaceIdNamespace::Param params; |
3639 ViewMsg_SetSurfaceIdNamespace::Read(msg, ¶ms); | 3645 ViewMsg_SetSurfaceIdNamespace::Read(msg, ¶ms); |
3640 view_->InitAsChild(NULL); | 3646 view_->InitAsChild(NULL); |
3641 view_->Show(); | 3647 view_->Show(); |
3642 view_->SetSize(size); | 3648 view_->SetSize(size); |
3643 view_->OnSwapCompositorFrame(0, | 3649 view_->OnSwapCompositorFrame(0, |
3644 MakeDelegatedFrame(1.f, size, gfx::Rect(size))); | 3650 MakeDelegatedFrame(1.f, size, gfx::Rect(size))); |
3645 EXPECT_EQ(view_->GetSurfaceIdNamespace(), base::get<0>(params)); | 3651 EXPECT_EQ(view_->GetSurfaceIdNamespace(), base::get<0>(params)); |
3646 } | 3652 } |
3647 | 3653 |
| 3654 // This class provides functionality to test a RenderWidgetHostViewAura |
| 3655 // instance which has been hooked up to a test RenderViewHost instance and |
| 3656 // a WebContents instance. |
| 3657 class RenderWidgetHostViewAuraWithViewHarnessTest |
| 3658 : public RenderViewHostImplTestHarness { |
| 3659 public: |
| 3660 RenderWidgetHostViewAuraWithViewHarnessTest() |
| 3661 : view_(nullptr) {} |
| 3662 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {} |
| 3663 |
| 3664 protected: |
| 3665 void SetUp() override { |
| 3666 ImageTransportFactory::InitializeForUnitTests( |
| 3667 scoped_ptr<ImageTransportFactory>( |
| 3668 new NoTransportImageTransportFactory)); |
| 3669 RenderViewHostImplTestHarness::SetUp(); |
| 3670 // Delete the current RenderWidgetHostView instance before setting |
| 3671 // the RWHVA as the view. |
| 3672 delete contents()->GetRenderViewHost()->GetWidget()->GetView(); |
| 3673 // This instance is destroyed in the TearDown method below. |
| 3674 view_ = new RenderWidgetHostViewAura( |
| 3675 contents()->GetRenderViewHost()->GetWidget(), |
| 3676 false); |
| 3677 } |
| 3678 |
| 3679 void TearDown() override { |
| 3680 view_->Destroy(); |
| 3681 RenderViewHostImplTestHarness::TearDown(); |
| 3682 ImageTransportFactory::Terminate(); |
| 3683 } |
| 3684 |
| 3685 RenderWidgetHostViewAura* view() { |
| 3686 return view_; |
| 3687 } |
| 3688 |
| 3689 private: |
| 3690 RenderWidgetHostViewAura* view_; |
| 3691 |
| 3692 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraWithViewHarnessTest); |
| 3693 }; |
| 3694 |
| 3695 // Provides a mock implementation of the WebContentsViewDelegate class. |
| 3696 // Currently provides functionality to validate the ShowContextMenu |
| 3697 // callback. |
| 3698 class MockWebContentsViewDelegate : public WebContentsViewDelegate { |
| 3699 public: |
| 3700 MockWebContentsViewDelegate() |
| 3701 : context_menu_request_received_(false) {} |
| 3702 |
| 3703 ~MockWebContentsViewDelegate() override {} |
| 3704 |
| 3705 bool context_menu_request_received() const { |
| 3706 return context_menu_request_received_; |
| 3707 } |
| 3708 |
| 3709 ui::MenuSourceType context_menu_source_type() const { |
| 3710 return context_menu_params_.source_type; |
| 3711 } |
| 3712 |
| 3713 // WebContentsViewDelegate overrides. |
| 3714 void ShowContextMenu(RenderFrameHost* render_frame_host, |
| 3715 const ContextMenuParams& params) override { |
| 3716 context_menu_request_received_ = true; |
| 3717 context_menu_params_ = params; |
| 3718 } |
| 3719 |
| 3720 void ClearState() { |
| 3721 context_menu_request_received_ = false; |
| 3722 context_menu_params_.source_type = ui::MENU_SOURCE_NONE; |
| 3723 } |
| 3724 |
| 3725 private: |
| 3726 bool context_menu_request_received_; |
| 3727 ContextMenuParams context_menu_params_; |
| 3728 |
| 3729 DISALLOW_COPY_AND_ASSIGN(MockWebContentsViewDelegate); |
| 3730 }; |
| 3731 |
| 3732 // On Windows we don't want the context menu to be displayed in the context of |
| 3733 // a long press gesture. It should be displayed when the touch is released. |
| 3734 // On other platforms we should display the context menu in the long press |
| 3735 // gesture. |
| 3736 // This test validates this behavior. |
| 3737 TEST_F(RenderWidgetHostViewAuraWithViewHarnessTest, |
| 3738 ContextMenuTest) { |
| 3739 // This instance will be destroyed when the WebContents instance is |
| 3740 // destroyed. |
| 3741 MockWebContentsViewDelegate* delegate = new MockWebContentsViewDelegate; |
| 3742 static_cast<WebContentsViewAura*>( |
| 3743 contents()->GetView())->SetDelegateForTesting(delegate); |
| 3744 |
| 3745 RenderViewHostFactory::set_is_real_render_view_host(true); |
| 3746 |
| 3747 // A context menu request with the MENU_SOURCE_MOUSE source type should |
| 3748 // result in the MockWebContentsViewDelegate::ShowContextMenu method |
| 3749 // getting called. This means that the request worked correctly. |
| 3750 ContextMenuParams context_menu_params; |
| 3751 context_menu_params.source_type = ui::MENU_SOURCE_MOUSE; |
| 3752 contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(), |
| 3753 context_menu_params); |
| 3754 EXPECT_TRUE(delegate->context_menu_request_received()); |
| 3755 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_MOUSE); |
| 3756 |
| 3757 // A context menu request with the MENU_SOURCE_TOUCH source type should |
| 3758 // result in the MockWebContentsViewDelegate::ShowContextMenu method |
| 3759 // getting called on non Windows platforms. This means that the request |
| 3760 // worked correctly. On Windows this should be blocked. |
| 3761 delegate->ClearState(); |
| 3762 context_menu_params.source_type = ui::MENU_SOURCE_TOUCH; |
| 3763 contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(), |
| 3764 context_menu_params); |
| 3765 #if defined(OS_WIN) |
| 3766 EXPECT_FALSE(delegate->context_menu_request_received()); |
| 3767 #else |
| 3768 EXPECT_TRUE(delegate->context_menu_request_received()); |
| 3769 #endif |
| 3770 |
| 3771 #if defined(OS_WIN) |
| 3772 // On Windows the context menu request blocked above should be received when |
| 3773 // the ET_GESTURE_LONG_TAP gesture is sent to the RenderWidgetHostViewAura |
| 3774 // instance. This means that the touch was released. |
| 3775 delegate->ClearState(); |
| 3776 |
| 3777 ui::GestureEventDetails event_details(ui::ET_GESTURE_LONG_TAP); |
| 3778 ui::GestureEvent gesture_event( |
| 3779 100, 100, 0, ui::EventTimeForNow(), event_details); |
| 3780 view()->OnGestureEvent(&gesture_event); |
| 3781 |
| 3782 EXPECT_TRUE(delegate->context_menu_request_received()); |
| 3783 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_MOUSE); |
| 3784 #endif |
| 3785 |
| 3786 RenderViewHostFactory::set_is_real_render_view_host(false); |
| 3787 } |
| 3788 |
3648 } // namespace content | 3789 } // namespace content |
OLD | NEW |