| 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_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 RecycleAndWait(); | 259 RecycleAndWait(); |
| 260 | 260 |
| 261 // See comment in SetUp(). | 261 // See comment in SetUp(). |
| 262 test_rvh()->GetWidget()->SetView( | 262 test_rvh()->GetWidget()->SetView( |
| 263 static_cast<RenderWidgetHostViewBase*>(old_rwhv_)); | 263 static_cast<RenderWidgetHostViewBase*>(old_rwhv_)); |
| 264 | 264 |
| 265 ImageTransportFactory::Terminate(); | 265 ImageTransportFactory::Terminate(); |
| 266 RenderViewHostImplTestHarness::TearDown(); | 266 RenderViewHostImplTestHarness::TearDown(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void SetupForWheelGestures(bool enable_wheel_gestures) { | |
| 270 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 271 switches::kDisableWheelGestures)); | |
| 272 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 273 switches::kEnableWheelGestures)); | |
| 274 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 275 enable_wheel_gestures ? switches::kEnableWheelGestures | |
| 276 : switches::kDisableWheelGestures); | |
| 277 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|. | |
| 278 rwhv_mac_ = new RenderWidgetHostViewMac(rvh()->GetWidget(), false); | |
| 279 rwhv_cocoa_.reset([rwhv_mac_->cocoa_view() retain]); | |
| 280 } | |
| 281 | |
| 282 void RecycleAndWait() { | 269 void RecycleAndWait() { |
| 283 pool_.Recycle(); | 270 pool_.Recycle(); |
| 284 base::MessageLoop::current()->RunUntilIdle(); | 271 base::MessageLoop::current()->RunUntilIdle(); |
| 285 pool_.Recycle(); | 272 pool_.Recycle(); |
| 286 } | 273 } |
| 287 | 274 |
| 288 void DestroyHostViewRetainCocoaView() { | 275 void DestroyHostViewRetainCocoaView() { |
| 289 test_rvh()->GetWidget()->SetView(nullptr); | 276 test_rvh()->GetWidget()->SetView(nullptr); |
| 290 rwhv_mac_->Destroy(); | 277 rwhv_mac_->Destroy(); |
| 291 } | 278 } |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 // render view receives it. | 913 // render view receives it. |
| 927 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); | 914 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); |
| 928 [NSApp postEvent:event2 atStart:NO]; | 915 [NSApp postEvent:event2 atStart:NO]; |
| 929 base::MessageLoop::current()->RunUntilIdle(); | 916 base::MessageLoop::current()->RunUntilIdle(); |
| 930 ASSERT_EQ(2U, process_host->sink().message_count()); | 917 ASSERT_EQ(2U, process_host->sink().message_count()); |
| 931 | 918 |
| 932 // Clean up. | 919 // Clean up. |
| 933 host->ShutdownAndDestroyWidget(true); | 920 host->ShutdownAndDestroyWidget(true); |
| 934 } | 921 } |
| 935 | 922 |
| 936 TEST_F(RenderWidgetHostViewMacTest, IgnoreEmptyUnhandledWheelEvent) { | |
| 937 SetupForWheelGestures(false); | |
| 938 | |
| 939 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | |
| 940 // the MockRenderProcessHost that is set up by the test harness which mocks | |
| 941 // out |OnMessageReceived()|. | |
| 942 TestBrowserContext browser_context; | |
| 943 MockRenderProcessHost* process_host = | |
| 944 new MockRenderProcessHost(&browser_context); | |
| 945 process_host->Init(); | |
| 946 MockRenderWidgetHostDelegate delegate; | |
| 947 int32_t routing_id = process_host->GetNextRoutingID(); | |
| 948 MockRenderWidgetHostImpl* host = | |
| 949 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); | |
| 950 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); | |
| 951 process_host->sink().ClearMessages(); | |
| 952 | |
| 953 // Add a delegate to the view. | |
| 954 base::scoped_nsobject<MockRenderWidgetHostViewMacDelegate> view_delegate( | |
| 955 [[MockRenderWidgetHostViewMacDelegate alloc] init]); | |
| 956 view->SetDelegate(view_delegate.get()); | |
| 957 | |
| 958 // Send an initial wheel event for scrolling by 3 lines. | |
| 959 NSEvent* event1 = MockScrollWheelEventWithPhase(@selector(phaseBegan), 3); | |
| 960 [view->cocoa_view() scrollWheel:event1]; | |
| 961 ASSERT_EQ(1U, process_host->sink().message_count()); | |
| 962 process_host->sink().ClearMessages(); | |
| 963 | |
| 964 // Indicate that the wheel event was unhandled. | |
| 965 InputEventAck unhandled_ack(blink::WebInputEvent::MouseWheel, | |
| 966 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 967 std::unique_ptr<IPC::Message> response1( | |
| 968 new InputHostMsg_HandleInputEvent_ACK(0, unhandled_ack)); | |
| 969 host->OnMessageReceived(*response1); | |
| 970 | |
| 971 // Check that the view delegate got an unhandled wheel event. | |
| 972 ASSERT_EQ(YES, view_delegate.get().unhandledWheelEventReceived); | |
| 973 view_delegate.get().unhandledWheelEventReceived = NO; | |
| 974 | |
| 975 // Send another wheel event, this time for scrolling by 0 lines (empty event). | |
| 976 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseChanged), 0); | |
| 977 [view->cocoa_view() scrollWheel:event2]; | |
| 978 ASSERT_EQ(1U, process_host->sink().message_count()); | |
| 979 | |
| 980 // Indicate that the wheel event was also unhandled. | |
| 981 std::unique_ptr<IPC::Message> response2( | |
| 982 new InputHostMsg_HandleInputEvent_ACK(0, unhandled_ack)); | |
| 983 host->OnMessageReceived(*response2); | |
| 984 | |
| 985 // Check that the view delegate ignored the empty unhandled wheel event. | |
| 986 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); | |
| 987 | |
| 988 // Clean up. | |
| 989 host->ShutdownAndDestroyWidget(true); | |
| 990 } | |
| 991 | |
| 992 TEST_F(RenderWidgetHostViewMacTest, | 923 TEST_F(RenderWidgetHostViewMacTest, |
| 993 IgnoreEmptyUnhandledWheelEventWithWheelGestures) { | 924 IgnoreEmptyUnhandledWheelEventWithWheelGestures) { |
| 994 SetupForWheelGestures(true); | |
| 995 | |
| 996 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | 925 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than |
| 997 // the MockRenderProcessHost that is set up by the test harness which mocks | 926 // the MockRenderProcessHost that is set up by the test harness which mocks |
| 998 // out |OnMessageReceived()|. | 927 // out |OnMessageReceived()|. |
| 999 TestBrowserContext browser_context; | 928 TestBrowserContext browser_context; |
| 1000 MockRenderProcessHost* process_host = | 929 MockRenderProcessHost* process_host = |
| 1001 new MockRenderProcessHost(&browser_context); | 930 new MockRenderProcessHost(&browser_context); |
| 1002 process_host->Init(); | 931 process_host->Init(); |
| 1003 MockRenderWidgetHostDelegate delegate; | 932 MockRenderWidgetHostDelegate delegate; |
| 1004 int32_t routing_id = process_host->GetNextRoutingID(); | 933 int32_t routing_id = process_host->GetNextRoutingID(); |
| 1005 MockRenderWidgetHostImpl* host = | 934 MockRenderWidgetHostImpl* host = |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. | 1241 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. |
| 1313 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); | 1242 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); |
| 1314 [view->cocoa_view() scrollWheel:wheelEvent]; | 1243 [view->cocoa_view() scrollWheel:wheelEvent]; |
| 1315 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1244 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
| 1316 | 1245 |
| 1317 // Clean up. | 1246 // Clean up. |
| 1318 host->ShutdownAndDestroyWidget(true); | 1247 host->ShutdownAndDestroyWidget(true); |
| 1319 } | 1248 } |
| 1320 | 1249 |
| 1321 } // namespace content | 1250 } // namespace content |
| OLD | NEW |