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

Side by Side Diff: content/renderer/render_widget_unittest.cc

Issue 2023243002: Remove base::Tuple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lint fix 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/render_widget.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include <tuple>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
11 #include "content/common/input/synthetic_web_input_event_builders.h" 12 #include "content/common/input/synthetic_web_input_event_builders.h"
12 #include "content/common/input/web_input_event_traits.h" 13 #include "content/common/input/web_input_event_traits.h"
13 #include "content/common/input_messages.h" 14 #include "content/common/input_messages.h"
14 #include "content/public/test/mock_render_thread.h" 15 #include "content/public/test/mock_render_thread.h"
15 #include "content/test/fake_compositor_dependencies.h" 16 #include "content/test/fake_compositor_dependencies.h"
16 #include "content/test/mock_render_process.h" 17 #include "content/test/mock_render_process.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 161
161 widget()->SendInputEvent(touch); 162 widget()->SendInputEvent(touch);
162 ASSERT_EQ(1u, widget()->sink()->message_count()); 163 ASSERT_EQ(1u, widget()->sink()->message_count());
163 164
164 // Since there's currently no touch-event handling region, the response should 165 // Since there's currently no touch-event handling region, the response should
165 // be 'no consumer exists'. 166 // be 'no consumer exists'.
166 const IPC::Message* message = widget()->sink()->GetMessageAt(0); 167 const IPC::Message* message = widget()->sink()->GetMessageAt(0);
167 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); 168 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type());
168 InputHostMsg_HandleInputEvent_ACK::Param params; 169 InputHostMsg_HandleInputEvent_ACK::Param params;
169 InputHostMsg_HandleInputEvent_ACK::Read(message, &params); 170 InputHostMsg_HandleInputEvent_ACK::Read(message, &params);
170 InputEventAckState ack_state = base::get<0>(params).state; 171 InputEventAckState ack_state = std::get<0>(params).state;
171 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); 172 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state);
172 widget()->sink()->ClearMessages(); 173 widget()->sink()->ClearMessages();
173 174
174 std::vector<gfx::Rect> rects; 175 std::vector<gfx::Rect> rects;
175 rects.push_back(gfx::Rect(0, 0, 20, 20)); 176 rects.push_back(gfx::Rect(0, 0, 20, 20));
176 rects.push_back(gfx::Rect(25, 0, 10, 10)); 177 rects.push_back(gfx::Rect(25, 0, 10, 10));
177 widget()->SetTouchRegion(rects); 178 widget()->SetTouchRegion(rects);
178 179
179 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_)) 180 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_))
180 .WillRepeatedly( 181 .WillRepeatedly(
181 ::testing::Return(blink::WebInputEventResult::NotHandled)); 182 ::testing::Return(blink::WebInputEventResult::NotHandled));
182 183
183 widget()->SendInputEvent(touch); 184 widget()->SendInputEvent(touch);
184 ASSERT_EQ(1u, widget()->sink()->message_count()); 185 ASSERT_EQ(1u, widget()->sink()->message_count());
185 message = widget()->sink()->GetMessageAt(0); 186 message = widget()->sink()->GetMessageAt(0);
186 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); 187 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type());
187 InputHostMsg_HandleInputEvent_ACK::Read(message, &params); 188 InputHostMsg_HandleInputEvent_ACK::Read(message, &params);
188 ack_state = base::get<0>(params).state; 189 ack_state = std::get<0>(params).state;
189 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); 190 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state);
190 widget()->sink()->ClearMessages(); 191 widget()->sink()->ClearMessages();
191 } 192 }
192 193
193 TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) { 194 TEST_F(RenderWidgetUnittest, TouchHitTestMultiplePoints) {
194 std::vector<gfx::Rect> rects; 195 std::vector<gfx::Rect> rects;
195 rects.push_back(gfx::Rect(0, 0, 20, 20)); 196 rects.push_back(gfx::Rect(0, 0, 20, 20));
196 rects.push_back(gfx::Rect(25, 0, 10, 10)); 197 rects.push_back(gfx::Rect(25, 0, 10, 10));
197 widget()->SetTouchRegion(rects); 198 widget()->SetTouchRegion(rects);
198 199
199 SyntheticWebTouchEvent touch; 200 SyntheticWebTouchEvent touch;
200 touch.PressPoint(25, 25); 201 touch.PressPoint(25, 25);
201 202
202 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_)) 203 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_))
203 .WillRepeatedly( 204 .WillRepeatedly(
204 ::testing::Return(blink::WebInputEventResult::NotHandled)); 205 ::testing::Return(blink::WebInputEventResult::NotHandled));
205 206
206 widget()->SendInputEvent(touch); 207 widget()->SendInputEvent(touch);
207 ASSERT_EQ(1u, widget()->sink()->message_count()); 208 ASSERT_EQ(1u, widget()->sink()->message_count());
208 209
209 // Since there's currently no touch-event handling region, the response should 210 // Since there's currently no touch-event handling region, the response should
210 // be 'no consumer exists'. 211 // be 'no consumer exists'.
211 const IPC::Message* message = widget()->sink()->GetMessageAt(0); 212 const IPC::Message* message = widget()->sink()->GetMessageAt(0);
212 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); 213 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type());
213 InputHostMsg_HandleInputEvent_ACK::Param params; 214 InputHostMsg_HandleInputEvent_ACK::Param params;
214 InputHostMsg_HandleInputEvent_ACK::Read(message, &params); 215 InputHostMsg_HandleInputEvent_ACK::Read(message, &params);
215 InputEventAckState ack_state = base::get<0>(params).state; 216 InputEventAckState ack_state = std::get<0>(params).state;
216 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state); 217 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, ack_state);
217 widget()->sink()->ClearMessages(); 218 widget()->sink()->ClearMessages();
218 219
219 // Press a second touch point. This time, on a touch-handling region. 220 // Press a second touch point. This time, on a touch-handling region.
220 touch.PressPoint(10, 10); 221 touch.PressPoint(10, 10);
221 widget()->SendInputEvent(touch); 222 widget()->SendInputEvent(touch);
222 ASSERT_EQ(1u, widget()->sink()->message_count()); 223 ASSERT_EQ(1u, widget()->sink()->message_count());
223 message = widget()->sink()->GetMessageAt(0); 224 message = widget()->sink()->GetMessageAt(0);
224 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); 225 EXPECT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type());
225 InputHostMsg_HandleInputEvent_ACK::Read(message, &params); 226 InputHostMsg_HandleInputEvent_ACK::Read(message, &params);
226 ack_state = base::get<0>(params).state; 227 ack_state = std::get<0>(params).state;
227 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state); 228 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_state);
228 widget()->sink()->ClearMessages(); 229 widget()->sink()->ClearMessages();
229 } 230 }
230 231
231 TEST_F(RenderWidgetUnittest, EventOverscroll) { 232 TEST_F(RenderWidgetUnittest, EventOverscroll) {
232 widget()->set_always_overscroll(true); 233 widget()->set_always_overscroll(true);
233 234
234 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_)) 235 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_))
235 .WillRepeatedly( 236 .WillRepeatedly(
236 ::testing::Return(blink::WebInputEventResult::NotHandled)); 237 ::testing::Return(blink::WebInputEventResult::NotHandled));
237 238
238 blink::WebGestureEvent scroll; 239 blink::WebGestureEvent scroll;
239 scroll.type = blink::WebInputEvent::GestureScrollUpdate; 240 scroll.type = blink::WebInputEvent::GestureScrollUpdate;
240 scroll.x = -10; 241 scroll.x = -10;
241 scroll.data.scrollUpdate.deltaY = 10; 242 scroll.data.scrollUpdate.deltaY = 10;
242 widget()->SendInputEvent(scroll); 243 widget()->SendInputEvent(scroll);
243 244
244 // Overscroll notifications received while handling an input event should 245 // Overscroll notifications received while handling an input event should
245 // be bundled with the event ack IPC. 246 // be bundled with the event ack IPC.
246 ASSERT_EQ(1u, widget()->sink()->message_count()); 247 ASSERT_EQ(1u, widget()->sink()->message_count());
247 const IPC::Message* message = widget()->sink()->GetMessageAt(0); 248 const IPC::Message* message = widget()->sink()->GetMessageAt(0);
248 ASSERT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type()); 249 ASSERT_EQ(InputHostMsg_HandleInputEvent_ACK::ID, message->type());
249 InputHostMsg_HandleInputEvent_ACK::Param params; 250 InputHostMsg_HandleInputEvent_ACK::Param params;
250 InputHostMsg_HandleInputEvent_ACK::Read(message, &params); 251 InputHostMsg_HandleInputEvent_ACK::Read(message, &params);
251 const InputEventAck& ack = base::get<0>(params); 252 const InputEventAck& ack = std::get<0>(params);
252 ASSERT_EQ(ack.type, scroll.type); 253 ASSERT_EQ(ack.type, scroll.type);
253 ASSERT_TRUE(ack.overscroll); 254 ASSERT_TRUE(ack.overscroll);
254 EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->accumulated_overscroll); 255 EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->accumulated_overscroll);
255 EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->latest_overscroll_delta); 256 EXPECT_EQ(gfx::Vector2dF(0, 10), ack.overscroll->latest_overscroll_delta);
256 EXPECT_EQ(gfx::Vector2dF(), ack.overscroll->current_fling_velocity); 257 EXPECT_EQ(gfx::Vector2dF(), ack.overscroll->current_fling_velocity);
257 EXPECT_EQ(gfx::PointF(-10, 0), ack.overscroll->causal_event_viewport_point); 258 EXPECT_EQ(gfx::PointF(-10, 0), ack.overscroll->causal_event_viewport_point);
258 widget()->sink()->ClearMessages(); 259 widget()->sink()->ClearMessages();
259 } 260 }
260 261
261 TEST_F(RenderWidgetUnittest, FlingOverscroll) { 262 TEST_F(RenderWidgetUnittest, FlingOverscroll) {
262 // Overscroll notifications received outside of handling an input event should 263 // Overscroll notifications received outside of handling an input event should
263 // be sent as a separate IPC. 264 // be sent as a separate IPC.
264 widget()->didOverscroll(blink::WebFloatSize(10, 5), blink::WebFloatSize(5, 5), 265 widget()->didOverscroll(blink::WebFloatSize(10, 5), blink::WebFloatSize(5, 5),
265 blink::WebFloatPoint(1, 1), 266 blink::WebFloatPoint(1, 1),
266 blink::WebFloatSize(10, 5)); 267 blink::WebFloatSize(10, 5));
267 ASSERT_EQ(1u, widget()->sink()->message_count()); 268 ASSERT_EQ(1u, widget()->sink()->message_count());
268 const IPC::Message* message = widget()->sink()->GetMessageAt(0); 269 const IPC::Message* message = widget()->sink()->GetMessageAt(0);
269 ASSERT_EQ(InputHostMsg_DidOverscroll::ID, message->type()); 270 ASSERT_EQ(InputHostMsg_DidOverscroll::ID, message->type());
270 InputHostMsg_DidOverscroll::Param params; 271 InputHostMsg_DidOverscroll::Param params;
271 InputHostMsg_DidOverscroll::Read(message, &params); 272 InputHostMsg_DidOverscroll::Read(message, &params);
272 const DidOverscrollParams& overscroll = base::get<0>(params); 273 const DidOverscrollParams& overscroll = std::get<0>(params);
273 EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.latest_overscroll_delta); 274 EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.latest_overscroll_delta);
274 EXPECT_EQ(gfx::Vector2dF(5, 5), overscroll.accumulated_overscroll); 275 EXPECT_EQ(gfx::Vector2dF(5, 5), overscroll.accumulated_overscroll);
275 EXPECT_EQ(gfx::PointF(1, 1), overscroll.causal_event_viewport_point); 276 EXPECT_EQ(gfx::PointF(1, 1), overscroll.causal_event_viewport_point);
276 EXPECT_EQ(gfx::Vector2dF(-10, -5), overscroll.current_fling_velocity); 277 EXPECT_EQ(gfx::Vector2dF(-10, -5), overscroll.current_fling_velocity);
277 widget()->sink()->ClearMessages(); 278 widget()->sink()->ClearMessages();
278 } 279 }
279 280
280 TEST_F(RenderWidgetUnittest, RenderWidgetInputEventUmaMetrics) { 281 TEST_F(RenderWidgetUnittest, RenderWidgetInputEventUmaMetrics) {
281 SyntheticWebTouchEvent touch; 282 SyntheticWebTouchEvent touch;
282 touch.PressPoint(10, 10); 283 touch.PressPoint(10, 10);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 histogram_tester().ExpectTotalCount( 342 histogram_tester().ExpectTotalCount(
342 "Event.Touch.TouchStartLatencyDuringFling", 1); 343 "Event.Touch.TouchStartLatencyDuringFling", 1);
343 344
344 touch.dispatchedDuringFling = false; 345 touch.dispatchedDuringFling = false;
345 widget()->SendInputEvent(touch); 346 widget()->SendInputEvent(touch);
346 histogram_tester().ExpectTotalCount( 347 histogram_tester().ExpectTotalCount(
347 "Event.Touch.TouchStartLatencyOutsideFling", 1); 348 "Event.Touch.TouchStartLatencyOutsideFling", 1);
348 } 349 }
349 350
350 } // namespace content 351 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698