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

Unified Diff: content/renderer/input/main_thread_event_queue_unittest.cc

Issue 2713093005: Teach MainThreadEventQueue about touchmove throttling. (Closed)
Patch Set: Roll if/else condition together Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/input/main_thread_event_queue.cc ('k') | content/renderer/render_widget.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1fe94ddd0c00acf6c9038170752db78726f559c6 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 base::TimeDelta kFrameInterval = base::TimeDelta::FromMilliseconds(16);
+
const int kTestRoutingID = 13;
const char* kCoalescedCountHistogram =
"Event.MainThreadEventQueue.CoalescedCount";
@@ -114,14 +117,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_ += kFrameInterval;
+ queue_->DispatchRafAlignedInput(frame_time_);
}
}
void RunSimulatedRafOnce() {
if (needs_main_frame_) {
needs_main_frame_ = false;
- queue_->DispatchRafAlignedInput();
+ frame_time_ += kFrameInterval;
+ queue_->DispatchRafAlignedInput(frame_time_);
}
}
@@ -135,6 +140,7 @@ class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>,
std::vector<uint32_t> additional_acked_events_;
int raf_aligned_input_setting_;
bool needs_main_frame_;
+ base::TimeTicks frame_time_;
};
TEST_P(MainThreadEventQueueTest, NonBlockingWheel) {
@@ -582,6 +588,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);
« no previous file with comments | « content/renderer/input/main_thread_event_queue.cc ('k') | content/renderer/render_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698