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 #if !defined(OS_ANDROID) | |
tdresser
2016/01/21 15:40:28
Is this define necessary?
ananta
2016/01/21 21:11:18
Yeah. Removed. Android does not have Aura.
| |
3655 // This class provides functionality to test a RenderWidgetHostViewAura | |
3656 // instance which has been hooked up to a test RenderViewHost instance and | |
3657 // a WebContents instance. | |
3658 class RenderWidgetHostViewAuraWithViewHarnessTest | |
3659 : public RenderViewHostImplTestHarness { | |
3660 public: | |
3661 RenderWidgetHostViewAuraWithViewHarnessTest() | |
3662 : view_(nullptr) {} | |
3663 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {} | |
3664 | |
3665 protected: | |
3666 void SetUp() override { | |
3667 ImageTransportFactory::InitializeForUnitTests( | |
3668 scoped_ptr<ImageTransportFactory>( | |
3669 new NoTransportImageTransportFactory)); | |
3670 RenderViewHostImplTestHarness::SetUp(); | |
3671 // This instance is destroyed in the TearDown method below. | |
3672 view_ = new RenderWidgetHostViewAura( | |
3673 contents()->GetRenderViewHost()->GetWidget(), | |
3674 false); | |
3675 } | |
3676 | |
3677 void TearDown() override { | |
3678 view_->Destroy(); | |
3679 RenderViewHostImplTestHarness::TearDown(); | |
3680 ImageTransportFactory::Terminate(); | |
3681 } | |
3682 | |
3683 RenderWidgetHostViewAura* view() { | |
3684 return view_; | |
3685 } | |
3686 | |
3687 private: | |
3688 RenderWidgetHostViewAura* view_; | |
3689 | |
3690 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraWithViewHarnessTest); | |
3691 }; | |
3692 | |
3693 // Provides a mock implementation of the WebContentsViewDelegate class. | |
3694 // Currently provides functionality to validate the ShowContextMenu | |
3695 // callback. | |
3696 class MockWebContentsViewDelegate : public WebContentsViewDelegate { | |
3697 public: | |
3698 MockWebContentsViewDelegate() | |
3699 : context_menu_request_received_(false) {} | |
3700 | |
3701 ~MockWebContentsViewDelegate() override {} | |
3702 | |
3703 bool context_menu_request_received() const { | |
3704 return context_menu_request_received_; | |
3705 } | |
3706 | |
3707 ui::MenuSourceType context_menu_source_type() const { | |
3708 return context_menu_params_.source_type; | |
3709 } | |
3710 | |
3711 // WebContentsViewDelegate overrides. | |
3712 void ShowContextMenu(RenderFrameHost* render_frame_host, | |
3713 const ContextMenuParams& params) override { | |
3714 context_menu_request_received_ = true; | |
3715 context_menu_params_ = params; | |
3716 } | |
3717 | |
3718 void ClearState() { | |
3719 context_menu_request_received_ = false; | |
3720 context_menu_params_.source_type = ui::MENU_SOURCE_NONE; | |
3721 } | |
3722 | |
3723 private: | |
3724 bool context_menu_request_received_; | |
3725 ContextMenuParams context_menu_params_; | |
3726 | |
3727 DISALLOW_COPY_AND_ASSIGN(MockWebContentsViewDelegate); | |
3728 }; | |
3729 | |
3730 // On Windows we don't want the context menu to be displayed in the context of | |
3731 // a long press gesture. It should be displayed when the touch is released. | |
3732 // On other platforms we should display the context menu in the long press | |
3733 // gesture. | |
3734 // This test validates this behavior. | |
3735 TEST_F(RenderWidgetHostViewAuraWithViewHarnessTest, | |
3736 ContextMenuTest) { | |
3737 // This instance will be destroyed when the WebContents instance is | |
3738 // destroyed. | |
3739 MockWebContentsViewDelegate* delegate = new MockWebContentsViewDelegate; | |
3740 static_cast<WebContentsViewAura*>(contents()->GetView())->SetDelegate( | |
3741 delegate); | |
3742 | |
3743 RenderViewHostFactory::set_allow_host_view_cast_in_test(true); | |
3744 | |
3745 // A context menu request with the MENU_SOURCE_MOUSE source type should | |
3746 // result in the MockWebContentsViewDelegate::ShowContextMenu method | |
3747 // getting called. This means that the request worked correctly. | |
3748 ContextMenuParams context_menu_params; | |
3749 context_menu_params.source_type = ui::MENU_SOURCE_MOUSE; | |
3750 contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(), | |
3751 context_menu_params); | |
3752 EXPECT_TRUE(delegate->context_menu_request_received()); | |
3753 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_MOUSE); | |
3754 | |
3755 // A context menu request with the MENU_SOURCE_TOUCH source type should | |
3756 // result in the MockWebContentsViewDelegate::ShowContextMenu method | |
3757 // getting called on non Windows platforms. This means that the request | |
3758 // worked correctly. On Windows this should be blocked. | |
3759 delegate->ClearState(); | |
3760 context_menu_params.source_type = ui::MENU_SOURCE_TOUCH; | |
3761 contents()->ShowContextMenu(contents()->GetRenderViewHost()->GetMainFrame(), | |
3762 context_menu_params); | |
3763 #if defined(OS_WIN) | |
3764 EXPECT_FALSE(delegate->context_menu_request_received()); | |
3765 #else | |
3766 EXPECT_TRUE(delegate->context_menu_request_received()); | |
3767 #endif | |
3768 | |
3769 #if defined(OS_WIN) | |
3770 // On Windows the context menu request blocked above should be received when | |
3771 // the ET_GESTURE_LONG_TAP gesture is sent to the RenderWidgetHostViewAura | |
3772 // instance. This means that the touch was released. | |
3773 delegate->ClearState(); | |
3774 | |
3775 ui::GestureEventDetails event_details(ui::ET_GESTURE_LONG_TAP); | |
3776 ui::GestureEvent gesture_event( | |
3777 100, 100, 0, ui::EventTimeForNow(), event_details); | |
3778 view()->OnGestureEvent(&gesture_event); | |
3779 | |
3780 EXPECT_TRUE(delegate->context_menu_request_received()); | |
3781 EXPECT_EQ(delegate->context_menu_source_type(), ui::MENU_SOURCE_MOUSE); | |
3782 #endif | |
3783 | |
3784 RenderViewHostFactory::set_allow_host_view_cast_in_test(false); | |
3785 } | |
3786 #endif | |
3787 | |
3648 } // namespace content | 3788 } // namespace content |
OLD | NEW |