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 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "base/test/scoped_feature_list.h" | 14 #include "base/test/scoped_feature_list.h" |
15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "content/common/input/synthetic_web_input_event_builders.h" | 17 #include "content/common/input/synthetic_web_input_event_builders.h" |
18 #include "content/renderer/input/main_thread_event_queue.h" | 18 #include "content/renderer/input/main_thread_event_queue.h" |
19 #include "content/renderer/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/scheduler/test/mock_renderer_schedu
ler.h" | 21 #include "third_party/WebKit/public/platform/scheduler/test/mock_renderer_schedu
ler.h" |
22 | 22 |
23 using blink::WebInputEvent; | 23 using blink::WebInputEvent; |
24 using blink::WebMouseEvent; | 24 using blink::WebMouseEvent; |
25 using blink::WebMouseWheelEvent; | 25 using blink::WebMouseWheelEvent; |
26 using blink::WebTouchEvent; | 26 using blink::WebTouchEvent; |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 bool operator==(const WebMouseWheelEvent& lhs, const WebMouseWheelEvent& rhs) { | 29 |
30 return memcmp(&lhs, &rhs, lhs.size) == 0; | 30 ::testing::AssertionResult AreEqual(const WebMouseWheelEvent& lhs, |
| 31 const WebMouseWheelEvent& rhs) { |
| 32 if (lhs.size != rhs.size) |
| 33 return ::testing::AssertionSuccess() << "Sizes aren't equal"; |
| 34 if (lhs.type != rhs.type) |
| 35 return ::testing::AssertionSuccess() << "Types aren't equal"; |
| 36 if (memcmp(&lhs, &rhs, lhs.size) == 0) |
| 37 return ::testing::AssertionSuccess(); |
| 38 else |
| 39 return ::testing::AssertionFailure(); |
31 } | 40 } |
32 | 41 |
33 bool operator==(const WebTouchEvent& lhs, const WebTouchEvent& rhs) { | 42 ::testing::AssertionResult AreEqual(const WebTouchEvent& lhs, |
34 return memcmp(&lhs, &rhs, lhs.size) == 0; | 43 const WebTouchEvent& rhs) { |
| 44 if (lhs.size != rhs.size) |
| 45 return ::testing::AssertionSuccess() << "Sizes aren't equal"; |
| 46 if (lhs.type != rhs.type) |
| 47 return ::testing::AssertionSuccess() << "Types aren't equal"; |
| 48 if (memcmp(&lhs, &rhs, lhs.size) == 0) |
| 49 return ::testing::AssertionSuccess(); |
| 50 else |
| 51 return ::testing::AssertionFailure(); |
35 } | 52 } |
| 53 |
36 } // namespace blink | 54 } // namespace blink |
37 | 55 |
38 namespace content { | 56 namespace content { |
39 namespace { | 57 namespace { |
40 | 58 |
41 const unsigned kRafAlignedEnabledTouch = 1; | 59 const unsigned kRafAlignedEnabledTouch = 1; |
42 const unsigned kRafAlignedEnabledMouse = 1 << 1; | 60 const unsigned kRafAlignedEnabledMouse = 1 << 1; |
43 | 61 |
44 const int kTestRoutingID = 13; | 62 const int kTestRoutingID = 13; |
45 const char* kCoalescedCountHistogram = | 63 const char* kCoalescedCountHistogram = |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 134 } |
117 } | 135 } |
118 | 136 |
119 void RunSimulatedRafOnce() { | 137 void RunSimulatedRafOnce() { |
120 if (needs_main_frame_) { | 138 if (needs_main_frame_) { |
121 needs_main_frame_ = false; | 139 needs_main_frame_ = false; |
122 queue_->DispatchRafAlignedInput(); | 140 queue_->DispatchRafAlignedInput(); |
123 } | 141 } |
124 } | 142 } |
125 | 143 |
| 144 void set_enable_non_blocking_due_to_main_thread_responsiveness_flag(bool enabl
e_flag) { |
| 145 queue_->enable_non_blocking_due_to_main_thread_responsiveness_flag_ = |
| 146 enable_flag; |
| 147 } |
| 148 |
| 149 const WebTouchEvent* last_touch_event() const { |
| 150 for (auto i = handled_events_.rbegin(); i != handled_events_.rend(); ++i) { |
| 151 if (WebInputEvent::isTouchEventType(i->get()->type)) |
| 152 return static_cast<const WebTouchEvent*>(i->get()); |
| 153 } |
| 154 CHECK(false); |
| 155 return nullptr; |
| 156 } |
| 157 |
| 158 const WebMouseWheelEvent* first_wheel_event() const { |
| 159 for (auto i = handled_events_.begin(); i != handled_events_.end(); ++i) { |
| 160 if (i->get()->type == WebInputEvent::MouseWheel) |
| 161 return static_cast<const WebMouseWheelEvent*>(i->get()); |
| 162 } |
| 163 CHECK(false); |
| 164 return nullptr; |
| 165 } |
| 166 |
| 167 const WebMouseWheelEvent* last_wheel_event() const { |
| 168 for (auto i = handled_events_.rbegin(); i != handled_events_.rend(); ++i) { |
| 169 if (i->get()->type == WebInputEvent::MouseWheel) |
| 170 return static_cast<const WebMouseWheelEvent*>(i->get()); |
| 171 } |
| 172 CHECK(false); |
| 173 return nullptr; |
| 174 } |
| 175 |
126 protected: | 176 protected: |
127 base::test::ScopedFeatureList feature_list_; | 177 base::test::ScopedFeatureList feature_list_; |
128 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; | 178 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; |
129 blink::scheduler::MockRendererScheduler renderer_scheduler_; | 179 blink::scheduler::MockRendererScheduler renderer_scheduler_; |
130 scoped_refptr<MainThreadEventQueue> queue_; | 180 scoped_refptr<MainThreadEventQueue> queue_; |
131 std::vector<ui::ScopedWebInputEvent> handled_events_; | 181 std::vector<ui::ScopedWebInputEvent> handled_events_; |
132 std::vector<uint32_t> additional_acked_events_; | 182 std::vector<uint32_t> additional_acked_events_; |
133 int raf_aligned_input_setting_; | 183 int raf_aligned_input_setting_; |
134 bool needs_main_frame_; | 184 bool needs_main_frame_; |
135 }; | 185 }; |
(...skipping 16 matching lines...) Expand all Loading... |
152 | 202 |
153 EXPECT_EQ(2u, event_queue().size()); | 203 EXPECT_EQ(2u, event_queue().size()); |
154 EXPECT_EQ((raf_aligned_input_setting_ & kRafAlignedEnabledMouse) == 0, | 204 EXPECT_EQ((raf_aligned_input_setting_ & kRafAlignedEnabledMouse) == 0, |
155 main_task_runner_->HasPendingTask()); | 205 main_task_runner_->HasPendingTask()); |
156 RunPendingTasksWithSimulatedRaf(); | 206 RunPendingTasksWithSimulatedRaf(); |
157 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 207 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
158 EXPECT_EQ(0u, event_queue().size()); | 208 EXPECT_EQ(0u, event_queue().size()); |
159 EXPECT_EQ(2u, handled_events_.size()); | 209 EXPECT_EQ(2u, handled_events_.size()); |
160 | 210 |
161 { | 211 { |
162 EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size); | |
163 EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type); | |
164 const WebMouseWheelEvent* last_wheel_event = | |
165 static_cast<const WebMouseWheelEvent*>(handled_events_.at(0).get()); | |
166 EXPECT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive, | 212 EXPECT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive, |
167 last_wheel_event->dispatchType); | 213 last_wheel_event()->dispatchType); |
168 WebMouseWheelEvent coalesced_event = kEvents[0]; | 214 WebMouseWheelEvent coalesced_event = kEvents[0]; |
169 internal::Coalesce(kEvents[1], &coalesced_event); | 215 internal::Coalesce(kEvents[1], &coalesced_event); |
170 coalesced_event.dispatchType = | 216 coalesced_event.dispatchType = |
171 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 217 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
172 EXPECT_EQ(coalesced_event, *last_wheel_event); | 218 EXPECT_TRUE(AreEqual(coalesced_event, *first_wheel_event())); |
173 } | 219 } |
174 | 220 |
175 { | 221 { |
176 const WebMouseWheelEvent* last_wheel_event = | |
177 static_cast<const WebMouseWheelEvent*>(handled_events_.at(1).get()); | |
178 WebMouseWheelEvent coalesced_event = kEvents[2]; | 222 WebMouseWheelEvent coalesced_event = kEvents[2]; |
179 internal::Coalesce(kEvents[3], &coalesced_event); | 223 internal::Coalesce(kEvents[3], &coalesced_event); |
180 coalesced_event.dispatchType = | 224 coalesced_event.dispatchType = |
181 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 225 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
182 EXPECT_EQ(coalesced_event, *last_wheel_event); | 226 EXPECT_TRUE(AreEqual(coalesced_event, *last_wheel_event())); |
183 } | 227 } |
184 histogram_tester.ExpectUniqueSample(kCoalescedCountHistogram, 1, 2); | 228 histogram_tester.ExpectUniqueSample(kCoalescedCountHistogram, 1, 2); |
185 } | 229 } |
186 | 230 |
187 TEST_P(MainThreadEventQueueTest, NonBlockingTouch) { | 231 TEST_P(MainThreadEventQueueTest, NonBlockingTouch) { |
188 base::HistogramTester histogram_tester; | 232 base::HistogramTester histogram_tester; |
189 | 233 |
190 SyntheticWebTouchEvent kEvents[4]; | 234 SyntheticWebTouchEvent kEvents[4]; |
191 kEvents[0].PressPoint(10, 10); | 235 kEvents[0].PressPoint(10, 10); |
192 kEvents[1].PressPoint(10, 10); | 236 kEvents[1].PressPoint(10, 10); |
193 kEvents[1].modifiers = 1; | 237 kEvents[1].modifiers = 1; |
194 kEvents[1].MovePoint(0, 20, 20); | 238 kEvents[1].MovePoint(0, 20, 20); |
195 kEvents[2].PressPoint(10, 10); | 239 kEvents[2].PressPoint(10, 10); |
196 kEvents[2].MovePoint(0, 30, 30); | 240 kEvents[2].MovePoint(0, 30, 30); |
197 kEvents[3].PressPoint(10, 10); | 241 kEvents[3].PressPoint(10, 10); |
198 kEvents[3].MovePoint(0, 35, 35); | 242 kEvents[3].MovePoint(0, 35, 35); |
199 | 243 |
200 for (SyntheticWebTouchEvent& event : kEvents) | 244 for (SyntheticWebTouchEvent& event : kEvents) |
201 HandleEvent(event, INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING); | 245 HandleEvent(event, INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING); |
202 | 246 |
203 EXPECT_EQ(3u, event_queue().size()); | 247 EXPECT_EQ(3u, event_queue().size()); |
204 EXPECT_TRUE(main_task_runner_->HasPendingTask()); | 248 EXPECT_TRUE(main_task_runner_->HasPendingTask()); |
205 RunPendingTasksWithSimulatedRaf(); | 249 RunPendingTasksWithSimulatedRaf(); |
206 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 250 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
207 EXPECT_EQ(0u, event_queue().size()); | 251 EXPECT_EQ(0u, event_queue().size()); |
208 EXPECT_EQ(3u, handled_events_.size()); | 252 EXPECT_EQ(3u, handled_events_.size()); |
209 | 253 |
210 EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size); | |
211 EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type); | |
212 const WebTouchEvent* last_touch_event = | |
213 static_cast<const WebTouchEvent*>(handled_events_.at(0).get()); | |
214 kEvents[0].dispatchType = | 254 kEvents[0].dispatchType = |
215 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 255 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
216 EXPECT_EQ(kEvents[0], *last_touch_event); | 256 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
217 | 257 |
218 EXPECT_EQ(kEvents[1].size, handled_events_.at(1)->size); | |
219 EXPECT_EQ(kEvents[1].type, handled_events_.at(1)->type); | |
220 last_touch_event = | |
221 static_cast<const WebTouchEvent*>(handled_events_.at(1).get()); | |
222 kEvents[1].dispatchType = | 258 kEvents[1].dispatchType = |
223 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 259 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
224 EXPECT_EQ(kEvents[1], *last_touch_event); | 260 EXPECT_TRUE(AreEqual( |
| 261 kEvents[1], *static_cast<WebTouchEvent*>(handled_events_.at(1).get()))); |
225 | 262 |
226 EXPECT_EQ(kEvents[2].size, handled_events_.at(1)->size); | 263 EXPECT_EQ(kEvents[2].size, handled_events_.at(1)->size); |
227 EXPECT_EQ(kEvents[2].type, handled_events_.at(2)->type); | 264 EXPECT_EQ(kEvents[2].type, handled_events_.at(2)->type); |
228 last_touch_event = | |
229 static_cast<const WebTouchEvent*>(handled_events_.at(2).get()); | |
230 WebTouchEvent coalesced_event = kEvents[2]; | 265 WebTouchEvent coalesced_event = kEvents[2]; |
231 internal::Coalesce(kEvents[3], &coalesced_event); | 266 internal::Coalesce(kEvents[3], &coalesced_event); |
232 coalesced_event.dispatchType = | 267 coalesced_event.dispatchType = |
233 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 268 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
234 EXPECT_EQ(coalesced_event, *last_touch_event); | 269 EXPECT_TRUE(AreEqual(coalesced_event, *last_touch_event())); |
235 histogram_tester.ExpectBucketCount(kCoalescedCountHistogram, 0, 1); | 270 histogram_tester.ExpectBucketCount(kCoalescedCountHistogram, 0, 1); |
236 histogram_tester.ExpectBucketCount(kCoalescedCountHistogram, 1, 1); | 271 histogram_tester.ExpectBucketCount(kCoalescedCountHistogram, 1, 1); |
237 } | 272 } |
238 | 273 |
239 TEST_P(MainThreadEventQueueTest, BlockingTouch) { | 274 TEST_P(MainThreadEventQueueTest, BlockingTouch) { |
240 base::HistogramTester histogram_tester; | 275 base::HistogramTester histogram_tester; |
241 SyntheticWebTouchEvent kEvents[4]; | 276 SyntheticWebTouchEvent kEvents[4]; |
242 kEvents[0].PressPoint(10, 10); | 277 kEvents[0].PressPoint(10, 10); |
243 kEvents[1].PressPoint(10, 10); | 278 kEvents[1].PressPoint(10, 10); |
244 kEvents[1].MovePoint(0, 20, 20); | 279 kEvents[1].MovePoint(0, 20, 20); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 328 |
294 EXPECT_EQ(2u, event_queue().size()); | 329 EXPECT_EQ(2u, event_queue().size()); |
295 EXPECT_EQ(raf_aligned_input_setting_ != | 330 EXPECT_EQ(raf_aligned_input_setting_ != |
296 (kRafAlignedEnabledMouse | kRafAlignedEnabledTouch), | 331 (kRafAlignedEnabledMouse | kRafAlignedEnabledTouch), |
297 main_task_runner_->HasPendingTask()); | 332 main_task_runner_->HasPendingTask()); |
298 RunPendingTasksWithSimulatedRaf(); | 333 RunPendingTasksWithSimulatedRaf(); |
299 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 334 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
300 EXPECT_EQ(0u, event_queue().size()); | 335 EXPECT_EQ(0u, event_queue().size()); |
301 EXPECT_EQ(2u, handled_events_.size()); | 336 EXPECT_EQ(2u, handled_events_.size()); |
302 { | 337 { |
303 EXPECT_EQ(kWheelEvents[0].size, handled_events_.at(0)->size); | |
304 EXPECT_EQ(kWheelEvents[0].type, handled_events_.at(0)->type); | |
305 const WebMouseWheelEvent* last_wheel_event = | |
306 static_cast<const WebMouseWheelEvent*>(handled_events_.at(0).get()); | |
307 EXPECT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive, | 338 EXPECT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive, |
308 last_wheel_event->dispatchType); | 339 last_wheel_event()->dispatchType); |
309 WebMouseWheelEvent coalesced_event = kWheelEvents[0]; | 340 WebMouseWheelEvent coalesced_event = kWheelEvents[0]; |
310 internal::Coalesce(kWheelEvents[1], &coalesced_event); | 341 internal::Coalesce(kWheelEvents[1], &coalesced_event); |
311 coalesced_event.dispatchType = | 342 coalesced_event.dispatchType = |
312 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 343 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
313 EXPECT_EQ(coalesced_event, *last_wheel_event); | 344 EXPECT_TRUE(AreEqual(coalesced_event, *last_wheel_event())); |
314 } | 345 } |
315 { | 346 { |
316 EXPECT_EQ(kTouchEvents[0].size, handled_events_.at(1)->size); | |
317 EXPECT_EQ(kTouchEvents[0].type, handled_events_.at(1)->type); | |
318 const WebTouchEvent* last_touch_event = | |
319 static_cast<const WebTouchEvent*>(handled_events_.at(1).get()); | |
320 WebTouchEvent coalesced_event = kTouchEvents[0]; | 347 WebTouchEvent coalesced_event = kTouchEvents[0]; |
321 internal::Coalesce(kTouchEvents[1], &coalesced_event); | 348 internal::Coalesce(kTouchEvents[1], &coalesced_event); |
322 coalesced_event.dispatchType = | 349 coalesced_event.dispatchType = |
323 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 350 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
324 EXPECT_EQ(coalesced_event, *last_touch_event); | 351 EXPECT_TRUE(AreEqual(coalesced_event, *last_touch_event())); |
325 } | 352 } |
326 } | 353 } |
327 | 354 |
328 TEST_P(MainThreadEventQueueTest, RafAlignedMouseInput) { | 355 TEST_P(MainThreadEventQueueTest, RafAlignedMouseInput) { |
329 // Don't run the test when we aren't supporting rAF aligned input. | 356 // Don't run the test when we aren't supporting rAF aligned input. |
330 if ((raf_aligned_input_setting_ & kRafAlignedEnabledMouse) == 0) | 357 if ((raf_aligned_input_setting_ & kRafAlignedEnabledMouse) == 0) |
331 return; | 358 return; |
332 | 359 |
333 WebMouseEvent mouseDown = | 360 WebMouseEvent mouseDown = |
334 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseDown, 10, 10, 0); | 361 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseDown, 10, 10, 0); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 kEvents[0].touchStartOrFirstTouchMove = true; | 467 kEvents[0].touchStartOrFirstTouchMove = true; |
441 set_is_flinging(true); | 468 set_is_flinging(true); |
442 set_enable_fling_passive_listener_flag(true); | 469 set_enable_fling_passive_listener_flag(true); |
443 | 470 |
444 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 471 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
445 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 472 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
446 RunPendingTasksWithSimulatedRaf(); | 473 RunPendingTasksWithSimulatedRaf(); |
447 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 474 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
448 EXPECT_EQ(0u, event_queue().size()); | 475 EXPECT_EQ(0u, event_queue().size()); |
449 EXPECT_EQ(1u, handled_events_.size()); | 476 EXPECT_EQ(1u, handled_events_.size()); |
450 EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size); | |
451 EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type); | |
452 EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling()); | 477 EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling()); |
453 const WebTouchEvent* last_touch_event = | |
454 static_cast<const WebTouchEvent*>(handled_events_.at(0).get()); | |
455 kEvents[0].dispatchedDuringFling = true; | 478 kEvents[0].dispatchedDuringFling = true; |
456 kEvents[0].dispatchType = WebInputEvent::ListenersForcedNonBlockingDueToFling; | 479 kEvents[0].dispatchType = WebInputEvent::ListenersForcedNonBlockingDueToFling; |
457 EXPECT_EQ(kEvents[0], *last_touch_event); | 480 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
458 | 481 |
459 kEvents[0].MovePoint(0, 30, 30); | 482 kEvents[0].MovePoint(0, 30, 30); |
460 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 483 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
461 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 484 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
462 EXPECT_EQ((raf_aligned_input_setting_ & kRafAlignedEnabledTouch) == 0, | 485 EXPECT_EQ((raf_aligned_input_setting_ & kRafAlignedEnabledTouch) == 0, |
463 main_task_runner_->HasPendingTask()); | 486 main_task_runner_->HasPendingTask()); |
464 RunPendingTasksWithSimulatedRaf(); | 487 RunPendingTasksWithSimulatedRaf(); |
465 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 488 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
466 EXPECT_EQ(0u, event_queue().size()); | 489 EXPECT_EQ(0u, event_queue().size()); |
467 EXPECT_EQ(2u, handled_events_.size()); | 490 EXPECT_EQ(2u, handled_events_.size()); |
468 EXPECT_EQ(kEvents[0].size, handled_events_.at(1)->size); | |
469 EXPECT_EQ(kEvents[0].type, handled_events_.at(1)->type); | |
470 EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling()); | 491 EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling()); |
471 last_touch_event = | |
472 static_cast<const WebTouchEvent*>(handled_events_.at(1).get()); | |
473 kEvents[0].dispatchedDuringFling = true; | 492 kEvents[0].dispatchedDuringFling = true; |
474 kEvents[0].dispatchType = WebInputEvent::ListenersForcedNonBlockingDueToFling; | 493 kEvents[0].dispatchType = WebInputEvent::ListenersForcedNonBlockingDueToFling; |
475 EXPECT_EQ(kEvents[0], *last_touch_event); | 494 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
476 | 495 |
477 kEvents[0].MovePoint(0, 50, 50); | 496 kEvents[0].MovePoint(0, 50, 50); |
478 kEvents[0].touchStartOrFirstTouchMove = false; | 497 kEvents[0].touchStartOrFirstTouchMove = false; |
479 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 498 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
480 RunPendingTasksWithSimulatedRaf(); | 499 RunPendingTasksWithSimulatedRaf(); |
481 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 500 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
482 EXPECT_EQ(0u, event_queue().size()); | 501 EXPECT_EQ(0u, event_queue().size()); |
483 EXPECT_EQ(3u, handled_events_.size()); | 502 EXPECT_EQ(3u, handled_events_.size()); |
484 EXPECT_EQ(kEvents[0].size, handled_events_.at(2)->size); | |
485 EXPECT_EQ(kEvents[0].type, handled_events_.at(2)->type); | |
486 EXPECT_TRUE(kEvents[0].dispatchedDuringFling); | 503 EXPECT_TRUE(kEvents[0].dispatchedDuringFling); |
487 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 504 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
488 last_touch_event = | 505 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
489 static_cast<const WebTouchEvent*>(handled_events_.at(2).get()); | |
490 EXPECT_EQ(kEvents[0], *last_touch_event); | |
491 | 506 |
492 kEvents[0].ReleasePoint(0); | 507 kEvents[0].ReleasePoint(0); |
493 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 508 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
494 RunPendingTasksWithSimulatedRaf(); | 509 RunPendingTasksWithSimulatedRaf(); |
495 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 510 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
496 EXPECT_EQ(0u, event_queue().size()); | 511 EXPECT_EQ(0u, event_queue().size()); |
497 EXPECT_EQ(4u, handled_events_.size()); | 512 EXPECT_EQ(4u, handled_events_.size()); |
498 EXPECT_EQ(kEvents[0].size, handled_events_.at(3)->size); | |
499 EXPECT_EQ(kEvents[0].type, handled_events_.at(3)->type); | |
500 EXPECT_TRUE(kEvents[0].dispatchedDuringFling); | 513 EXPECT_TRUE(kEvents[0].dispatchedDuringFling); |
501 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 514 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
502 last_touch_event = | 515 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
503 static_cast<const WebTouchEvent*>(handled_events_.at(3).get()); | |
504 EXPECT_EQ(kEvents[0], *last_touch_event); | |
505 } | 516 } |
506 | 517 |
507 TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) { | 518 TEST_P(MainThreadEventQueueTest, BlockingTouchesOutsideFling) { |
508 SyntheticWebTouchEvent kEvents[1]; | 519 SyntheticWebTouchEvent kEvents[1]; |
509 kEvents[0].PressPoint(10, 10); | 520 kEvents[0].PressPoint(10, 10); |
510 kEvents[0].touchStartOrFirstTouchMove = true; | 521 kEvents[0].touchStartOrFirstTouchMove = true; |
511 set_is_flinging(false); | 522 set_is_flinging(false); |
512 set_enable_fling_passive_listener_flag(false); | 523 set_enable_fling_passive_listener_flag(false); |
513 | 524 |
514 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 525 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
515 RunPendingTasksWithSimulatedRaf(); | 526 RunPendingTasksWithSimulatedRaf(); |
516 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 527 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
517 EXPECT_EQ(0u, event_queue().size()); | 528 EXPECT_EQ(0u, event_queue().size()); |
518 EXPECT_EQ(1u, handled_events_.size()); | 529 EXPECT_EQ(1u, handled_events_.size()); |
519 EXPECT_EQ(kEvents[0].size, handled_events_.at(0)->size); | |
520 EXPECT_EQ(kEvents[0].type, handled_events_.at(0)->type); | |
521 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); | 530 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); |
522 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 531 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
523 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 532 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
524 const WebTouchEvent* last_touch_event = | 533 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
525 static_cast<const WebTouchEvent*>(handled_events_.at(0).get()); | |
526 EXPECT_EQ(kEvents[0], *last_touch_event); | |
527 | 534 |
528 set_is_flinging(true); | 535 set_is_flinging(true); |
529 set_enable_fling_passive_listener_flag(false); | 536 set_enable_fling_passive_listener_flag(false); |
530 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 537 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
531 RunPendingTasksWithSimulatedRaf(); | 538 RunPendingTasksWithSimulatedRaf(); |
532 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 539 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
533 EXPECT_EQ(0u, event_queue().size()); | 540 EXPECT_EQ(0u, event_queue().size()); |
534 EXPECT_EQ(2u, handled_events_.size()); | 541 EXPECT_EQ(2u, handled_events_.size()); |
535 EXPECT_EQ(kEvents[0].size, handled_events_.at(1)->size); | |
536 EXPECT_EQ(kEvents[0].type, handled_events_.at(1)->type); | |
537 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); | 542 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); |
538 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 543 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
539 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 544 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
540 last_touch_event = | |
541 static_cast<const WebTouchEvent*>(handled_events_.at(1).get()); | |
542 kEvents[0].dispatchedDuringFling = true; | 545 kEvents[0].dispatchedDuringFling = true; |
543 EXPECT_EQ(kEvents[0], *last_touch_event); | 546 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
544 | 547 |
545 set_is_flinging(false); | 548 set_is_flinging(false); |
546 set_enable_fling_passive_listener_flag(true); | 549 set_enable_fling_passive_listener_flag(true); |
547 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 550 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
548 RunPendingTasksWithSimulatedRaf(); | 551 RunPendingTasksWithSimulatedRaf(); |
549 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 552 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
550 EXPECT_EQ(0u, event_queue().size()); | 553 EXPECT_EQ(0u, event_queue().size()); |
551 EXPECT_EQ(3u, handled_events_.size()); | 554 EXPECT_EQ(3u, handled_events_.size()); |
552 EXPECT_EQ(kEvents[0].size, handled_events_.at(2)->size); | |
553 EXPECT_EQ(kEvents[0].type, handled_events_.at(2)->type); | |
554 EXPECT_TRUE(kEvents[0].dispatchedDuringFling); | 555 EXPECT_TRUE(kEvents[0].dispatchedDuringFling); |
555 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 556 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
556 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 557 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
557 last_touch_event = | |
558 static_cast<const WebTouchEvent*>(handled_events_.at(2).get()); | |
559 kEvents[0].dispatchedDuringFling = false; | 558 kEvents[0].dispatchedDuringFling = false; |
560 EXPECT_EQ(kEvents[0], *last_touch_event); | 559 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
561 | 560 |
562 kEvents[0].MovePoint(0, 30, 30); | 561 kEvents[0].MovePoint(0, 30, 30); |
563 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 562 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
564 RunPendingTasksWithSimulatedRaf(); | 563 RunPendingTasksWithSimulatedRaf(); |
565 EXPECT_FALSE(main_task_runner_->HasPendingTask()); | 564 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
566 EXPECT_EQ(0u, event_queue().size()); | 565 EXPECT_EQ(0u, event_queue().size()); |
567 EXPECT_EQ(4u, handled_events_.size()); | 566 EXPECT_EQ(4u, handled_events_.size()); |
568 EXPECT_EQ(kEvents[0].size, handled_events_.at(3)->size); | |
569 EXPECT_EQ(kEvents[0].type, handled_events_.at(3)->type); | |
570 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); | 567 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); |
571 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 568 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
572 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 569 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
573 last_touch_event = | 570 EXPECT_TRUE(AreEqual(kEvents[0], *last_touch_event())); |
574 static_cast<const WebTouchEvent*>(handled_events_.at(3).get()); | 571 } |
575 EXPECT_EQ(kEvents[0], *last_touch_event); | 572 |
| 573 TEST_P(MainThreadEventQueueTest, ForcedNonBlockingDueToUnresponsiveMainThread) { |
| 574 SyntheticWebTouchEvent kEvent; |
| 575 kEvent.PressPoint(10, 10); |
| 576 kEvent.touchStartOrFirstTouchMove = true; |
| 577 set_enable_non_blocking_due_to_main_thread_responsiveness_flag(true); |
| 578 |
| 579 EXPECT_CALL(renderer_scheduler_, |
| 580 ShouldForceEventsNonBlockingForUnresponsiveMainThread()) |
| 581 .Times(4) |
| 582 .WillRepeatedly(testing::Return(true)); |
| 583 |
| 584 HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 585 RunPendingTasksWithSimulatedRaf(); |
| 586 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 587 EXPECT_EQ(0u, event_queue().size()); |
| 588 EXPECT_EQ(1u, handled_events_.size()); |
| 589 kEvent.dispatchType = |
| 590 WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness; |
| 591 EXPECT_TRUE(AreEqual(kEvent, *last_touch_event())); |
| 592 |
| 593 kEvent.MovePoint(0, 30, 30); |
| 594 HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 595 RunPendingTasksWithSimulatedRaf(); |
| 596 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 597 EXPECT_EQ(0u, event_queue().size()); |
| 598 EXPECT_EQ(2u, handled_events_.size()); |
| 599 kEvent.dispatchType = |
| 600 WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness; |
| 601 EXPECT_TRUE(AreEqual(kEvent, *last_touch_event())); |
| 602 |
| 603 kEvent.MovePoint(0, 50, 50); |
| 604 kEvent.touchStartOrFirstTouchMove = false; |
| 605 HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 606 RunPendingTasksWithSimulatedRaf(); |
| 607 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 608 EXPECT_EQ(0u, event_queue().size()); |
| 609 EXPECT_EQ(3u, handled_events_.size()); |
| 610 kEvent.dispatchType = |
| 611 WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness; |
| 612 EXPECT_TRUE(AreEqual(kEvent, *last_touch_event())); |
| 613 |
| 614 kEvent.ReleasePoint(0); |
| 615 HandleEvent(kEvent, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 616 RunPendingTasksWithSimulatedRaf(); |
| 617 EXPECT_FALSE(main_task_runner_->HasPendingTask()); |
| 618 EXPECT_EQ(0u, event_queue().size()); |
| 619 EXPECT_EQ(4u, handled_events_.size()); |
| 620 kEvent.dispatchType = |
| 621 WebInputEvent::ListenersForcedNonBlockingDueToMainThreadResponsiveness; |
| 622 EXPECT_TRUE(AreEqual(kEvent, *last_touch_event())); |
576 } | 623 } |
577 | 624 |
578 // The boolean parameterized test varies whether rAF aligned input | 625 // The boolean parameterized test varies whether rAF aligned input |
579 // is enabled or not. | 626 // is enabled or not. |
580 INSTANTIATE_TEST_CASE_P( | 627 INSTANTIATE_TEST_CASE_P( |
581 MainThreadEventQueueTests, | 628 MainThreadEventQueueTests, |
582 MainThreadEventQueueTest, | 629 MainThreadEventQueueTest, |
583 testing::Range(0u, | 630 testing::Range(0u, |
584 (kRafAlignedEnabledTouch | kRafAlignedEnabledMouse) + 1)); | 631 (kRafAlignedEnabledTouch | kRafAlignedEnabledMouse) + 1)); |
585 | 632 |
586 } // namespace content | 633 } // namespace content |
OLD | NEW |