OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <new> | 7 #include <new> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 return memcmp(&lhs, &rhs, lhs.size()) == 0; | 35 return memcmp(&lhs, &rhs, lhs.size()) == 0; |
36 } | 36 } |
37 } // namespace blink | 37 } // namespace blink |
38 | 38 |
39 namespace content { | 39 namespace content { |
40 namespace { | 40 namespace { |
41 | 41 |
42 const unsigned kRafAlignedEnabledTouch = 1; | 42 const unsigned kRafAlignedEnabledTouch = 1; |
43 const unsigned kRafAlignedEnabledMouse = 1 << 1; | 43 const unsigned kRafAlignedEnabledMouse = 1 << 1; |
44 | 44 |
| 45 // Simulate a 16ms frame signal. |
| 46 const base::TimeDelta kFrameInterval = base::TimeDelta::FromMilliseconds(16); |
| 47 |
45 const int kTestRoutingID = 13; | 48 const int kTestRoutingID = 13; |
46 const char* kCoalescedCountHistogram = | 49 const char* kCoalescedCountHistogram = |
47 "Event.MainThreadEventQueue.CoalescedCount"; | 50 "Event.MainThreadEventQueue.CoalescedCount"; |
48 | 51 |
49 } // namespace | 52 } // namespace |
50 | 53 |
51 class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>, | 54 class MainThreadEventQueueTest : public testing::TestWithParam<unsigned>, |
52 public MainThreadEventQueueClient { | 55 public MainThreadEventQueueClient { |
53 public: | 56 public: |
54 MainThreadEventQueueTest() | 57 MainThreadEventQueueTest() |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 110 } |
108 | 111 |
109 void set_enable_fling_passive_listener_flag(bool enable_flag) { | 112 void set_enable_fling_passive_listener_flag(bool enable_flag) { |
110 queue_->enable_fling_passive_listener_flag_ = enable_flag; | 113 queue_->enable_fling_passive_listener_flag_ = enable_flag; |
111 } | 114 } |
112 | 115 |
113 void RunPendingTasksWithSimulatedRaf() { | 116 void RunPendingTasksWithSimulatedRaf() { |
114 while (needs_main_frame_ || main_task_runner_->HasPendingTask()) { | 117 while (needs_main_frame_ || main_task_runner_->HasPendingTask()) { |
115 main_task_runner_->RunUntilIdle(); | 118 main_task_runner_->RunUntilIdle(); |
116 needs_main_frame_ = false; | 119 needs_main_frame_ = false; |
117 queue_->DispatchRafAlignedInput(); | 120 frame_time_ += kFrameInterval; |
| 121 queue_->DispatchRafAlignedInput(frame_time_); |
118 } | 122 } |
119 } | 123 } |
120 | 124 |
121 void RunSimulatedRafOnce() { | 125 void RunSimulatedRafOnce() { |
122 if (needs_main_frame_) { | 126 if (needs_main_frame_) { |
123 needs_main_frame_ = false; | 127 needs_main_frame_ = false; |
124 queue_->DispatchRafAlignedInput(); | 128 frame_time_ += kFrameInterval; |
| 129 queue_->DispatchRafAlignedInput(frame_time_); |
125 } | 130 } |
126 } | 131 } |
127 | 132 |
128 protected: | 133 protected: |
129 base::test::ScopedFeatureList feature_list_; | 134 base::test::ScopedFeatureList feature_list_; |
130 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; | 135 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; |
131 blink::scheduler::MockRendererScheduler renderer_scheduler_; | 136 blink::scheduler::MockRendererScheduler renderer_scheduler_; |
132 scoped_refptr<MainThreadEventQueue> queue_; | 137 scoped_refptr<MainThreadEventQueue> queue_; |
133 std::vector<blink::WebCoalescedInputEvent> handled_events_; | 138 std::vector<blink::WebCoalescedInputEvent> handled_events_; |
134 | 139 |
135 std::vector<uint32_t> additional_acked_events_; | 140 std::vector<uint32_t> additional_acked_events_; |
136 int raf_aligned_input_setting_; | 141 int raf_aligned_input_setting_; |
137 bool needs_main_frame_; | 142 bool needs_main_frame_; |
| 143 base::TimeTicks frame_time_; |
138 }; | 144 }; |
139 | 145 |
140 TEST_P(MainThreadEventQueueTest, NonBlockingWheel) { | 146 TEST_P(MainThreadEventQueueTest, NonBlockingWheel) { |
141 base::HistogramTester histogram_tester; | 147 base::HistogramTester histogram_tester; |
142 | 148 |
143 WebMouseWheelEvent kEvents[4] = { | 149 WebMouseWheelEvent kEvents[4] = { |
144 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), | 150 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), |
145 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), | 151 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), |
146 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), | 152 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
147 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), | 153 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 EXPECT_TRUE(needs_main_frame_); | 581 EXPECT_TRUE(needs_main_frame_); |
576 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); | 582 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
577 EXPECT_EQ(1u, event_queue().size()); | 583 EXPECT_EQ(1u, event_queue().size()); |
578 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 584 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
579 EXPECT_TRUE(needs_main_frame_); | 585 EXPECT_TRUE(needs_main_frame_); |
580 RunPendingTasksWithSimulatedRaf(); | 586 RunPendingTasksWithSimulatedRaf(); |
581 EXPECT_EQ(0u, event_queue().size()); | 587 EXPECT_EQ(0u, event_queue().size()); |
582 EXPECT_EQ(0u, additional_acked_events_.size()); | 588 EXPECT_EQ(0u, additional_acked_events_.size()); |
583 } | 589 } |
584 | 590 |
| 591 TEST_P(MainThreadEventQueueTest, RafAlignedTouchInputThrottlingMoves) { |
| 592 // Don't run the test when we aren't supporting rAF aligned input. |
| 593 if ((raf_aligned_input_setting_ & kRafAlignedEnabledTouch) == 0) |
| 594 return; |
| 595 |
| 596 SyntheticWebTouchEvent kEvents[2]; |
| 597 kEvents[0].PressPoint(10, 10); |
| 598 kEvents[0].MovePoint(0, 50, 50); |
| 599 kEvents[0].dispatchType = WebInputEvent::EventNonBlocking; |
| 600 kEvents[1].PressPoint(10, 10); |
| 601 kEvents[1].MovePoint(0, 20, 20); |
| 602 kEvents[1].dispatchType = WebInputEvent::EventNonBlocking; |
| 603 |
| 604 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 605 EXPECT_EQ(0u, event_queue().size()); |
| 606 |
| 607 // Send a non-cancelable touch move and then send it another one. The |
| 608 // second one shouldn't go out with the next rAF call and should be throttled. |
| 609 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 610 EXPECT_EQ(1u, event_queue().size()); |
| 611 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 612 EXPECT_TRUE(needs_main_frame_); |
| 613 RunPendingTasksWithSimulatedRaf(); |
| 614 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 615 EXPECT_TRUE(HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 616 EXPECT_EQ(1u, event_queue().size()); |
| 617 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 618 EXPECT_TRUE(needs_main_frame_); |
| 619 |
| 620 // Event should still be in queue after handling a single rAF call. |
| 621 RunSimulatedRafOnce(); |
| 622 EXPECT_EQ(1u, event_queue().size()); |
| 623 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 624 EXPECT_TRUE(needs_main_frame_); |
| 625 |
| 626 // And should eventually flush. |
| 627 RunPendingTasksWithSimulatedRaf(); |
| 628 EXPECT_EQ(0u, event_queue().size()); |
| 629 EXPECT_EQ(0u, additional_acked_events_.size()); |
| 630 } |
| 631 |
585 TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) { | 632 TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) { |
586 SyntheticWebTouchEvent kEvents; | 633 SyntheticWebTouchEvent kEvents; |
587 kEvents.PressPoint(10, 10); | 634 kEvents.PressPoint(10, 10); |
588 kEvents.touchStartOrFirstTouchMove = true; | 635 kEvents.touchStartOrFirstTouchMove = true; |
589 set_enable_fling_passive_listener_flag(true); | 636 set_enable_fling_passive_listener_flag(true); |
590 | 637 |
591 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 638 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
592 HandleEvent(kEvents, INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING); | 639 HandleEvent(kEvents, INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING); |
593 RunPendingTasksWithSimulatedRaf(); | 640 RunPendingTasksWithSimulatedRaf(); |
594 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 641 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 "MainThreadResponsivenessScrollIntervention", "Control"); | 822 "MainThreadResponsivenessScrollIntervention", "Control"); |
776 queue_ = new MainThreadEventQueue(kTestRoutingID, | 823 queue_ = new MainThreadEventQueue(kTestRoutingID, |
777 &dummy_main_thread_event_queue_client_, | 824 &dummy_main_thread_event_queue_client_, |
778 main_task_runner_, &renderer_scheduler_); | 825 main_task_runner_, &renderer_scheduler_); |
779 EXPECT_FALSE(enable_non_blocking_due_to_main_thread_responsiveness_flag()); | 826 EXPECT_FALSE(enable_non_blocking_due_to_main_thread_responsiveness_flag()); |
780 EXPECT_EQ(base::TimeDelta::FromMilliseconds(0), | 827 EXPECT_EQ(base::TimeDelta::FromMilliseconds(0), |
781 main_thread_responsiveness_threshold()); | 828 main_thread_responsiveness_threshold()); |
782 } | 829 } |
783 | 830 |
784 } // namespace content | 831 } // namespace content |
OLD | NEW |