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 2cdd7c4215f8cb7cfab0f84a58611e75036c9d62..d54be0eaa600ae3812eb9662b71cdc1e4cefb572 100644 |
--- a/content/renderer/input/main_thread_event_queue_unittest.cc |
+++ b/content/renderer/input/main_thread_event_queue_unittest.cc |
@@ -42,6 +42,9 @@ namespace { |
const unsigned kRafAlignedEnabledTouch = 1; |
const unsigned kRafAlignedEnabledMouse = 1 << 1; |
+// Simulate a 16ms frame signal. |
+const double kFrameInterval = 0.016; |
+ |
const int kTestRoutingID = 13; |
const char* kCoalescedCountHistogram = |
"Event.MainThreadEventQueue.CoalescedCount"; |
@@ -54,7 +57,8 @@ class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>, |
MainThreadEventQueueTest() |
: main_task_runner_(new base::TestSimpleTaskRunner()), |
raf_aligned_input_setting_(GetParam()), |
- needs_main_frame_(false) { |
+ needs_main_frame_(false), |
+ frame_time_sec_(0) { |
std::vector<std::string> features; |
if (raf_aligned_input_setting_ & kRafAlignedEnabledTouch) |
features.push_back(features::kRafAlignedTouchInputEvents.name); |
@@ -114,14 +118,16 @@ class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>, |
while (needs_main_frame_ || main_task_runner_->HasPendingTask()) { |
main_task_runner_->RunUntilIdle(); |
needs_main_frame_ = false; |
- queue_->DispatchRafAlignedInput(); |
+ frame_time_sec_ += kFrameInterval; |
+ queue_->DispatchRafAlignedInput(frame_time_sec_); |
} |
} |
void RunSimulatedRafOnce() { |
if (needs_main_frame_) { |
needs_main_frame_ = false; |
- queue_->DispatchRafAlignedInput(); |
+ frame_time_sec_ += kFrameInterval; |
+ queue_->DispatchRafAlignedInput(frame_time_sec_); |
} |
} |
@@ -135,6 +141,7 @@ class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>, |
std::vector<uint32_t> additional_acked_events_; |
int raf_aligned_input_setting_; |
bool needs_main_frame_; |
+ double frame_time_sec_; |
}; |
TEST_P(MainThreadEventQueueTest, NonBlockingWheel) { |
@@ -582,6 +589,47 @@ TEST_P(MainThreadEventQueueTest, RafAlignedTouchInputCoalescedMoves) { |
EXPECT_EQ(0u, additional_acked_events_.size()); |
} |
+TEST_P(MainThreadEventQueueTest, RafAlignedTouchInputThrottlingMoves) { |
+ // Don't run the test when we aren't supporting rAF aligned input. |
+ if ((raf_aligned_input_setting_ & kRafAlignedEnabledTouch) == 0) |
+ return; |
+ |
+ SyntheticWebTouchEvent kEvents[2]; |
+ kEvents[0].PressPoint(10, 10); |
+ kEvents[0].MovePoint(0, 50, 50); |
+ kEvents[0].dispatchType = WebInputEvent::EventNonBlocking; |
+ kEvents[1].PressPoint(10, 10); |
+ kEvents[1].MovePoint(0, 20, 20); |
+ kEvents[1].dispatchType = WebInputEvent::EventNonBlocking; |
+ |
+ EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
+ EXPECT_EQ(0u, event_queue().size()); |
+ |
+ // Send a non-cancelable touch move and then send it another one. The |
+ // second one shouldn't go out with the next rAF call and should be throttled. |
+ EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
+ EXPECT_EQ(1u, event_queue().size()); |
+ EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
+ EXPECT_TRUE(needs_main_frame_); |
+ RunPendingTasksWithSimulatedRaf(); |
+ EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
+ EXPECT_TRUE(HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
+ EXPECT_EQ(1u, event_queue().size()); |
+ EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
+ EXPECT_TRUE(needs_main_frame_); |
+ |
+ // Event should still be in queue after handling a single rAF call. |
+ RunSimulatedRafOnce(); |
+ EXPECT_EQ(1u, event_queue().size()); |
+ EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
+ EXPECT_TRUE(needs_main_frame_); |
+ |
+ // And should eventually flush. |
+ RunPendingTasksWithSimulatedRaf(); |
+ EXPECT_EQ(0u, event_queue().size()); |
+ EXPECT_EQ(0u, additional_acked_events_.size()); |
+} |
+ |
TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) { |
SyntheticWebTouchEvent kEvents; |
kEvents.PressPoint(10, 10); |