Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_latency_tracker_unittest.cc
blob1c5b7b83c208314672c968f56d178a9769ef60ed
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/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 ui::LatencyInfo scroll_latency;
28 tracker.OnInputEvent(scroll, &scroll_latency);
29 EXPECT_TRUE(
30 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
31 tracker.latency_component_id(), nullptr));
32 EXPECT_EQ(1U, scroll_latency.input_coordinates_size);
36 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
37 blink::WebMouseWheelEvent::PhaseChanged);
38 ui::LatencyInfo wheel_latency;
39 tracker.OnInputEvent(wheel, &wheel_latency);
40 EXPECT_TRUE(
41 wheel_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
42 tracker.latency_component_id(), nullptr));
43 EXPECT_EQ(1U, wheel_latency.input_coordinates_size);
47 SyntheticWebTouchEvent touch;
48 touch.PressPoint(0, 0);
49 touch.PressPoint(1, 1);
50 ui::LatencyInfo touch_latency;
51 tracker.OnInputEvent(touch, &touch_latency);
52 EXPECT_TRUE(
53 touch_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
54 tracker.latency_component_id(), nullptr));
55 EXPECT_EQ(2U, touch_latency.input_coordinates_size);
59 TEST(RenderWidgetHostLatencyTrackerTest,
60 LatencyTerminatedOnAckIfRenderingNotScheduled) {
61 RenderWidgetHostLatencyTracker tracker;
62 tracker.Initialize(kTestRoutingId, kTestProcessId);
65 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollBegin(5.f, -5.f);
66 ui::LatencyInfo scroll_latency;
67 tracker.OnInputEvent(scroll, &scroll_latency);
68 tracker.OnInputEventAck(scroll, &scroll_latency);
69 EXPECT_TRUE(scroll_latency.FindLatency(
70 ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT, 0, nullptr));
71 EXPECT_TRUE(scroll_latency.terminated);
75 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
76 blink::WebMouseWheelEvent::PhaseChanged);
77 ui::LatencyInfo wheel_latency;
78 tracker.OnInputEvent(wheel, &wheel_latency);
79 tracker.OnInputEventAck(wheel, &wheel_latency);
80 EXPECT_TRUE(wheel_latency.FindLatency(
81 ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT, 0, nullptr));
82 EXPECT_TRUE(wheel_latency.terminated);
86 SyntheticWebTouchEvent touch;
87 touch.PressPoint(0, 0);
88 ui::LatencyInfo touch_latency;
89 tracker.OnInputEvent(touch, &touch_latency);
90 tracker.OnInputEventAck(touch, &touch_latency);
91 EXPECT_TRUE(touch_latency.FindLatency(
92 ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT, 0, nullptr));
93 EXPECT_TRUE(touch_latency.terminated);
97 TEST(RenderWidgetHostLatencyTrackerTest, InputCoordinatesPopulated) {
98 RenderWidgetHostLatencyTracker tracker;
99 tracker.Initialize(kTestRoutingId, kTestProcessId);
102 auto event = SyntheticWebMouseWheelEventBuilder::Build(-5, 0, 0, true);
103 event.x = 100;
104 event.y = 200;
105 ui::LatencyInfo latency_info;
106 tracker.OnInputEvent(event, &latency_info);
107 EXPECT_EQ(1u, latency_info.input_coordinates_size);
108 EXPECT_EQ(100, latency_info.input_coordinates[0].x);
109 EXPECT_EQ(200, latency_info.input_coordinates[0].y);
113 auto event = SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove);
114 event.x = 300;
115 event.y = 400;
116 ui::LatencyInfo latency_info;
117 tracker.OnInputEvent(event, &latency_info);
118 EXPECT_EQ(1u, latency_info.input_coordinates_size);
119 EXPECT_EQ(300, latency_info.input_coordinates[0].x);
120 EXPECT_EQ(400, latency_info.input_coordinates[0].y);
124 auto event = SyntheticWebGestureEventBuilder::Build(
125 WebInputEvent::GestureScrollBegin, blink::WebGestureDeviceTouchscreen);
126 event.x = 500;
127 event.y = 600;
128 ui::LatencyInfo latency_info;
129 tracker.OnInputEvent(event, &latency_info);
130 EXPECT_EQ(1u, latency_info.input_coordinates_size);
131 EXPECT_EQ(500, latency_info.input_coordinates[0].x);
132 EXPECT_EQ(600, latency_info.input_coordinates[0].y);
136 SyntheticWebTouchEvent event;
137 event.PressPoint(700, 800);
138 event.PressPoint(900, 1000);
139 event.PressPoint(1100, 1200); // LatencyInfo only holds two coordinates.
140 ui::LatencyInfo latency_info;
141 tracker.OnInputEvent(event, &latency_info);
142 EXPECT_EQ(2u, latency_info.input_coordinates_size);
143 EXPECT_EQ(700, latency_info.input_coordinates[0].x);
144 EXPECT_EQ(800, latency_info.input_coordinates[0].y);
145 EXPECT_EQ(900, latency_info.input_coordinates[1].x);
146 EXPECT_EQ(1000, latency_info.input_coordinates[1].y);
150 NativeWebKeyboardEvent event;
151 event.type = blink::WebKeyboardEvent::KeyDown;
152 ui::LatencyInfo latency_info;
153 tracker.OnInputEvent(event, &latency_info);
154 EXPECT_EQ(0u, latency_info.input_coordinates_size);
158 TEST(RenderWidgetHostLatencyTrackerTest, ScrollLatency) {
159 RenderWidgetHostLatencyTracker tracker;
160 tracker.Initialize(kTestRoutingId, kTestProcessId);
162 auto scroll_begin = SyntheticWebGestureEventBuilder::BuildScrollBegin(5, -5);
163 ui::LatencyInfo scroll_latency;
164 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
166 tracker.OnInputEvent(scroll_begin, &scroll_latency);
167 EXPECT_TRUE(
168 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
169 tracker.latency_component_id(), nullptr));
170 EXPECT_EQ(2U, scroll_latency.latency_components.size());
172 // The first GestureScrollUpdate should be provided with
173 // INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT.
174 auto first_scroll_update = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
175 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen);
176 scroll_latency = ui::LatencyInfo();
177 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
179 tracker.OnInputEvent(first_scroll_update, &scroll_latency);
180 EXPECT_TRUE(
181 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
182 tracker.latency_component_id(), nullptr));
183 EXPECT_TRUE(scroll_latency.FindLatency(
184 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
185 tracker.latency_component_id(), nullptr));
186 EXPECT_FALSE(scroll_latency.FindLatency(
187 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
188 tracker.latency_component_id(), nullptr));
189 EXPECT_EQ(3U, scroll_latency.latency_components.size());
191 // Subseqeunt GestureScrollUpdates should be provided with
192 // INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT.
193 auto scroll_update = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
194 -5.f, 5.f, 0, blink::WebGestureDeviceTouchscreen);
195 scroll_latency = ui::LatencyInfo();
196 scroll_latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0,
198 tracker.OnInputEvent(scroll_update, &scroll_latency);
199 EXPECT_TRUE(
200 scroll_latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
201 tracker.latency_component_id(), nullptr));
202 EXPECT_FALSE(scroll_latency.FindLatency(
203 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
204 tracker.latency_component_id(), nullptr));
205 EXPECT_TRUE(scroll_latency.FindLatency(
206 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
207 tracker.latency_component_id(), nullptr));
208 EXPECT_EQ(3U, scroll_latency.latency_components.size());
211 } // namespace content