Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / render_widget_host_latency_tracker_unittest.cc
blobebb3839c39d85cdf3003efb38fb79b73ad354d5e
1 // Copyright 2014 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.
5 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker.h"
6 #include "content/common/input/synthetic_web_input_event_builders.h"
7 #include "content/public/browser/native_web_keyboard_event.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using blink::WebInputEvent;
12 namespace content {
13 namespace {
15 const int kTestRoutingId = 3;
16 const int kTestProcessId = 1;
18 } // namespace
20 TEST(RenderWidgetHostLatencyTrackerTest, Basic) {
21 RenderWidgetHostLatencyTracker tracker;
22 tracker.Initialize(kTestRoutingId, kTestProcessId);
25 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
26 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen);
27 scroll.timeStampSeconds =
28 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
29 ui::LatencyInfo scroll_latency;
30 tracker.OnInputEvent(scroll, &scroll_latency);
31 EXPECT_TRUE(
32 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
33 tracker.latency_component_id(), nullptr));
34 EXPECT_TRUE(
35 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
36 0, nullptr));
37 EXPECT_EQ(1U, scroll_latency.input_coordinates_size());
41 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
42 blink::WebMouseWheelEvent::PhaseChanged);
43 wheel.timeStampSeconds =
44 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
45 ui::LatencyInfo wheel_latency;
46 tracker.OnInputEvent(wheel, &wheel_latency);
47 EXPECT_TRUE(
48 wheel_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
49 tracker.latency_component_id(), nullptr));
50 EXPECT_TRUE(
51 wheel_latency.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
52 0, nullptr));
53 EXPECT_EQ(1U, wheel_latency.input_coordinates_size());
57 SyntheticWebTouchEvent touch;
58 touch.PressPoint(0, 0);
59 touch.PressPoint(1, 1);
60 ui::LatencyInfo touch_latency;
61 tracker.OnInputEvent(touch, &touch_latency);
62 EXPECT_TRUE(
63 touch_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
64 tracker.latency_component_id(), nullptr));
65 EXPECT_TRUE(
66 touch_latency.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
67 0, nullptr));
68 EXPECT_EQ(2U, touch_latency.input_coordinates_size());
72 TEST(RenderWidgetHostLatencyTrackerTest,
73 LatencyTerminatedOnAckIfRenderingNotScheduled) {
74 RenderWidgetHostLatencyTracker tracker;
75 tracker.Initialize(kTestRoutingId, kTestProcessId);
78 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollBegin(5.f, -5.f);
79 ui::LatencyInfo scroll_latency;
80 tracker.OnInputEvent(scroll, &scroll_latency);
81 tracker.OnInputEventAck(scroll, &scroll_latency);
82 EXPECT_TRUE(scroll_latency.FindLatency(
83 ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT, 0, nullptr));
84 EXPECT_TRUE(scroll_latency.terminated());
88 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
89 blink::WebMouseWheelEvent::PhaseChanged);
90 ui::LatencyInfo wheel_latency;
91 tracker.OnInputEvent(wheel, &wheel_latency);
92 tracker.OnInputEventAck(wheel, &wheel_latency);
93 EXPECT_TRUE(wheel_latency.FindLatency(
94 ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_WHEEL_COMPONENT, 0, nullptr));
95 EXPECT_TRUE(wheel_latency.terminated());
99 SyntheticWebTouchEvent touch;
100 touch.PressPoint(0, 0);
101 ui::LatencyInfo touch_latency;
102 tracker.OnInputEvent(touch, &touch_latency);
103 tracker.OnInputEventAck(touch, &touch_latency);
104 EXPECT_TRUE(touch_latency.FindLatency(
105 ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT, 0, nullptr));
106 EXPECT_TRUE(touch_latency.terminated());
110 auto mouse_move = SyntheticWebMouseEventBuilder::Build(
111 blink::WebMouseEvent::MouseMove);
112 ui::LatencyInfo mouse_latency;
113 tracker.OnInputEvent(mouse_move, &mouse_latency);
114 tracker.OnInputEventAck(mouse_move, &mouse_latency);
115 EXPECT_TRUE(mouse_latency.FindLatency(
116 ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT, 0, nullptr));
117 EXPECT_TRUE(mouse_latency.terminated());
121 auto key_event = SyntheticWebKeyboardEventBuilder::Build(
122 blink::WebKeyboardEvent::Char);
123 ui::LatencyInfo key_latency;
124 tracker.OnInputEvent(key_event, &key_latency);
125 tracker.OnInputEventAck(key_event, &key_latency);
126 EXPECT_TRUE(key_latency.FindLatency(
127 ui::INPUT_EVENT_LATENCY_TERMINATED_KEYBOARD_COMPONENT, 0, nullptr));
128 EXPECT_TRUE(key_latency.terminated());
132 TEST(RenderWidgetHostLatencyTrackerTest, InputCoordinatesPopulated) {
133 RenderWidgetHostLatencyTracker tracker;
134 tracker.Initialize(kTestRoutingId, kTestProcessId);
137 auto event = SyntheticWebMouseWheelEventBuilder::Build(-5, 0, 0, true);
138 event.x = 100;
139 event.y = 200;
140 ui::LatencyInfo latency_info;
141 tracker.OnInputEvent(event, &latency_info);
142 EXPECT_EQ(1u, latency_info.input_coordinates_size());
143 EXPECT_EQ(100, latency_info.input_coordinates()[0].x);
144 EXPECT_EQ(200, latency_info.input_coordinates()[0].y);
148 auto event = SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove);
149 event.x = 300;
150 event.y = 400;
151 ui::LatencyInfo latency_info;
152 tracker.OnInputEvent(event, &latency_info);
153 EXPECT_EQ(1u, latency_info.input_coordinates_size());
154 EXPECT_EQ(300, latency_info.input_coordinates()[0].x);
155 EXPECT_EQ(400, latency_info.input_coordinates()[0].y);
159 auto event = SyntheticWebGestureEventBuilder::Build(
160 WebInputEvent::GestureScrollBegin, blink::WebGestureDeviceTouchscreen);
161 event.x = 500;
162 event.y = 600;
163 ui::LatencyInfo latency_info;
164 tracker.OnInputEvent(event, &latency_info);
165 EXPECT_EQ(1u, latency_info.input_coordinates_size());
166 EXPECT_EQ(500, latency_info.input_coordinates()[0].x);
167 EXPECT_EQ(600, latency_info.input_coordinates()[0].y);
171 SyntheticWebTouchEvent event;
172 event.PressPoint(700, 800);
173 event.PressPoint(900, 1000);
174 event.PressPoint(1100, 1200); // LatencyInfo only holds two coordinates.
175 ui::LatencyInfo latency_info;
176 tracker.OnInputEvent(event, &latency_info);
177 EXPECT_EQ(2u, latency_info.input_coordinates_size());
178 EXPECT_EQ(700, latency_info.input_coordinates()[0].x);
179 EXPECT_EQ(800, latency_info.input_coordinates()[0].y);
180 EXPECT_EQ(900, latency_info.input_coordinates()[1].x);
181 EXPECT_EQ(1000, latency_info.input_coordinates()[1].y);
185 NativeWebKeyboardEvent event;
186 event.type = blink::WebKeyboardEvent::KeyDown;
187 ui::LatencyInfo latency_info;
188 tracker.OnInputEvent(event, &latency_info);
189 EXPECT_EQ(0u, latency_info.input_coordinates_size());
193 TEST(RenderWidgetHostLatencyTrackerTest, ScrollLatency) {
194 RenderWidgetHostLatencyTracker tracker;
195 tracker.Initialize(kTestRoutingId, kTestProcessId);
197 auto scroll_begin = SyntheticWebGestureEventBuilder::BuildScrollBegin(5, -5);
198 ui::LatencyInfo scroll_latency;
199 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
201 tracker.OnInputEvent(scroll_begin, &scroll_latency);
202 EXPECT_TRUE(
203 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
204 tracker.latency_component_id(), nullptr));
205 EXPECT_EQ(2U, scroll_latency.latency_components().size());
207 // The first GestureScrollUpdate should be provided with
208 // INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT.
209 auto first_scroll_update = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
210 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen);
211 scroll_latency = ui::LatencyInfo();
212 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
214 tracker.OnInputEvent(first_scroll_update, &scroll_latency);
215 EXPECT_TRUE(
216 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
217 tracker.latency_component_id(), nullptr));
218 EXPECT_TRUE(scroll_latency.FindLatency(
219 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
220 tracker.latency_component_id(), nullptr));
221 EXPECT_FALSE(scroll_latency.FindLatency(
222 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
223 tracker.latency_component_id(), nullptr));
224 EXPECT_EQ(3U, scroll_latency.latency_components().size());
226 // Subseqeunt GestureScrollUpdates should be provided with
227 // INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT.
228 auto scroll_update = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
229 -5.f, 5.f, 0, blink::WebGestureDeviceTouchscreen);
230 scroll_latency = ui::LatencyInfo();
231 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
233 tracker.OnInputEvent(scroll_update, &scroll_latency);
234 EXPECT_TRUE(
235 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
236 tracker.latency_component_id(), nullptr));
237 EXPECT_FALSE(scroll_latency.FindLatency(
238 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
239 tracker.latency_component_id(), nullptr));
240 EXPECT_TRUE(scroll_latency.FindLatency(
241 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
242 tracker.latency_component_id(), nullptr));
243 EXPECT_EQ(3U, scroll_latency.latency_components().size());
246 } // namespace content