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

Unified Diff: content/renderer/input/main_thread_event_queue_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: Fix build. 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/input/main_thread_event_queue_unittest.cc
diff --git a/content/renderer/input/main_thread_event_queue_unittest.cc b/content/renderer/input/main_thread_event_queue_unittest.cc
index 1f8c2a833b04d13910c33d3ec05ad675dc747aba..5e517443a9703eeb9e5e151c143b7b47ae7c8732 100644
--- a/content/renderer/input/main_thread_event_queue_unittest.cc
+++ b/content/renderer/input/main_thread_event_queue_unittest.cc
@@ -26,13 +26,31 @@ using blink::WebMouseWheelEvent;
using blink::WebTouchEvent;
namespace blink {
-bool operator==(const WebMouseWheelEvent& lhs, const WebMouseWheelEvent& rhs) {
- return memcmp(&lhs, &rhs, lhs.size) == 0;
+
+::testing::AssertionResult AreEqual(const WebMouseWheelEvent& lhs,
+ const WebMouseWheelEvent& rhs) {
+ if (lhs.size != rhs.size)
+ return ::testing::AssertionSuccess() << "Sizes aren't equal";
+ if (lhs.type != rhs.type)
+ return ::testing::AssertionSuccess() << "Types aren't equal";
+ if (memcmp(&lhs, &rhs, lhs.size) == 0)
+ return ::testing::AssertionSuccess();
+ else
+ return ::testing::AssertionFailure();
}
-bool operator==(const WebTouchEvent& lhs, const WebTouchEvent& rhs) {
- return memcmp(&lhs, &rhs, lhs.size) == 0;
+::testing::AssertionResult AreEqual(const WebTouchEvent& lhs,
+ const WebTouchEvent& rhs) {
+ if (lhs.size != rhs.size)
+ return ::testing::AssertionSuccess() << "Sizes aren't equal";
+ if (lhs.type != rhs.type)
+ return ::testing::AssertionSuccess() << "Types aren't equal";
+ if (memcmp(&lhs, &rhs, lhs.size) == 0)
+ return ::testing::AssertionSuccess();
+ else
+ return ::testing::AssertionFailure();
}
+
} // namespace blink
namespace content {
@@ -123,6 +141,38 @@ class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>,
}
}
+ void set_enable_non_blocking_due_to_main_thread_responsiveness_flag(bool enable_flag) {
+ queue_->enable_non_blocking_due_to_main_thread_responsiveness_flag_ =
+ enable_flag;
+ }
+
+ const WebTouchEvent* last_touch_event() const {
+ for (auto i = handled_events_.rbegin(); i != handled_events_.rend(); ++i) {
+ if (WebInputEvent::isTouchEventType(i->get()->type))
+ return static_cast<const WebTouchEvent*>(i->get());
+ }
+ CHECK(false);
+ return nullptr;
+ }
+
+ const WebMouseWheelEvent* first_wheel_event() const {
+ for (auto i = handled_events_.begin(); i != handled_events_.end(); ++i) {
+ if (i->get()->type == WebInputEvent::MouseWheel)
+ return static_cast<const WebMouseWheelEvent*>(i->get());
+ }
+ CHECK(false);
+ return nullptr;
+ }
+
+ const WebMouseWheelEvent* last_wheel_event() const {
+ for (auto i = handled_events_.rbegin(); i != handled_events_.rend(); ++i) {
+ if (i->get()->type == WebInputEvent::MouseWheel)
+ return static_cast<const WebMouseWheelEvent*>(i->get());
+ }
+ CHECK(false);
+ return nullptr;
+ }
+
protected:
base::test::ScopedFeatureList feature_list_;
scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_;
@@ -159,27 +209,21 @@ TEST_P(MainThreadEventQueueTest, NonBlockingWheel) {
EXPECT_EQ(2u, handled_events_.size());
{
- EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type);
- const WebMouseWheelEvent* last_wheel_event =
- static_cast<const WebMouseWheelEvent*>(handled_events_.at(0).get());
EXPECT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive,
- last_wheel_event->dispatchType);
+ last_wheel_event()->dispatchType);
WebMouseWheelEvent coalesced_event = kEvents[0];
internal::Coalesce(kEvents[1], &coalesced_event);
coalesced_event.dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(coalesced_event, *last_wheel_event);
+ EXPECT_TRUE(AreEqual(coalesced_event, *first_wheel_event()));
}
{
- const WebMouseWheelEvent* last_wheel_event =
- static_cast<const WebMouseWheelEvent*>(handled_events_.at(1).get());
WebMouseWheelEvent coalesced_event = kEvents[2];
internal::Coalesce(kEvents[3], &coalesced_event);
coalesced_event.dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(coalesced_event, *last_wheel_event);
+ EXPECT_TRUE(AreEqual(coalesced_event, *last_wheel_event()));
}
histogram_tester.ExpectUniqueSample(kCoalescedCountHistogram, 1, 2);
}
@@ -207,31 +251,22 @@ TEST_P(MainThreadEventQueueTest, NonBlockingTouch) {
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(3u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type);
- const WebTouchEvent* last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(0).get());
kEvents[0].dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
- EXPECT_EQ(kEvents[1].size, handled_events_.at(1)->size);
- EXPECT_EQ(kEvents[1].type, handled_events_.at(1)->type);
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(1).get());
kEvents[1].dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(kEvents[1], *last_touch_event);
+ EXPECT_TRUE(AreEqual(
+ kEvents[1], *static_cast<WebTouchEvent*>(handled_events_.at(1).get())));
EXPECT_EQ(kEvents[2].size, handled_events_.at(1)->size);
EXPECT_EQ(kEvents[2].type, handled_events_.at(2)->type);
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(2).get());
WebTouchEvent coalesced_event = kEvents[2];
internal::Coalesce(kEvents[3], &coalesced_event);
coalesced_event.dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(coalesced_event, *last_touch_event);
+ EXPECT_TRUE(AreEqual(coalesced_event, *last_touch_event()));
histogram_tester.ExpectBucketCount(kCoalescedCountHistogram, 0, 1);
histogram_tester.ExpectBucketCount(kCoalescedCountHistogram, 1, 1);
}
@@ -300,28 +335,20 @@ TEST_P(MainThreadEventQueueTest, InterleavedEvents) {
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(2u, handled_events_.size());
{
- EXPECT_EQ(kWheelEvents[0].size, handled_events_.at(0)->size);
- EXPECT_EQ(kWheelEvents[0].type, handled_events_.at(0)->type);
- const WebMouseWheelEvent* last_wheel_event =
- static_cast<const WebMouseWheelEvent*>(handled_events_.at(0).get());
EXPECT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive,
- last_wheel_event->dispatchType);
+ last_wheel_event()->dispatchType);
WebMouseWheelEvent coalesced_event = kWheelEvents[0];
internal::Coalesce(kWheelEvents[1], &coalesced_event);
coalesced_event.dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(coalesced_event, *last_wheel_event);
+ EXPECT_TRUE(AreEqual(coalesced_event, *last_wheel_event()));
}
{
- EXPECT_EQ(kTouchEvents[0].size, handled_events_.at(1)->size);
- EXPECT_EQ(kTouchEvents[0].type, handled_events_.at(1)->type);
- const WebTouchEvent* last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(1).get());
WebTouchEvent coalesced_event = kTouchEvents[0];
internal::Coalesce(kTouchEvents[1], &coalesced_event);
coalesced_event.dispatchType =
WebInputEvent::DispatchType::ListenersNonBlockingPassive;
- EXPECT_EQ(coalesced_event, *last_touch_event);
+ EXPECT_TRUE(AreEqual(coalesced_event, *last_touch_event()));
}
}
@@ -447,14 +474,10 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(1u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type);
EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling());
- const WebTouchEvent* last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(0).get());
kEvents[0].dispatchedDuringFling = true;
kEvents[0].dispatchType = WebInputEvent::ListenersForcedNonBlockingDueToFling;
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
kEvents[0].MovePoint(0, 30, 30);
EXPECT_FALSE(main_task_runner_->HasPendingTask());
@@ -465,14 +488,10 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(2u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(1)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(1)->type);
EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling());
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(1).get());
kEvents[0].dispatchedDuringFling = true;
kEvents[0].dispatchType = WebInputEvent::ListenersForcedNonBlockingDueToFling;
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
kEvents[0].MovePoint(0, 50, 50);
kEvents[0].touchStartOrFirstTouchMove = false;
@@ -481,13 +500,9 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(3u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(2)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(2)->type);
EXPECT_TRUE(kEvents[0].dispatchedDuringFling);
EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking);
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(2).get());
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
kEvents[0].ReleasePoint(0);
HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
@@ -495,13 +510,9 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(4u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(3)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(3)->type);
EXPECT_TRUE(kEvents[0].dispatchedDuringFling);
EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking);
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(3).get());
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
}
TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) {
@@ -516,14 +527,10 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(1u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type);
EXPECT_FALSE(kEvents[0].dispatchedDuringFling);
EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking);
EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling());
- const WebTouchEvent* last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(0).get());
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
set_is_flinging(true);
set_enable_fling_passive_listener_flag(false);
@@ -532,15 +539,11 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(2u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(1)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(1)->type);
EXPECT_FALSE(kEvents[0].dispatchedDuringFling);
EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking);
EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling());
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(1).get());
kEvents[0].dispatchedDuringFling = true;
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
set_is_flinging(false);
set_enable_fling_passive_listener_flag(true);
@@ -549,15 +552,11 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(3u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(2)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(2)->type);
EXPECT_TRUE(kEvents[0].dispatchedDuringFling);
EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking);
EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling());
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(2).get());
kEvents[0].dispatchedDuringFling = false;
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
kEvents[0].MovePoint(0, 30, 30);
HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
@@ -565,14 +564,62 @@ TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) {
EXPECT_FALSE(main_task_runner_->HasPendingTask());
EXPECT_EQ(0u, event_queue().size());
EXPECT_EQ(4u, handled_events_.size());
- EXPECT_EQ(kEvents[0].size, handled_events_.at(3)->size);
- EXPECT_EQ(kEvents[0].type, handled_events_.at(3)->type);
EXPECT_FALSE(kEvents[0].dispatchedDuringFling);
EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking);
EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling());
- last_touch_event =
- static_cast<const WebTouchEvent*>(handled_events_.at(3).get());
- EXPECT_EQ(kEvents[0], *last_touch_event);
+ EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event()));
+}
+
+TEST_P(MainThreadEventQueueTest, ForcedNonBlockingDueToUnresponsiveMainThread) {
+ SyntheticWebTouchEvent kEvent;
+ kEvent.PressPoint(10, 10);
+ kEvent.touchStartOrFirstTouchMove = true;
+ set_enable_non_blocking_due_to_main_thread_responsiveness_flag(true);
+
+ EXPECT_CALL(renderer_scheduler_,
+ ShouldForceEventsNonBlockingForUnresponsiveMainThread())
+ .Times(4)
+ .WillRepeatedly(testing::Return(true));
+
+ HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ RunPendingTasksWithSimulatedRaf();
+ EXPECT_FALSE(main_task_runner_->HasPendingTask());
+ EXPECT_EQ(0u, event_queue().size());
+ EXPECT_EQ(1u, handled_events_.size());
+ kEvent.dispatchType =
+ WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness;
+ EXPECT_TRUE(AreEqual(kEvent, *last_touch_event()));
+
+ kEvent.MovePoint(0, 30, 30);
+ HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ RunPendingTasksWithSimulatedRaf();
+ EXPECT_FALSE(main_task_runner_->HasPendingTask());
+ EXPECT_EQ(0u, event_queue().size());
+ EXPECT_EQ(2u, handled_events_.size());
+ kEvent.dispatchType =
+ WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness;
+ EXPECT_TRUE(AreEqual(kEvent, *last_touch_event()));
+
+ kEvent.MovePoint(0, 50, 50);
+ kEvent.touchStartOrFirstTouchMove = false;
+ HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ RunPendingTasksWithSimulatedRaf();
+ EXPECT_FALSE(main_task_runner_->HasPendingTask());
+ EXPECT_EQ(0u, event_queue().size());
+ EXPECT_EQ(3u, handled_events_.size());
+ kEvent.dispatchType =
+ WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness;
+ EXPECT_TRUE(AreEqual(kEvent, *last_touch_event()));
+
+ kEvent.ReleasePoint(0);
+ HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ RunPendingTasksWithSimulatedRaf();
+ EXPECT_FALSE(main_task_runner_->HasPendingTask());
+ EXPECT_EQ(0u, event_queue().size());
+ EXPECT_EQ(4u, handled_events_.size());
+ kEvent.dispatchType =
+ WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness;
+ EXPECT_TRUE(AreEqual(kEvent, *last_touch_event()));
}
// The boolean parameterized test varies whether rAF aligned input

Powered by Google App Engine
This is Rietveld 408576698