| 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/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/common/input/synthetic_web_input_event_builders.h" | 14 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 15 #include "content/renderer/input/main_thread_event_queue.h" | 15 #include "content/renderer/input/main_thread_event_queue.h" |
| 16 #include "content/renderer/render_thread_impl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/scheduler/test/mock_renderer_schedu
ler.h" |
| 17 | 19 |
| 18 using blink::WebInputEvent; | 20 using blink::WebInputEvent; |
| 19 using blink::WebMouseEvent; | 21 using blink::WebMouseEvent; |
| 20 using blink::WebMouseWheelEvent; | 22 using blink::WebMouseWheelEvent; |
| 21 using blink::WebTouchEvent; | 23 using blink::WebTouchEvent; |
| 22 | 24 |
| 23 namespace blink { | 25 namespace blink { |
| 24 bool operator==(const WebMouseWheelEvent& lhs, const WebMouseWheelEvent& rhs) { | 26 bool operator==(const WebMouseWheelEvent& lhs, const WebMouseWheelEvent& rhs) { |
| 25 return memcmp(&lhs, &rhs, lhs.size) == 0; | 27 return memcmp(&lhs, &rhs, lhs.size) == 0; |
| 26 } | 28 } |
| 27 | 29 |
| 28 bool operator==(const WebTouchEvent& lhs, const WebTouchEvent& rhs) { | 30 bool operator==(const WebTouchEvent& lhs, const WebTouchEvent& rhs) { |
| 29 return memcmp(&lhs, &rhs, lhs.size) == 0; | 31 return memcmp(&lhs, &rhs, lhs.size) == 0; |
| 30 } | 32 } |
| 31 } // namespace blink | 33 } // namespace blink |
| 32 | 34 |
| 33 namespace content { | 35 namespace content { |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 const int kTestRoutingID = 13; | 38 const int kTestRoutingID = 13; |
| 37 } | 39 } |
| 38 | 40 |
| 39 class MainThreadEventQueueTest : public testing::Test, | 41 class MainThreadEventQueueTest : public testing::Test, |
| 40 public MainThreadEventQueueClient { | 42 public MainThreadEventQueueClient { |
| 41 public: | 43 public: |
| 42 MainThreadEventQueueTest() | 44 MainThreadEventQueueTest() |
| 43 : main_task_runner_(new base::TestSimpleTaskRunner()), | 45 : main_task_runner_(new base::TestSimpleTaskRunner()), |
| 44 queue_( | 46 queue_(new MainThreadEventQueue(kTestRoutingID, |
| 45 new MainThreadEventQueue(kTestRoutingID, this, main_task_runner_)) { | 47 this, |
| 46 } | 48 main_task_runner_, |
| 49 &renderer_scheduler_)) {} |
| 47 | 50 |
| 48 void HandleEventOnMainThread(int routing_id, | 51 void HandleEventOnMainThread(int routing_id, |
| 49 const blink::WebInputEvent* event, | 52 const blink::WebInputEvent* event, |
| 50 const ui::LatencyInfo& latency, | 53 const ui::LatencyInfo& latency, |
| 51 InputEventDispatchType type) override { | 54 InputEventDispatchType type) override { |
| 52 EXPECT_EQ(kTestRoutingID, routing_id); | 55 EXPECT_EQ(kTestRoutingID, routing_id); |
| 53 handled_events_.push_back(ui::WebInputEventTraits::Clone(*event)); | 56 handled_events_.push_back(ui::WebInputEventTraits::Clone(*event)); |
| 54 queue_->EventHandled(event->type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 57 queue_->EventHandled(event->type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 55 } | 58 } |
| 56 | 59 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 bool last_touch_start_forced_nonblocking_due_to_fling() { | 80 bool last_touch_start_forced_nonblocking_due_to_fling() { |
| 78 return queue_->last_touch_start_forced_nonblocking_due_to_fling_; | 81 return queue_->last_touch_start_forced_nonblocking_due_to_fling_; |
| 79 } | 82 } |
| 80 | 83 |
| 81 void set_enable_fling_passive_listener_flag(bool enable_flag) { | 84 void set_enable_fling_passive_listener_flag(bool enable_flag) { |
| 82 queue_->enable_fling_passive_listener_flag_ = enable_flag; | 85 queue_->enable_fling_passive_listener_flag_ = enable_flag; |
| 83 } | 86 } |
| 84 | 87 |
| 85 protected: | 88 protected: |
| 86 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; | 89 scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; |
| 90 blink::scheduler::MockRendererScheduler renderer_scheduler_; |
| 87 scoped_refptr<MainThreadEventQueue> queue_; | 91 scoped_refptr<MainThreadEventQueue> queue_; |
| 88 std::vector<ui::ScopedWebInputEvent> handled_events_; | 92 std::vector<ui::ScopedWebInputEvent> handled_events_; |
| 89 std::vector<uint32_t> additional_acked_events_; | 93 std::vector<uint32_t> additional_acked_events_; |
| 90 }; | 94 }; |
| 91 | 95 |
| 92 TEST_F(MainThreadEventQueueTest, NonBlockingWheel) { | 96 TEST_F(MainThreadEventQueueTest, NonBlockingWheel) { |
| 93 WebMouseWheelEvent kEvents[4] = { | 97 WebMouseWheelEvent kEvents[4] = { |
| 94 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), | 98 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), |
| 95 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), | 99 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), |
| 96 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), | 100 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 189 |
| 186 TEST_F(MainThreadEventQueueTest, BlockingTouch) { | 190 TEST_F(MainThreadEventQueueTest, BlockingTouch) { |
| 187 SyntheticWebTouchEvent kEvents[4]; | 191 SyntheticWebTouchEvent kEvents[4]; |
| 188 kEvents[0].PressPoint(10, 10); | 192 kEvents[0].PressPoint(10, 10); |
| 189 kEvents[1].PressPoint(10, 10); | 193 kEvents[1].PressPoint(10, 10); |
| 190 kEvents[1].MovePoint(0, 20, 20); | 194 kEvents[1].MovePoint(0, 20, 20); |
| 191 kEvents[2].PressPoint(10, 10); | 195 kEvents[2].PressPoint(10, 10); |
| 192 kEvents[2].MovePoint(0, 30, 30); | 196 kEvents[2].MovePoint(0, 30, 30); |
| 193 kEvents[3].PressPoint(10, 10); | 197 kEvents[3].PressPoint(10, 10); |
| 194 kEvents[3].MovePoint(0, 35, 35); | 198 kEvents[3].MovePoint(0, 35, 35); |
| 199 |
| 200 EXPECT_CALL(renderer_scheduler_, DidHandleInputEventOnMainThread(testing::_)) |
| 201 .Times(2); |
| 195 // Ensure that coalescing takes place. | 202 // Ensure that coalescing takes place. |
| 196 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING); | 203 HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING); |
| 197 HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 204 HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 198 HandleEvent(kEvents[2], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 205 HandleEvent(kEvents[2], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 199 HandleEvent(kEvents[3], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 206 HandleEvent(kEvents[3], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 200 | 207 |
| 201 EXPECT_EQ(2u, event_queue().size()); | 208 EXPECT_EQ(2u, event_queue().size()); |
| 202 EXPECT_TRUE(main_task_runner_->HasPendingTask()); | 209 EXPECT_TRUE(main_task_runner_->HasPendingTask()); |
| 203 main_task_runner_->RunUntilIdle(); | 210 main_task_runner_->RunUntilIdle(); |
| 204 EXPECT_EQ(0u, event_queue().size()); | 211 EXPECT_EQ(0u, event_queue().size()); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 EXPECT_EQ(kEvents[0].type, handled_events_.at(3)->type); | 397 EXPECT_EQ(kEvents[0].type, handled_events_.at(3)->type); |
| 391 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); | 398 EXPECT_FALSE(kEvents[0].dispatchedDuringFling); |
| 392 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); | 399 EXPECT_EQ(kEvents[0].dispatchType, WebInputEvent::Blocking); |
| 393 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); | 400 EXPECT_FALSE(last_touch_start_forced_nonblocking_due_to_fling()); |
| 394 last_touch_event = | 401 last_touch_event = |
| 395 static_cast<const WebTouchEvent*>(handled_events_.at(3).get()); | 402 static_cast<const WebTouchEvent*>(handled_events_.at(3).get()); |
| 396 EXPECT_EQ(kEvents[0], *last_touch_event); | 403 EXPECT_EQ(kEvents[0], *last_touch_event); |
| 397 } | 404 } |
| 398 | 405 |
| 399 } // namespace content | 406 } // namespace content |
| OLD | NEW |