Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: content/renderer/input/non_blocking_event_queue_unittest.cc

Issue 1631963002: Plumb firing passive event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_passive_listeners_2a
Patch Set: Rename to non-blocking and rebase against underlying changes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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);
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
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(WebInputEventQueue<
64 MouseWheelEventWithLatencyInfo>::State::ITEM_NOT_PENDING,
65 wheel_event_queue().state());
66 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo());
67 ASSERT_EQ(
68 WebInputEventQueue<MouseWheelEventWithLatencyInfo>::State::ITEM_PENDING,
69 wheel_event_queue().state());
70 queue_.HandleEvent(&kEvents[1], ui::LatencyInfo());
71 ASSERT_EQ(kEvents[0].size, last_event_.size());
72 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[0], kEvents[0].size) == 0);
73 queue_.EventHandled(blink::WebInputEvent::MouseWheel);
74 ASSERT_EQ(kEvents[1].size, last_event_.size());
75 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[1], kEvents[1].size) == 0);
76 ASSERT_EQ(
77 WebInputEventQueue<MouseWheelEventWithLatencyInfo>::State::ITEM_PENDING,
78 wheel_event_queue().state());
79 queue_.EventHandled(blink::WebInputEvent::MouseWheel);
80 ASSERT_EQ(WebInputEventQueue<
81 MouseWheelEventWithLatencyInfo>::State::ITEM_NOT_PENDING,
82 wheel_event_queue().state());
83
84 // Ensure that coalescing takes place.
85 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo());
86 queue_.HandleEvent(&kEvents[2], ui::LatencyInfo());
87 queue_.HandleEvent(&kEvents[3], ui::LatencyInfo());
88 ASSERT_EQ(1u, wheel_event_queue().size());
89 ASSERT_EQ(
90 WebInputEventQueue<MouseWheelEventWithLatencyInfo>::State::ITEM_PENDING,
91 wheel_event_queue().state());
92 }
93
94 TEST_F(NonBlockingEventQueueTest, NonBlockingTouch) {
95 SyntheticWebTouchEvent kEvents[4];
96 kEvents[0].PressPoint(10, 10);
97 kEvents[1].PressPoint(10, 10);
98 kEvents[1].modifiers = 1;
99 kEvents[1].MovePoint(0, 20, 20);
100 kEvents[2].PressPoint(10, 10);
101 kEvents[2].MovePoint(0, 30, 30);
102 kEvents[3].PressPoint(10, 10);
103 kEvents[3].MovePoint(0, 35, 35);
104
105 ASSERT_EQ(
106 WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_NOT_PENDING,
107 touch_event_queue().state());
108 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo());
109 ASSERT_EQ(WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_PENDING,
110 touch_event_queue().state());
111 queue_.HandleEvent(&kEvents[1], ui::LatencyInfo());
112 ASSERT_EQ(kEvents[0].size, last_event_.size());
113 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[0], kEvents[0].size) == 0);
114 queue_.EventHandled(blink::WebInputEvent::TouchStart);
115 ASSERT_EQ(kEvents[1].size, last_event_.size());
116 ASSERT_TRUE(memcmp(&last_event_[0], &kEvents[1], kEvents[1].size) == 0);
117 ASSERT_EQ(WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_PENDING,
118 touch_event_queue().state());
119 queue_.EventHandled(blink::WebInputEvent::TouchMove);
120 ASSERT_EQ(
121 WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_NOT_PENDING,
122 touch_event_queue().state());
123
124 // Ensure that coalescing takes place.
125 queue_.HandleEvent(&kEvents[0], ui::LatencyInfo());
126 queue_.HandleEvent(&kEvents[2], ui::LatencyInfo());
127 queue_.HandleEvent(&kEvents[3], ui::LatencyInfo());
128 ASSERT_EQ(1u, touch_event_queue().size());
129 ASSERT_EQ(WebInputEventQueue<TouchEventWithLatencyInfo>::State::ITEM_PENDING,
130 touch_event_queue().state());
131 }
132
133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698