Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm

Issue 2050033002: Revert of Remove enable/disable wheel gestures setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@can_scroll_remove
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
269 void RecycleAndWait() { 282 void RecycleAndWait() {
270 pool_.Recycle(); 283 pool_.Recycle();
271 base::MessageLoop::current()->RunUntilIdle(); 284 base::MessageLoop::current()->RunUntilIdle();
272 pool_.Recycle(); 285 pool_.Recycle();
273 } 286 }
274 287
275 void DestroyHostViewRetainCocoaView() { 288 void DestroyHostViewRetainCocoaView() {
276 test_rvh()->GetWidget()->SetView(nullptr); 289 test_rvh()->GetWidget()->SetView(nullptr);
277 rwhv_mac_->Destroy(); 290 rwhv_mac_->Destroy();
278 } 291 }
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 // render view receives it. 926 // render view receives it.
914 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); 927 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0);
915 [NSApp postEvent:event2 atStart:NO]; 928 [NSApp postEvent:event2 atStart:NO];
916 base::MessageLoop::current()->RunUntilIdle(); 929 base::MessageLoop::current()->RunUntilIdle();
917 ASSERT_EQ(2U, process_host->sink().message_count()); 930 ASSERT_EQ(2U, process_host->sink().message_count());
918 931
919 // Clean up. 932 // Clean up.
920 host->ShutdownAndDestroyWidget(true); 933 host->ShutdownAndDestroyWidget(true);
921 } 934 }
922 935
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
923 TEST_F(RenderWidgetHostViewMacTest, 992 TEST_F(RenderWidgetHostViewMacTest,
924 IgnoreEmptyUnhandledWheelEventWithWheelGestures) { 993 IgnoreEmptyUnhandledWheelEventWithWheelGestures) {
994 SetupForWheelGestures(true);
995
925 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than 996 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than
926 // the MockRenderProcessHost that is set up by the test harness which mocks 997 // the MockRenderProcessHost that is set up by the test harness which mocks
927 // out |OnMessageReceived()|. 998 // out |OnMessageReceived()|.
928 TestBrowserContext browser_context; 999 TestBrowserContext browser_context;
929 MockRenderProcessHost* process_host = 1000 MockRenderProcessHost* process_host =
930 new MockRenderProcessHost(&browser_context); 1001 new MockRenderProcessHost(&browser_context);
931 process_host->Init(); 1002 process_host->Init();
932 MockRenderWidgetHostDelegate delegate; 1003 MockRenderWidgetHostDelegate delegate;
933 int32_t routing_id = process_host->GetNextRoutingID(); 1004 int32_t routing_id = process_host->GetNextRoutingID();
934 MockRenderWidgetHostImpl* host = 1005 MockRenderWidgetHostImpl* host =
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly. 1312 // Verify that Event.Latency.OS.MOUSE_WHEEL histogram is computed properly.
1242 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3); 1313 NSEvent* wheelEvent = MockScrollWheelEventWithPhase(@selector(phaseBegan),3);
1243 [view->cocoa_view() scrollWheel:wheelEvent]; 1314 [view->cocoa_view() scrollWheel:wheelEvent];
1244 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); 1315 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1);
1245 1316
1246 // Clean up. 1317 // Clean up.
1247 host->ShutdownAndDestroyWidget(true); 1318 host->ShutdownAndDestroyWidget(true);
1248 } 1319 }
1249 1320
1250 } // namespace content 1321 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.mm ('k') | content/common/input/input_event_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698