Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / renderer_host / input / render_widget_host_latency_tracker_unittest.cc
blob3db83653a41e308dc60f9f3b44f48c34e2000721
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_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 TEST(RenderWidgetHostLatencyTrackerTest, InputCoordinatesPopulated) {
111 RenderWidgetHostLatencyTracker tracker;
112 tracker.Initialize(kTestRoutingId, kTestProcessId);
115 auto event = SyntheticWebMouseWheelEventBuilder::Build(-5, 0, 0, true);
116 event.x = 100;
117 event.y = 200;
118 ui::LatencyInfo latency_info;
119 tracker.OnInputEvent(event, &latency_info);
120 EXPECT_EQ(1u, latency_info.input_coordinates_size);
121 EXPECT_EQ(100, latency_info.input_coordinates[0].x);
122 EXPECT_EQ(200, latency_info.input_coordinates[0].y);
126 auto event = SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove);
127 event.x = 300;
128 event.y = 400;
129 ui::LatencyInfo latency_info;
130 tracker.OnInputEvent(event, &latency_info);
131 EXPECT_EQ(1u, latency_info.input_coordinates_size);
132 EXPECT_EQ(300, latency_info.input_coordinates[0].x);
133 EXPECT_EQ(400, latency_info.input_coordinates[0].y);
137 auto event = SyntheticWebGestureEventBuilder::Build(
138 WebInputEvent::GestureScrollBegin, blink::WebGestureDeviceTouchscreen);
139 event.x = 500;
140 event.y = 600;
141 ui::LatencyInfo latency_info;
142 tracker.OnInputEvent(event, &latency_info);
143 EXPECT_EQ(1u, latency_info.input_coordinates_size);
144 EXPECT_EQ(500, latency_info.input_coordinates[0].x);
145 EXPECT_EQ(600, latency_info.input_coordinates[0].y);
149 SyntheticWebTouchEvent event;
150 event.PressPoint(700, 800);
151 event.PressPoint(900, 1000);
152 event.PressPoint(1100, 1200); // LatencyInfo only holds two coordinates.
153 ui::LatencyInfo latency_info;
154 tracker.OnInputEvent(event, &latency_info);
155 EXPECT_EQ(2u, latency_info.input_coordinates_size);
156 EXPECT_EQ(700, latency_info.input_coordinates[0].x);
157 EXPECT_EQ(800, latency_info.input_coordinates[0].y);
158 EXPECT_EQ(900, latency_info.input_coordinates[1].x);
159 EXPECT_EQ(1000, latency_info.input_coordinates[1].y);
163 NativeWebKeyboardEvent event;
164 event.type = blink::WebKeyboardEvent::KeyDown;
165 ui::LatencyInfo latency_info;
166 tracker.OnInputEvent(event, &latency_info);
167 EXPECT_EQ(0u, latency_info.input_coordinates_size);
171 TEST(RenderWidgetHostLatencyTrackerTest, ScrollLatency) {
172 RenderWidgetHostLatencyTracker tracker;
173 tracker.Initialize(kTestRoutingId, kTestProcessId);
175 auto scroll_begin = SyntheticWebGestureEventBuilder::BuildScrollBegin(5, -5);
176 ui::LatencyInfo scroll_latency;
177 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
179 tracker.OnInputEvent(scroll_begin, &scroll_latency);
180 EXPECT_TRUE(
181 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
182 tracker.latency_component_id(), nullptr));
183 EXPECT_EQ(2U, scroll_latency.latency_components.size());
185 // The first GestureScrollUpdate should be provided with
186 // INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT.
187 auto first_scroll_update = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
188 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen);
189 scroll_latency = ui::LatencyInfo();
190 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
192 tracker.OnInputEvent(first_scroll_update, &scroll_latency);
193 EXPECT_TRUE(
194 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
195 tracker.latency_component_id(), nullptr));
196 EXPECT_TRUE(scroll_latency.FindLatency(
197 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
198 tracker.latency_component_id(), nullptr));
199 EXPECT_FALSE(scroll_latency.FindLatency(
200 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
201 tracker.latency_component_id(), nullptr));
202 EXPECT_EQ(3U, scroll_latency.latency_components.size());
204 // Subseqeunt GestureScrollUpdates should be provided with
205 // INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT.
206 auto scroll_update = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
207 -5.f, 5.f, 0, blink::WebGestureDeviceTouchscreen);
208 scroll_latency = ui::LatencyInfo();
209 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
211 tracker.OnInputEvent(scroll_update, &scroll_latency);
212 EXPECT_TRUE(
213 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
214 tracker.latency_component_id(), nullptr));
215 EXPECT_FALSE(scroll_latency.FindLatency(
216 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
217 tracker.latency_component_id(), nullptr));
218 EXPECT_TRUE(scroll_latency.FindLatency(
219 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
220 tracker.latency_component_id(), nullptr));
221 EXPECT_EQ(3U, scroll_latency.latency_components.size());
224 } // namespace content