OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stddef.h> |
| 6 |
| 7 #include <new> |
| 8 #include <utility> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "build/build_config.h" |
| 13 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 14 #include "content/renderer/input/non_blocking_event_queue.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 using blink::WebInputEvent; |
| 18 using blink::WebMouseEvent; |
| 19 using blink::WebMouseWheelEvent; |
| 20 using blink::WebTouchEvent; |
| 21 |
| 22 namespace content { |
| 23 namespace { |
| 24 |
| 25 const int kTestRoutingID = 13; |
| 26 } |
| 27 |
| 28 class NonBlockingEventQueueTest : public testing::Test, |
| 29 public NonBlockingEventQueueClient { |
| 30 public: |
| 31 NonBlockingEventQueueTest() : queue_(kTestRoutingID, this) {} |
| 32 |
| 33 void SendNonBlockingEvent(int routing_id, |
| 34 const blink::WebInputEvent* event, |
| 35 const ui::LatencyInfo& latency) override { |
| 36 ASSERT_EQ(kTestRoutingID, routing_id); |
| 37 const unsigned char* eventPtr = |
| 38 reinterpret_cast<const unsigned char*>(event); |
| 39 last_event_.assign(eventPtr, eventPtr + event->size); |
| 40 } |
| 41 |
| 42 WebInputEventQueue<MouseWheelEventWithLatencyInfo>& wheel_event_queue() { |
| 43 return queue_.wheel_events_; |
| 44 } |
| 45 |
| 46 WebInputEventQueue<TouchEventWithLatencyInfo>& touch_event_queue() { |
| 47 return queue_.touch_events_; |
| 48 } |
| 49 |
| 50 protected: |
| 51 NonBlockingEventQueue queue_; |
| 52 std::vector<unsigned char> last_event_; |
| 53 }; |
| 54 |
| 55 TEST_F(NonBlockingEventQueueTest, NonBlockingWheel) { |
| 56 WebMouseWheelEvent kEvents[4] = { |
| 57 SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), |
| 58 SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), |
| 59 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
| 60 SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
| 61 }; |
| 62 |
| 63 ASSERT_EQ(WebInputEventQueueState::ITEM_NOT_PENDING, |
| 64 wheel_event_queue().state()); |
| 65 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| 66 ASSERT_EQ(WebInputEventQueueState::ITEM_PENDING, wheel_event_queue().state()); |
| 67 queue_.HandleEvent(&kEvents[1], ui::LatencyInfo()); |
| 68 ASSERT_EQ(kEvents[0].size, last_event_.size()); |
| 69 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[0], kEvents[0].size) == 0); |
| 70 queue_.EventHandled(blink::WebInputEvent::MouseWheel); |
| 71 ASSERT_EQ(kEvents[1].size, last_event_.size()); |
| 72 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[1], kEvents[1].size) == 0); |
| 73 ASSERT_EQ(WebInputEventQueueState::ITEM_PENDING, wheel_event_queue().state()); |
| 74 queue_.EventHandled(blink::WebInputEvent::MouseWheel); |
| 75 ASSERT_EQ(WebInputEventQueueState::ITEM_NOT_PENDING, |
| 76 wheel_event_queue().state()); |
| 77 |
| 78 // Ensure that coalescing takes place. |
| 79 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| 80 queue_.HandleEvent(&kEvents[2], ui::LatencyInfo()); |
| 81 queue_.HandleEvent(&kEvents[3], ui::LatencyInfo()); |
| 82 ASSERT_EQ(1u, wheel_event_queue().size()); |
| 83 ASSERT_EQ(WebInputEventQueueState::ITEM_PENDING, wheel_event_queue().state()); |
| 84 } |
| 85 |
| 86 TEST_F(NonBlockingEventQueueTest, NonBlockingTouch) { |
| 87 SyntheticWebTouchEvent kEvents[4]; |
| 88 kEvents[0].PressPoint(10, 10); |
| 89 kEvents[1].PressPoint(10, 10); |
| 90 kEvents[1].modifiers = 1; |
| 91 kEvents[1].MovePoint(0, 20, 20); |
| 92 kEvents[2].PressPoint(10, 10); |
| 93 kEvents[2].MovePoint(0, 30, 30); |
| 94 kEvents[3].PressPoint(10, 10); |
| 95 kEvents[3].MovePoint(0, 35, 35); |
| 96 |
| 97 ASSERT_EQ(WebInputEventQueueState::ITEM_NOT_PENDING, |
| 98 touch_event_queue().state()); |
| 99 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| 100 ASSERT_EQ(WebInputEventQueueState::ITEM_PENDING, touch_event_queue().state()); |
| 101 queue_.HandleEvent(&kEvents[1], ui::LatencyInfo()); |
| 102 ASSERT_EQ(kEvents[0].size, last_event_.size()); |
| 103 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[0], kEvents[0].size) == 0); |
| 104 queue_.EventHandled(blink::WebInputEvent::TouchStart); |
| 105 ASSERT_EQ(kEvents[1].size, last_event_.size()); |
| 106 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[1], kEvents[1].size) == 0); |
| 107 ASSERT_EQ(WebInputEventQueueState::ITEM_PENDING, touch_event_queue().state()); |
| 108 queue_.EventHandled(blink::WebInputEvent::TouchMove); |
| 109 ASSERT_EQ(WebInputEventQueueState::ITEM_NOT_PENDING, |
| 110 touch_event_queue().state()); |
| 111 |
| 112 // Ensure that coalescing takes place. |
| 113 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| 114 queue_.HandleEvent(&kEvents[2], ui::LatencyInfo()); |
| 115 queue_.HandleEvent(&kEvents[3], ui::LatencyInfo()); |
| 116 ASSERT_EQ(1u, touch_event_queue().size()); |
| 117 ASSERT_EQ(WebInputEventQueueState::ITEM_PENDING, touch_event_queue().state()); |
| 118 } |
| 119 |
| 120 } // namespace content |
OLD | NEW |