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 blink::WebPointerProperties::PointerType GetInputMessagePointerTypes( | |
128 MockRenderProcessHost* process) { | |
129 blink::WebPointerProperties::PointerType pointer_type; | |
130 DCHECK_LE(process->sink().message_count(), 1U); | |
131 for (size_t i = 0; i < process->sink().message_count(); ++i) { | |
132 const IPC::Message* message = process->sink().GetMessageAt(i); | |
133 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); | |
134 InputMsg_HandleInputEvent::Param params; | |
135 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); | |
136 const blink::WebInputEvent* event = std::get<0>(params); | |
137 if (blink::WebInputEvent::isMouseEventType(event->type())) { | |
138 pointer_type = | |
139 static_cast<const blink::WebMouseEvent*>(event)->pointerType; | |
140 } | |
141 } | |
142 process->sink().ClearMessages(); | |
143 return pointer_type; | |
144 } | |
145 | |
146 NSEvent* MockTabletEventWithParams(CGEventType type, | |
147 bool is_entering_proximity, | |
148 NSPointingDeviceType device_type) { | |
149 CGEventRef cg_event = CGEventCreate(NULL); | |
150 CGEventSetType(cg_event, type); | |
151 CGEventSetIntegerValueField(cg_event, kCGTabletProximityEventEnterProximity, | |
152 is_entering_proximity); | |
153 CGEventSetIntegerValueField(cg_event, kCGTabletProximityEventPointerType, | |
154 device_type); | |
155 NSEvent* event = [NSEvent eventWithCGEvent:cg_event]; | |
tdresser
2017/03/23 12:16:54
Pardon my not knowing much about Mac development.
lanwei
2017/03/23 18:55:16
Actually, I am not sure. I saw other tests all did
| |
156 CFRelease(cg_event); | |
157 return event; | |
158 } | |
159 | |
160 NSEvent* MockMouseEventWithParams(CGEventType mouse_type, | |
161 CGPoint location, | |
162 CGMouseButton button, | |
163 CGEventMouseSubtype subtype) { | |
164 CGEventRef cg_event = | |
165 CGEventCreateMouseEvent(NULL, mouse_type, location, button); | |
166 CGEventSetIntegerValueField(cg_event, kCGMouseEventSubtype, subtype); | |
167 NSEvent* event = [NSEvent eventWithCGEvent:cg_event]; | |
168 CFRelease(cg_event); | |
169 return event; | |
170 } | |
171 | |
127 id MockGestureEvent(NSEventType type, double magnification) { | 172 id MockGestureEvent(NSEventType type, double magnification) { |
128 id event = [OCMockObject mockForClass:[NSEvent class]]; | 173 id event = [OCMockObject mockForClass:[NSEvent class]]; |
129 NSPoint locationInWindow = NSMakePoint(0, 0); | 174 NSPoint locationInWindow = NSMakePoint(0, 0); |
130 CGFloat deltaX = 0; | 175 CGFloat deltaX = 0; |
131 CGFloat deltaY = 0; | 176 CGFloat deltaY = 0; |
132 NSTimeInterval timestamp = 1; | 177 NSTimeInterval timestamp = 1; |
133 NSUInteger modifierFlags = 0; | 178 NSUInteger modifierFlags = 0; |
134 | 179 |
135 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; | 180 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type]; |
136 [(NSEvent*)[[event stub] | 181 [(NSEvent*)[[event stub] |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
998 // render view receives it. | 1043 // render view receives it. |
999 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); | 1044 NSEvent* event2 = MockScrollWheelEventWithPhase(@selector(phaseEnded), 0); |
1000 [NSApp postEvent:event2 atStart:NO]; | 1045 [NSApp postEvent:event2 atStart:NO]; |
1001 base::RunLoop().RunUntilIdle(); | 1046 base::RunLoop().RunUntilIdle(); |
1002 ASSERT_EQ(1U, process_host->sink().message_count()); | 1047 ASSERT_EQ(1U, process_host->sink().message_count()); |
1003 | 1048 |
1004 // Clean up. | 1049 // Clean up. |
1005 host->ShutdownAndDestroyWidget(true); | 1050 host->ShutdownAndDestroyWidget(true); |
1006 } | 1051 } |
1007 | 1052 |
1053 TEST_F(RenderWidgetHostViewMacTest, PointerEventWithEraserType) { | |
1054 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | |
1055 // the MockRenderProcessHost that is set up by the test harness which mocks | |
1056 // out |OnMessageReceived()|. | |
1057 TestBrowserContext browser_context; | |
1058 MockRenderProcessHost* process_host = | |
1059 new MockRenderProcessHost(&browser_context); | |
1060 process_host->Init(); | |
1061 MockRenderWidgetHostDelegate delegate; | |
1062 int32_t routing_id = process_host->GetNextRoutingID(); | |
1063 MockRenderWidgetHostImpl* host = | |
1064 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); | |
1065 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); | |
1066 process_host->sink().ClearMessages(); | |
1067 | |
1068 // Send a NSEvent of NSTabletProximity type which has a device type of eraser. | |
1069 NSEvent* event = MockTabletEventWithParams(kCGEventTabletProximity, true, | |
1070 NSEraserPointingDevice); | |
1071 [view->cocoa_view() tabletEvent:event]; | |
1072 // Flush and clear other messages (e.g. begin frames) the RWHVMac also sends. | |
1073 base::RunLoop().RunUntilIdle(); | |
1074 process_host->sink().ClearMessages(); | |
1075 | |
1076 event = MockMouseEventWithParams(kCGEventMouseMoved, {6, 9}, 0, | |
1077 kCGEventMouseSubtypeTabletPoint); | |
1078 [view->cocoa_view() mouseEvent:event]; | |
1079 ASSERT_EQ(1U, process_host->sink().message_count()); | |
1080 EXPECT_EQ(blink::WebPointerProperties::PointerType::Eraser, | |
1081 GetInputMessagePointerTypes(process_host)); | |
1082 | |
1083 // Clean up. | |
1084 host->ShutdownAndDestroyWidget(true); | |
1085 } | |
1086 | |
1087 TEST_F(RenderWidgetHostViewMacTest, PointerEventWithPenType) { | |
1088 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | |
1089 // the MockRenderProcessHost that is set up by the test harness which mocks | |
1090 // out |OnMessageReceived()|. | |
1091 TestBrowserContext browser_context; | |
1092 MockRenderProcessHost* process_host = | |
1093 new MockRenderProcessHost(&browser_context); | |
1094 process_host->Init(); | |
1095 MockRenderWidgetHostDelegate delegate; | |
1096 int32_t routing_id = process_host->GetNextRoutingID(); | |
1097 MockRenderWidgetHostImpl* host = | |
1098 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); | |
1099 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); | |
1100 process_host->sink().ClearMessages(); | |
1101 | |
1102 // Send a NSEvent of NSTabletProximity type which has a device type of pen. | |
1103 NSEvent* event = MockTabletEventWithParams(kCGEventTabletProximity, true, | |
1104 NSPenPointingDevice); | |
1105 [view->cocoa_view() tabletEvent:event]; | |
1106 // Flush and clear other messages (e.g. begin frames) the RWHVMac also sends. | |
1107 base::RunLoop().RunUntilIdle(); | |
1108 process_host->sink().ClearMessages(); | |
1109 | |
1110 event = MockMouseEventWithParams(kCGEventMouseMoved, {6, 9}, 0, | |
1111 kCGEventMouseSubtypeTabletPoint); | |
1112 [view->cocoa_view() mouseEvent:event]; | |
1113 ASSERT_EQ(1U, process_host->sink().message_count()); | |
1114 EXPECT_EQ(blink::WebPointerProperties::PointerType::Pen, | |
1115 GetInputMessagePointerTypes(process_host)); | |
1116 | |
1117 // Clean up. | |
1118 host->ShutdownAndDestroyWidget(true); | |
1119 } | |
1120 | |
1121 TEST_F(RenderWidgetHostViewMacTest, PointerEventWithMouseType) { | |
1122 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | |
1123 // the MockRenderProcessHost that is set up by the test harness which mocks | |
1124 // out |OnMessageReceived()|. | |
1125 TestBrowserContext browser_context; | |
1126 MockRenderProcessHost* process_host = | |
1127 new MockRenderProcessHost(&browser_context); | |
1128 process_host->Init(); | |
1129 MockRenderWidgetHostDelegate delegate; | |
1130 int32_t routing_id = process_host->GetNextRoutingID(); | |
1131 MockRenderWidgetHostImpl* host = | |
1132 new MockRenderWidgetHostImpl(&delegate, process_host, routing_id); | |
1133 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false); | |
1134 process_host->sink().ClearMessages(); | |
1135 | |
1136 // Send a NSEvent of a mouse type. | |
1137 NSEvent* event = MockMouseEventWithParams(kCGEventMouseMoved, {6, 9}, 0, | |
1138 kCGEventMouseSubtypeDefault); | |
1139 [view->cocoa_view() mouseEvent:event]; | |
1140 ASSERT_EQ(1U, process_host->sink().message_count()); | |
1141 EXPECT_EQ(blink::WebPointerProperties::PointerType::Mouse, | |
1142 GetInputMessagePointerTypes(process_host)); | |
1143 | |
1144 // Clean up. | |
1145 host->ShutdownAndDestroyWidget(true); | |
1146 } | |
1147 | |
1008 TEST_F(RenderWidgetHostViewMacTest, | 1148 TEST_F(RenderWidgetHostViewMacTest, |
1009 IgnoreEmptyUnhandledWheelEventWithWheelGestures) { | 1149 IgnoreEmptyUnhandledWheelEventWithWheelGestures) { |
1010 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than | 1150 // Initialize the view associated with a MockRenderWidgetHostImpl, rather than |
1011 // the MockRenderProcessHost that is set up by the test harness which mocks | 1151 // the MockRenderProcessHost that is set up by the test harness which mocks |
1012 // out |OnMessageReceived()|. | 1152 // out |OnMessageReceived()|. |
1013 TestBrowserContext browser_context; | 1153 TestBrowserContext browser_context; |
1014 MockRenderProcessHost* process_host = | 1154 MockRenderProcessHost* process_host = |
1015 new MockRenderProcessHost(&browser_context); | 1155 new MockRenderProcessHost(&browser_context); |
1016 process_host->Init(); | 1156 process_host->Init(); |
1017 MockRenderWidgetHostDelegate delegate; | 1157 MockRenderWidgetHostDelegate delegate; |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1642 // Verify that this IPC is asking for no monitoring or immediate updates. | 1782 // Verify that this IPC is asking for no monitoring or immediate updates. |
1643 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_child, | 1783 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_child, |
1644 &child_msg_params); | 1784 &child_msg_params); |
1645 is_child_msg_for_immediate_request = std::get<0>(child_msg_params); | 1785 is_child_msg_for_immediate_request = std::get<0>(child_msg_params); |
1646 is_child_msg_for_monitor_request = std::get<1>(child_msg_params); | 1786 is_child_msg_for_monitor_request = std::get<1>(child_msg_params); |
1647 EXPECT_FALSE(is_child_msg_for_immediate_request); | 1787 EXPECT_FALSE(is_child_msg_for_immediate_request); |
1648 EXPECT_FALSE(is_child_msg_for_monitor_request); | 1788 EXPECT_FALSE(is_child_msg_for_monitor_request); |
1649 } | 1789 } |
1650 | 1790 |
1651 } // namespace content | 1791 } // namespace content |
OLD | NEW |