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 double kFrameInterval = 0.016; |
| 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() |
55 : main_task_runner_(new base::TestSimpleTaskRunner()), | 58 : main_task_runner_(new base::TestSimpleTaskRunner()), |
56 raf_aligned_input_setting_(GetParam()), | 59 raf_aligned_input_setting_(GetParam()), |
57 needs_main_frame_(false) { | 60 needs_main_frame_(false), |
| 61 frame_time_sec_(0) { |
58 std::vector<std::string> features; | 62 std::vector<std::string> features; |
59 if (raf_aligned_input_setting_ & kRafAlignedEnabledTouch) | 63 if (raf_aligned_input_setting_ & kRafAlignedEnabledTouch) |
60 features.push_back(features::kRafAlignedTouchInputEvents.name); | 64 features.push_back(features::kRafAlignedTouchInputEvents.name); |
61 if (raf_aligned_input_setting_ & kRafAlignedEnabledMouse) | 65 if (raf_aligned_input_setting_ & kRafAlignedEnabledMouse) |
62 features.push_back(features::kRafAlignedMouseInputEvents.name); | 66 features.push_back(features::kRafAlignedMouseInputEvents.name); |
63 | 67 |
64 feature_list_.InitFromCommandLine(base::JoinString(features, ","), | 68 feature_list_.InitFromCommandLine(base::JoinString(features, ","), |
65 std::string()); | 69 std::string()); |
66 } | 70 } |
67 | 71 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 111 } |
108 | 112 |
109 void set_enable_fling_passive_listener_flag(bool enable_flag) { | 113 void set_enable_fling_passive_listener_flag(bool enable_flag) { |
110 queue_->enable_fling_passive_listener_flag_ = enable_flag; | 114 queue_->enable_fling_passive_listener_flag_ = enable_flag; |
111 } | 115 } |
112 | 116 |
113 void RunPendingTasksWithSimulatedRaf() { | 117 void RunPendingTasksWithSimulatedRaf() { |
114 while (needs_main_frame_ || main_task_runner_->HasPendingTask()) { | 118 while (needs_main_frame_ || main_task_runner_->HasPendingTask()) { |
115 main_task_runner_->RunUntilIdle(); | 119 main_task_runner_->RunUntilIdle(); |
116 needs_main_frame_ = false; | 120 needs_main_frame_ = false; |
117 queue_->DispatchRafAlignedInput(); | 121 frame_time_sec_ += kFrameInterval; |
| 122 queue_->DispatchRafAlignedInput(frame_time_sec_); |
118 } | 123 } |
119 } | 124 } |
120 | 125 |
121 void RunSimulatedRafOnce() { | 126 void RunSimulatedRafOnce() { |
122 if (needs_main_frame_) { | 127 if (needs_main_frame_) { |
123 needs_main_frame_ = false; | 128 needs_main_frame_ = false; |
124 queue_->DispatchRafAlignedInput(); | 129 frame_time_sec_ += kFrameInterval; |
| 130 queue_->DispatchRafAlignedInput(frame_time_sec_); |
125 } | 131 } |
126 } | 132 } |
127 | 133 |
128 protected: | 134 protected: |
129 base::test::ScopedFeatureList feature_list_; | 135 base::test::ScopedFeatureList feature_list_; |
130 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; | 136 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; |
131 blink::scheduler::MockRendererScheduler renderer_scheduler_; | 137 blink::scheduler::MockRendererScheduler renderer_scheduler_; |
132 scoped_refptr<MainThreadEventQueue> queue_; | 138 scoped_refptr<MainThreadEventQueue> queue_; |
133 std::vector<blink::WebCoalescedInputEvent> handled_events_; | 139 std::vector<blink::WebCoalescedInputEvent> handled_events_; |
134 | 140 |
135 std::vector<uint32_t> additional_acked_events_; | 141 std::vector<uint32_t> additional_acked_events_; |
136 int raf_aligned_input_setting_; | 142 int raf_aligned_input_setting_; |
137 bool needs_main_frame_; | 143 bool needs_main_frame_; |
| 144 double frame_time_sec_; |
138 }; | 145 }; |
139 | 146 |
140 TEST_P(MainThreadEventQueueTest, NonBlockingWheel) { | 147 TEST_P(MainThreadEventQueueTest, NonBlockingWheel) { |
141 base::HistogramTester histogram_tester; | 148 base::HistogramTester histogram_tester; |
142 | 149 |
143 WebMouseWheelEvent kEvents[4] = { | 150 WebMouseWheelEvent kEvents[4] = { |
144 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), | 151 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), |
145 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), | 152 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), |
146 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), | 153 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
147 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), | 154 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_); | 582 EXPECT_TRUE(needs_main_frame_); |
576 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); | 583 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
577 EXPECT_EQ(1u, event_queue().size()); | 584 EXPECT_EQ(1u, event_queue().size()); |
578 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 585 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
579 EXPECT_TRUE(needs_main_frame_); | 586 EXPECT_TRUE(needs_main_frame_); |
580 RunPendingTasksWithSimulatedRaf(); | 587 RunPendingTasksWithSimulatedRaf(); |
581 EXPECT_EQ(0u, event_queue().size()); | 588 EXPECT_EQ(0u, event_queue().size()); |
582 EXPECT_EQ(0u, additional_acked_events_.size()); | 589 EXPECT_EQ(0u, additional_acked_events_.size()); |
583 } | 590 } |
584 | 591 |
| 592 TEST_P(MainThreadEventQueueTest, RafAlignedTouchInputThrottlingMoves) { |
| 593 // Don't run the test when we aren't supporting rAF aligned input. |
| 594 if ((raf_aligned_input_setting_ & kRafAlignedEnabledTouch) == 0) |
| 595 return; |
| 596 |
| 597 SyntheticWebTouchEvent kEvents[2]; |
| 598 kEvents[0].PressPoint(10, 10); |
| 599 kEvents[0].MovePoint(0, 50, 50); |
| 600 kEvents[0].dispatchType = WebInputEvent::EventNonBlocking; |
| 601 kEvents[1].PressPoint(10, 10); |
| 602 kEvents[1].MovePoint(0, 20, 20); |
| 603 kEvents[1].dispatchType = WebInputEvent::EventNonBlocking; |
| 604 |
| 605 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 606 EXPECT_EQ(0u, event_queue().size()); |
| 607 |
| 608 // Send a non-cancelable touch move and then send it another one. The |
| 609 // second one shouldn't go out with the next rAF call and should be throttled. |
| 610 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 611 EXPECT_EQ(1u, event_queue().size()); |
| 612 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 613 EXPECT_TRUE(needs_main_frame_); |
| 614 RunPendingTasksWithSimulatedRaf(); |
| 615 EXPECT_TRUE(HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 616 EXPECT_TRUE(HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 617 EXPECT_EQ(1u, event_queue().size()); |
| 618 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 619 EXPECT_TRUE(needs_main_frame_); |
| 620 |
| 621 // Event should still be in queue after handling a single rAF call. |
| 622 RunSimulatedRafOnce(); |
| 623 EXPECT_EQ(1u, event_queue().size()); |
| 624 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 625 EXPECT_TRUE(needs_main_frame_); |
| 626 |
| 627 // And should eventually flush. |
| 628 RunPendingTasksWithSimulatedRaf(); |
| 629 EXPECT_EQ(0u, event_queue().size()); |
| 630 EXPECT_EQ(0u, additional_acked_events_.size()); |
| 631 } |
| 632 |
585 TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) { | 633 TEST_P(MainThreadEventQueueTest, BlockingTouchesDuringFling) { |
586 SyntheticWebTouchEvent kEvents; | 634 SyntheticWebTouchEvent kEvents; |
587 kEvents.PressPoint(10, 10); | 635 kEvents.PressPoint(10, 10); |
588 kEvents.touchStartOrFirstTouchMove = true; | 636 kEvents.touchStartOrFirstTouchMove = true; |
589 set_enable_fling_passive_listener_flag(true); | 637 set_enable_fling_passive_listener_flag(true); |
590 | 638 |
591 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 639 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
592 HandleEvent(kEvents, INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING); | 640 HandleEvent(kEvents, INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING); |
593 RunPendingTasksWithSimulatedRaf(); | 641 RunPendingTasksWithSimulatedRaf(); |
594 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 642 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 "MainThreadResponsivenessScrollIntervention", "Control"); | 823 "MainThreadResponsivenessScrollIntervention", "Control"); |
776 queue_ = new MainThreadEventQueue(kTestRoutingID, | 824 queue_ = new MainThreadEventQueue(kTestRoutingID, |
777 &dummy_main_thread_event_queue_client_, | 825 &dummy_main_thread_event_queue_client_, |
778 main_task_runner_, &renderer_scheduler_); | 826 main_task_runner_, &renderer_scheduler_); |
779 EXPECT_FALSE(enable_non_blocking_due_to_main_thread_responsiveness_flag()); | 827 EXPECT_FALSE(enable_non_blocking_due_to_main_thread_responsiveness_flag()); |
780 EXPECT_EQ(base::TimeDelta::FromMilliseconds(0), | 828 EXPECT_EQ(base::TimeDelta::FromMilliseconds(0), |
781 main_thread_responsiveness_threshold()); | 829 main_thread_responsiveness_threshold()); |
782 } | 830 } |
783 | 831 |
784 } // namespace content | 832 } // namespace content |
OLD | NEW |