| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); | 117 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); |
| 118 const blink::WebInputEvent* event = std::get<0>(params); | 118 const blink::WebInputEvent* event = std::get<0>(params); |
| 119 if (i != 0) | 119 if (i != 0) |
| 120 result += " "; | 120 result += " "; |
| 121 result += blink::WebInputEvent::GetName(event->type()); | 121 result += blink::WebInputEvent::GetName(event->type()); |
| 122 } | 122 } |
| 123 process->sink().ClearMessages(); | 123 process->sink().ClearMessages(); |
| 124 return result; | 124 return result; |
| 125 } | 125 } |
| 126 | 126 |
| 127 NSEventPhase PhaseForEventType(NSEventType type) { |
| 128 if (type == NSEventTypeBeginGesture) |
| 129 return NSEventPhaseBegan; |
| 130 if (type == NSEventTypeEndGesture) |
| 131 return NSEventPhaseEnded; |
| 132 return NSEventPhaseChanged; |
| 133 } |
| 134 |
| 127 id MockGestureEvent(NSEventType type, double magnification) { | 135 id MockGestureEvent(NSEventType type, double magnification) { |
| 128 id event = [OCMockObject mockForClass:[NSEvent class]]; | 136 id event = [OCMockObject mockForClass:[NSEvent class]]; |
| 137 NSEventPhase phase = PhaseForEventType(type); |
| 129 NSPoint locationInWindow = NSMakePoint(0, 0); | 138 NSPoint locationInWindow = NSMakePoint(0, 0); |
| 130 CGFloat deltaX = 0; | 139 CGFloat deltaX = 0; |
| 131 CGFloat deltaY = 0; | 140 CGFloat deltaY = 0; |
| 132 NSTimeInterval timestamp = 1; | 141 NSTimeInterval timestamp = 1; |
| 133 NSUInteger modifierFlags = 0; | 142 NSUInteger modifierFlags = 0; |
| 134 | 143 |
| 135 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; | 144 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; |
| 145 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(phase)] phase]; |
| 136 [(NSEvent*)[[event stub] | 146 [(NSEvent*)[[event stub] |
| 137 andReturnValue:OCMOCK_VALUE(locationInWindow)] locationInWindow]; | 147 andReturnValue:OCMOCK_VALUE(locationInWindow)] locationInWindow]; |
| 138 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(deltaX)] deltaX]; | 148 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(deltaX)] deltaX]; |
| 139 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(deltaY)] deltaY]; | 149 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(deltaY)] deltaY]; |
| 140 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(timestamp)] timestamp]; | 150 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(timestamp)] timestamp]; |
| 141 [(NSEvent*)[[event stub] | 151 [(NSEvent*)[[event stub] |
| 142 andReturnValue:OCMOCK_VALUE(modifierFlags)] modifierFlags]; | 152 andReturnValue:OCMOCK_VALUE(modifierFlags)] modifierFlags]; |
| 143 [(NSEvent*)[[event stub] | 153 [(NSEvent*)[[event stub] |
| 144 andReturnValue:OCMOCK_VALUE(magnification)] magnification]; | 154 andReturnValue:OCMOCK_VALUE(magnification)] magnification]; |
| 145 return event; | 155 return event; |
| (...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 MockGestureEvent(NSEventTypeBeginGesture, 0); | 1228 MockGestureEvent(NSEventTypeBeginGesture, 0); |
| 1219 NSEvent* pinchUpdateEvents[3] = { | 1229 NSEvent* pinchUpdateEvents[3] = { |
| 1220 MockGestureEvent(NSEventTypeMagnify, 0.25), | 1230 MockGestureEvent(NSEventTypeMagnify, 0.25), |
| 1221 MockGestureEvent(NSEventTypeMagnify, 0.25), | 1231 MockGestureEvent(NSEventTypeMagnify, 0.25), |
| 1222 MockGestureEvent(NSEventTypeMagnify, 0.25), | 1232 MockGestureEvent(NSEventTypeMagnify, 0.25), |
| 1223 }; | 1233 }; |
| 1224 NSEvent* pinchEndEvent = | 1234 NSEvent* pinchEndEvent = |
| 1225 MockGestureEvent(NSEventTypeEndGesture, 0); | 1235 MockGestureEvent(NSEventTypeEndGesture, 0); |
| 1226 | 1236 |
| 1227 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; | 1237 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; |
| 1238 [view->cocoa_view() magnifyWithEvent:pinchBeginEvent]; |
| 1228 EXPECT_EQ(0U, process_host_->sink().message_count()); | 1239 EXPECT_EQ(0U, process_host_->sink().message_count()); |
| 1229 | 1240 |
| 1230 // No zoom is sent for the first update event. | 1241 // No zoom is sent for the first update event. |
| 1231 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[0]]; | 1242 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[0]]; |
| 1232 host->OnMessageReceived(*response); | 1243 host->OnMessageReceived(*response); |
| 1233 EXPECT_EQ(2U, process_host_->sink().message_count()); | 1244 EXPECT_EQ(2U, process_host_->sink().message_count()); |
| 1234 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); | 1245 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); |
| 1235 process_host_->sink().ClearMessages(); | 1246 process_host_->sink().ClearMessages(); |
| 1236 | 1247 |
| 1237 // The second update event crosses the threshold of 0.4, and so zoom is no | 1248 // The second update event crosses the threshold of 0.4, and so zoom is no |
| 1238 // longer disabled. | 1249 // longer disabled. |
| 1239 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[1]]; | 1250 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[1]]; |
| 1240 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); | 1251 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); |
| 1241 host->OnMessageReceived(*response); | 1252 host->OnMessageReceived(*response); |
| 1242 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1253 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 1243 process_host_->sink().ClearMessages(); | 1254 process_host_->sink().ClearMessages(); |
| 1244 | 1255 |
| 1245 // The third update still has zoom enabled. | 1256 // The third update still has zoom enabled. |
| 1246 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[2]]; | 1257 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvents[2]]; |
| 1247 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); | 1258 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); |
| 1248 host->OnMessageReceived(*response); | 1259 host->OnMessageReceived(*response); |
| 1249 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1260 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 1250 process_host_->sink().ClearMessages(); | 1261 process_host_->sink().ClearMessages(); |
| 1251 | 1262 |
| 1252 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 1263 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
| 1264 [view->cocoa_view() magnifyWithEvent:pinchEndEvent]; |
| 1253 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1265 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 1254 process_host_->sink().ClearMessages(); | 1266 process_host_->sink().ClearMessages(); |
| 1255 } | 1267 } |
| 1256 | 1268 |
| 1257 // Do a gesture that doesn't cross the threshold, but happens when we're not | 1269 // Do a gesture that doesn't cross the threshold, but happens when we're not |
| 1258 // at page scale factor one, so it should be sent to the renderer. | 1270 // at page scale factor one, so it should be sent to the renderer. |
| 1259 { | 1271 { |
| 1260 NSEvent* pinchBeginEvent = MockGestureEvent(NSEventTypeBeginGesture, 0); | 1272 NSEvent* pinchBeginEvent = MockGestureEvent(NSEventTypeBeginGesture, 0); |
| 1261 NSEvent* pinchUpdateEvent = MockGestureEvent(NSEventTypeMagnify, 0.25); | 1273 NSEvent* pinchUpdateEvent = MockGestureEvent(NSEventTypeMagnify, 0.25); |
| 1262 NSEvent* pinchEndEvent = MockGestureEvent(NSEventTypeEndGesture, 0); | 1274 NSEvent* pinchEndEvent = MockGestureEvent(NSEventTypeEndGesture, 0); |
| 1263 | 1275 |
| 1264 view->page_at_minimum_scale_ = false; | 1276 view->page_at_minimum_scale_ = false; |
| 1265 | 1277 |
| 1266 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; | 1278 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; |
| 1279 [view->cocoa_view() magnifyWithEvent:pinchBeginEvent]; |
| 1267 EXPECT_EQ(0U, process_host_->sink().message_count()); | 1280 EXPECT_EQ(0U, process_host_->sink().message_count()); |
| 1268 | 1281 |
| 1269 // Expect that a zoom happen because the time threshold has not passed. | 1282 // Expect that a zoom happen because the time threshold has not passed. |
| 1270 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; | 1283 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; |
| 1271 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); | 1284 EXPECT_FALSE(ZoomDisabledForPinchUpdateMessage()); |
| 1272 host->OnMessageReceived(*response); | 1285 host->OnMessageReceived(*response); |
| 1273 EXPECT_EQ(2U, process_host_->sink().message_count()); | 1286 EXPECT_EQ(2U, process_host_->sink().message_count()); |
| 1274 process_host_->sink().ClearMessages(); | 1287 process_host_->sink().ClearMessages(); |
| 1275 | 1288 |
| 1276 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 1289 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
| 1290 [view->cocoa_view() magnifyWithEvent:pinchEndEvent]; |
| 1277 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1291 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 1278 process_host_->sink().ClearMessages(); | 1292 process_host_->sink().ClearMessages(); |
| 1279 } | 1293 } |
| 1280 | 1294 |
| 1281 // Do a gesture again, after the page scale is no longer at one, and ensure | 1295 // Do a gesture again, after the page scale is no longer at one, and ensure |
| 1282 // that it is thresholded again. | 1296 // that it is thresholded again. |
| 1283 { | 1297 { |
| 1284 NSEvent* pinchBeginEvent = MockGestureEvent(NSEventTypeBeginGesture, 0); | 1298 NSEvent* pinchBeginEvent = MockGestureEvent(NSEventTypeBeginGesture, 0); |
| 1285 NSEvent* pinchUpdateEvent = MockGestureEvent(NSEventTypeMagnify, 0.25); | 1299 NSEvent* pinchUpdateEvent = MockGestureEvent(NSEventTypeMagnify, 0.25); |
| 1286 NSEvent* pinchEndEvent = MockGestureEvent(NSEventTypeEndGesture, 0); | 1300 NSEvent* pinchEndEvent = MockGestureEvent(NSEventTypeEndGesture, 0); |
| 1287 | 1301 |
| 1288 view->page_at_minimum_scale_ = true; | 1302 view->page_at_minimum_scale_ = true; |
| 1289 | 1303 |
| 1290 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; | 1304 [view->cocoa_view() beginGestureWithEvent:pinchBeginEvent]; |
| 1305 [view->cocoa_view() magnifyWithEvent:pinchBeginEvent]; |
| 1291 EXPECT_EQ(0U, process_host_->sink().message_count()); | 1306 EXPECT_EQ(0U, process_host_->sink().message_count()); |
| 1292 | 1307 |
| 1293 // Get back to zoom one right after the begin event. This should still keep | 1308 // Get back to zoom one right after the begin event. This should still keep |
| 1294 // the thresholding in place (it is latched at the begin event). | 1309 // the thresholding in place (it is latched at the begin event). |
| 1295 view->page_at_minimum_scale_ = false; | 1310 view->page_at_minimum_scale_ = false; |
| 1296 | 1311 |
| 1297 // Expect that zoom be disabled because the time threshold has passed. | 1312 // Expect that zoom be disabled because the time threshold has passed. |
| 1298 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; | 1313 [view->cocoa_view() magnifyWithEvent:pinchUpdateEvent]; |
| 1299 EXPECT_EQ(2U, process_host_->sink().message_count()); | 1314 EXPECT_EQ(2U, process_host_->sink().message_count()); |
| 1300 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); | 1315 EXPECT_TRUE(ZoomDisabledForPinchUpdateMessage()); |
| 1301 host->OnMessageReceived(*response); | 1316 host->OnMessageReceived(*response); |
| 1302 process_host_->sink().ClearMessages(); | 1317 process_host_->sink().ClearMessages(); |
| 1303 | 1318 |
| 1304 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; | 1319 [view->cocoa_view() endGestureWithEvent:pinchEndEvent]; |
| 1320 [view->cocoa_view() magnifyWithEvent:pinchEndEvent]; |
| 1305 EXPECT_EQ(1U, process_host_->sink().message_count()); | 1321 EXPECT_EQ(1U, process_host_->sink().message_count()); |
| 1306 process_host_->sink().ClearMessages(); | 1322 process_host_->sink().ClearMessages(); |
| 1307 } | 1323 } |
| 1308 | 1324 |
| 1309 // Clean up. | 1325 // Clean up. |
| 1310 host->ShutdownAndDestroyWidget(true); | 1326 host->ShutdownAndDestroyWidget(true); |
| 1311 } | 1327 } |
| 1312 | 1328 |
| 1313 TEST_F(RenderWidgetHostViewMacTest, EventLatencyOSMouseWheelHistogram) { | 1329 TEST_F(RenderWidgetHostViewMacTest, EventLatencyOSMouseWheelHistogram) { |
| 1314 base::HistogramTester histogram_tester; | 1330 base::HistogramTester histogram_tester; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 // Verify that this IPC is asking for no monitoring or immediate updates. | 1655 // Verify that this IPC is asking for no monitoring or immediate updates. |
| 1640 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_child, | 1656 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_child, |
| 1641 &child_msg_params); | 1657 &child_msg_params); |
| 1642 is_child_msg_for_immediate_request = std::get<0>(child_msg_params); | 1658 is_child_msg_for_immediate_request = std::get<0>(child_msg_params); |
| 1643 is_child_msg_for_monitor_request = std::get<1>(child_msg_params); | 1659 is_child_msg_for_monitor_request = std::get<1>(child_msg_params); |
| 1644 EXPECT_FALSE(is_child_msg_for_immediate_request); | 1660 EXPECT_FALSE(is_child_msg_for_immediate_request); |
| 1645 EXPECT_FALSE(is_child_msg_for_monitor_request); | 1661 EXPECT_FALSE(is_child_msg_for_monitor_request); |
| 1646 } | 1662 } |
| 1647 | 1663 |
| 1648 } // namespace content | 1664 } // namespace content |
| OLD | NEW |