Chromium Code Reviews| Index: content/renderer/input/non_blocking_event_queue_unittest.cc |
| diff --git a/content/renderer/input/non_blocking_event_queue_unittest.cc b/content/renderer/input/non_blocking_event_queue_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..283c50a6f4cff83f90293b1392a975a7609e46d6 |
| --- /dev/null |
| +++ b/content/renderer/input/non_blocking_event_queue_unittest.cc |
| @@ -0,0 +1,133 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <stddef.h> |
| + |
| +#include <new> |
| +#include <utility> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "build/build_config.h" |
| +#include "content/common/input/synthetic_web_input_event_builders.h" |
| +#include "content/renderer/input/non_blocking_event_queue.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using blink::WebInputEvent; |
| +using blink::WebMouseEvent; |
| +using blink::WebMouseWheelEvent; |
| +using blink::WebTouchEvent; |
| + |
| +namespace content { |
| +namespace { |
| + |
| +const int kTestRoutingID = 13; |
| +} |
| + |
| +class NonBlockingEventQueueTest : public testing::Test, |
| + public NonBlockingEventQueueClient { |
| + public: |
| + NonBlockingEventQueueTest() : queue_(kTestRoutingID, this) {} |
| + |
| + void SendNonBlockingEvent(int routing_id, |
| + const blink::WebInputEvent* event, |
| + const ui::LatencyInfo& latency) override { |
| + ASSERT_EQ(kTestRoutingID, routing_id); |
| + const unsigned char* eventPtr = |
| + reinterpret_cast<const unsigned char*>(event); |
| + last_event_.assign(eventPtr, eventPtr + event->size); |
|
tdresser
2016/02/08 17:51:32
Why not just store the WebInputEvent?
dtapuska
2016/02/09 19:40:12
WebInputEvent ctor is protected and the struct is
|
| + } |
| + |
| + WebInputEventQueue<MouseWheelEventWithLatencyInfo>& wheel_event_queue() { |
| + return queue_.wheel_events_; |
| + } |
| + |
| + WebInputEventQueue<TouchEventWithLatencyInfo>& touch_event_queue() { |
| + return queue_.touch_events_; |
| + } |
| + |
| + protected: |
| + NonBlockingEventQueue queue_; |
| + std::vector<unsigned char> last_event_; |
| +}; |
| + |
| +TEST_F(NonBlockingEventQueueTest, NonBlockingWheel) { |
| + WebMouseWheelEvent kEvents[4] = { |
| + SyntheticWebMouseWheelEventBuilder::Build(10, 10, 0, 53, 0, false), |
| + SyntheticWebMouseWheelEventBuilder::Build(20, 20, 0, 53, 0, false), |
| + SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
| + SyntheticWebMouseWheelEventBuilder::Build(30, 30, 0, 53, 1, false), |
| + }; |
| + |
| + ASSERT_EQ(WebInputEventQueue< |
| + MouseWheelEventWithLatencyInfo>::State::ITEM_NOT_PENDING, |
| + wheel_event_queue().state()); |
| + queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| + ASSERT_EQ( |
| + WebInputEventQueue<MouseWheelEventWithLatencyInfo>::State::ITEM_PENDING, |
| + wheel_event_queue().state()); |
| + queue_.HandleEvent(&kEvents[1], ui::LatencyInfo()); |
| + ASSERT_EQ(kEvents[0].size, last_event_.size()); |
| + ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[0], kEvents[0].size) == 0); |
| + queue_.EventHandled(blink::WebInputEvent::MouseWheel); |
| + ASSERT_EQ(kEvents[1].size, last_event_.size()); |
| + ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[1], kEvents[1].size) == 0); |
| + ASSERT_EQ( |
| + WebInputEventQueue<MouseWheelEventWithLatencyInfo>::State::ITEM_PENDING, |
| + wheel_event_queue().state()); |
| + queue_.EventHandled(blink::WebInputEvent::MouseWheel); |
| + ASSERT_EQ(WebInputEventQueue< |
| + MouseWheelEventWithLatencyInfo>::State::ITEM_NOT_PENDING, |
| + wheel_event_queue().state()); |
| + |
| + // Ensure that coalescing takes place. |
| + queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| + queue_.HandleEvent(&kEvents[2], ui::LatencyInfo()); |
| + queue_.HandleEvent(&kEvents[3], ui::LatencyInfo()); |
| + ASSERT_EQ(1u, wheel_event_queue().size()); |
| + ASSERT_EQ( |
| + WebInputEventQueue<MouseWheelEventWithLatencyInfo>::State::ITEM_PENDING, |
| + wheel_event_queue().state()); |
| +} |
| + |
| +TEST_F(NonBlockingEventQueueTest, NonBlockingTouch) { |
| + SyntheticWebTouchEvent kEvents[4]; |
| + kEvents[0].PressPoint(10, 10); |
| + kEvents[1].PressPoint(10, 10); |
| + kEvents[1].modifiers = 1; |
| + kEvents[1].MovePoint(0, 20, 20); |
| + kEvents[2].PressPoint(10, 10); |
| + kEvents[2].MovePoint(0, 30, 30); |
| + kEvents[3].PressPoint(10, 10); |
| + kEvents[3].MovePoint(0, 35, 35); |
| + |
| + ASSERT_EQ( |
| + WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_NOT_PENDING, |
| + touch_event_queue().state()); |
| + queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| + ASSERT_EQ(WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_PENDING, |
| + touch_event_queue().state()); |
| + queue_.HandleEvent(&kEvents[1], ui::LatencyInfo()); |
| + ASSERT_EQ(kEvents[0].size, last_event_.size()); |
| + ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[0], kEvents[0].size) == 0); |
| + queue_.EventHandled(blink::WebInputEvent::TouchStart); |
| + ASSERT_EQ(kEvents[1].size, last_event_.size()); |
| + ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[1], kEvents[1].size) == 0); |
| + ASSERT_EQ(WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_PENDING, |
| + touch_event_queue().state()); |
| + queue_.EventHandled(blink::WebInputEvent::TouchMove); |
| + ASSERT_EQ( |
| + WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_NOT_PENDING, |
| + touch_event_queue().state()); |
| + |
| + // Ensure that coalescing takes place. |
| + queue_.HandleEvent(&kEvents[0], ui::LatencyInfo()); |
| + queue_.HandleEvent(&kEvents[2], ui::LatencyInfo()); |
| + queue_.HandleEvent(&kEvents[3], ui::LatencyInfo()); |
| + ASSERT_EQ(1u, touch_event_queue().size()); |
| + ASSERT_EQ(WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_PENDING, |
| + touch_event_queue().state()); |
| +} |
| + |
| +} // namespace content |