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

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

Issue 2273703002: Force events to be non blocking if main thread is unresponsive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests, fix bugs. Created 4 years, 1 month 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 <tuple>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 14 matching lines...) Expand all
25 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
26 26
27 using testing::_; 27 using testing::_;
28 28
29 namespace content { 29 namespace content {
30 30
31 namespace { 31 namespace {
32 32
33 const char* EVENT_LISTENER_RESULT_HISTOGRAM = "Event.PassiveListeners"; 33 const char* EVENT_LISTENER_RESULT_HISTOGRAM = "Event.PassiveListeners";
34 34
35 // Keep in sync with enum defined in
36 // RenderWidgetInputHandler::LogPassiveEventListenersUma.
35 enum { 37 enum {
36 PASSIVE_LISTENER_UMA_ENUM_PASSIVE, 38 PASSIVE_LISTENER_UMA_ENUM_PASSIVE,
37 PASSIVE_LISTENER_UMA_ENUM_UNCANCELABLE, 39 PASSIVE_LISTENER_UMA_ENUM_UNCANCELABLE,
38 PASSIVE_LISTENER_UMA_ENUM_SUPPRESSED, 40 PASSIVE_LISTENER_UMA_ENUM_SUPPRESSED,
39 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE, 41 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE,
40 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE_AND_CANCELED, 42 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE_AND_CANCELED,
41 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_FLING, 43 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_FLING,
44 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_MAIN_THREAD_RESPONSIVENES S,
42 PASSIVE_LISTENER_UMA_ENUM_COUNT 45 PASSIVE_LISTENER_UMA_ENUM_COUNT
43 }; 46 };
44 47
45 class MockWebWidget : public blink::WebWidget { 48 class MockWebWidget : public blink::WebWidget {
46 public: 49 public:
47 MOCK_METHOD1(handleInputEvent, 50 MOCK_METHOD1(handleInputEvent,
48 blink::WebInputEventResult(const blink::WebInputEvent&)); 51 blink::WebInputEventResult(const blink::WebInputEvent&));
49 }; 52 };
50 53
51 } // namespace 54 } // namespace
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.current_fling_velocity); 282 EXPECT_EQ(gfx::Vector2dF(10, 5), overscroll.current_fling_velocity);
280 widget()->sink()->ClearMessages(); 283 widget()->sink()->ClearMessages();
281 } 284 }
282 285
283 TEST_F(RenderWidgetUnittest, RenderWidgetInputEventUmaMetrics) { 286 TEST_F(RenderWidgetUnittest, RenderWidgetInputEventUmaMetrics) {
284 SyntheticWebTouchEvent touch; 287 SyntheticWebTouchEvent touch;
285 touch.PressPoint(10, 10); 288 touch.PressPoint(10, 10);
286 touch.touchStartOrFirstTouchMove = true; 289 touch.touchStartOrFirstTouchMove = true;
287 290
288 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_)) 291 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_))
289 .Times(5) 292 .Times(7)
290 .WillRepeatedly( 293 .WillRepeatedly(
291 ::testing::Return(blink::WebInputEventResult::NotHandled)); 294 ::testing::Return(blink::WebInputEventResult::NotHandled));
292 295
293 widget()->SendInputEvent(touch); 296 widget()->SendInputEvent(touch);
294 histogram_tester().ExpectBucketCount(EVENT_LISTENER_RESULT_HISTOGRAM, 297 histogram_tester().ExpectBucketCount(EVENT_LISTENER_RESULT_HISTOGRAM,
295 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE, 1); 298 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE, 1);
296 299
297 touch.dispatchType = blink::WebInputEvent::DispatchType::EventNonBlocking; 300 touch.dispatchType = blink::WebInputEvent::DispatchType::EventNonBlocking;
298 widget()->SendInputEvent(touch); 301 widget()->SendInputEvent(touch);
299 histogram_tester().ExpectBucketCount(EVENT_LISTENER_RESULT_HISTOGRAM, 302 histogram_tester().ExpectBucketCount(EVENT_LISTENER_RESULT_HISTOGRAM,
(...skipping 15 matching lines...) Expand all
315 318
316 touch.MovePoint(0, 10, 10); 319 touch.MovePoint(0, 10, 10);
317 touch.touchStartOrFirstTouchMove = true; 320 touch.touchStartOrFirstTouchMove = true;
318 touch.dispatchType = 321 touch.dispatchType =
319 blink::WebInputEvent::DispatchType::ListenersForcedNonBlockingDueToFling; 322 blink::WebInputEvent::DispatchType::ListenersForcedNonBlockingDueToFling;
320 widget()->SendInputEvent(touch); 323 widget()->SendInputEvent(touch);
321 histogram_tester().ExpectBucketCount( 324 histogram_tester().ExpectBucketCount(
322 EVENT_LISTENER_RESULT_HISTOGRAM, 325 EVENT_LISTENER_RESULT_HISTOGRAM,
323 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_FLING, 2); 326 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_FLING, 2);
324 327
328 touch.dispatchType = blink::WebInputEvent::DispatchType::
329 ListenersForcedNonBlockingDueToMainThreadResponsiveness;
330 widget()->SendInputEvent(touch);
331 histogram_tester().ExpectBucketCount(
332 EVENT_LISTENER_RESULT_HISTOGRAM,
333 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_MAIN_THREAD_RESPONSIV ENESS,
334 1);
335
336 touch.MovePoint(0, 10, 10);
337 touch.touchStartOrFirstTouchMove = true;
338 touch.dispatchType = blink::WebInputEvent::DispatchType::
339 ListenersForcedNonBlockingDueToMainThreadResponsiveness;
340 widget()->SendInputEvent(touch);
341 histogram_tester().ExpectBucketCount(
342 EVENT_LISTENER_RESULT_HISTOGRAM,
343 PASSIVE_LISTENER_UMA_ENUM_FORCED_NON_BLOCKING_DUE_TO_MAIN_THREAD_RESPONSIV ENESS,
344 2);
345
325 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_)) 346 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_))
326 .WillOnce( 347 .WillOnce(
327 ::testing::Return(blink::WebInputEventResult::HandledSuppressed)); 348 ::testing::Return(blink::WebInputEventResult::HandledSuppressed));
328 touch.dispatchType = blink::WebInputEvent::DispatchType::Blocking; 349 touch.dispatchType = blink::WebInputEvent::DispatchType::Blocking;
329 widget()->SendInputEvent(touch); 350 widget()->SendInputEvent(touch);
330 histogram_tester().ExpectBucketCount(EVENT_LISTENER_RESULT_HISTOGRAM, 351 histogram_tester().ExpectBucketCount(EVENT_LISTENER_RESULT_HISTOGRAM,
331 PASSIVE_LISTENER_UMA_ENUM_SUPPRESSED, 1); 352 PASSIVE_LISTENER_UMA_ENUM_SUPPRESSED, 1);
332 353
333 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_)) 354 EXPECT_CALL(*widget()->mock_webwidget(), handleInputEvent(_))
334 .WillOnce( 355 .WillOnce(
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 blink::WebRect popup_emulated_rect(130, 170, 100, 400); 506 blink::WebRect popup_emulated_rect(130, 170, 100, 400);
486 widget()->setWindowRect(popup_emulated_rect); 507 widget()->setWindowRect(popup_emulated_rect);
487 508
488 EXPECT_EQ(popup_emulated_rect.x, widget()->windowRect().x); 509 EXPECT_EQ(popup_emulated_rect.x, widget()->windowRect().x);
489 EXPECT_EQ(popup_emulated_rect.y, widget()->windowRect().y); 510 EXPECT_EQ(popup_emulated_rect.y, widget()->windowRect().y);
490 EXPECT_EQ(popup_emulated_rect.x, widget()->viewRect().x); 511 EXPECT_EQ(popup_emulated_rect.x, widget()->viewRect().x);
491 EXPECT_EQ(popup_emulated_rect.y, widget()->viewRect().y); 512 EXPECT_EQ(popup_emulated_rect.y, widget()->viewRect().y);
492 } 513 }
493 514
494 } // namespace content 515 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698