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

Side by Side Diff: content/browser/renderer_host/input/scroll_latency_browsertest.cc

Issue 2863103002: Reduce composited smooth scroll latency by a frame (also fixes latency UMAs). (Closed)
Patch Set: Cleanup. Created 3 years, 7 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
« no previous file with comments | « cc/trees/mutator_host.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "base/test/histogram_tester.h"
9 #include "content/browser/renderer_host/input/synthetic_gesture.h"
10 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
11 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
12 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
13 #include "content/browser/renderer_host/render_widget_host_impl.h"
14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/common/input/synthetic_gesture_params.h"
16 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/render_widget_host_view.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "content/public/test/content_browser_test.h"
21 #include "content/public/test/content_browser_test_utils.h"
22 #include "content/shell/browser/shell.h"
23
24 namespace {
25
26 const char kDataURL[] =
27 "data:text/html;charset=utf-8,"
28 "<!DOCTYPE html>"
29 "<html>"
30 "<head>"
31 "<title>Mouse wheel latency histograms reported.</title>"
32 "<script src=\"../../resources/testharness.js\"></script>"
33 "<script src=\"../../resources/testharnessreport.js\"></script>"
34 "<style>"
35 "body {"
36 " height:3000px;"
37 "}"
38 "</style>"
39 "</head>"
40 "<body>"
41 "</body>"
42 "</html>";
43
44 } // namespace
45
46 namespace content {
47
48 class ScrollLatencyBrowserTest : public ContentBrowserTest {
49 public:
50 ScrollLatencyBrowserTest() : loop_(base::MessageLoop::TYPE_UI) {}
51 ~ScrollLatencyBrowserTest() override {}
52
53 RenderWidgetHostImpl* GetWidgetHost() {
54 return RenderWidgetHostImpl::From(
55 shell()->web_contents()->GetRenderViewHost()->GetWidget());
56 }
57
58 // TODO(tdresser): Find a way to avoid sleeping like this. See
59 // crbug.com/405282 for details.
60 void GiveItSomeTime() {
61 base::RunLoop run_loop;
62 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
63 FROM_HERE, run_loop.QuitClosure(),
64 base::TimeDelta::FromMillisecondsD(10));
65 run_loop.Run();
66 }
67
68 void WaitAFrame() {
69 while (!GetWidgetHost()->ScheduleComposite())
70 GiveItSomeTime();
71 frame_watcher_.WaitFrames(1);
72 }
73
74 protected:
75 void LoadURL() {
76 const GURL data_url(kDataURL);
77 NavigateToURL(shell(), data_url);
78
79 RenderWidgetHostImpl* host = GetWidgetHost();
80 host->GetView()->SetSize(gfx::Size(400, 400));
81
82 frame_watcher_.Observe(shell()->web_contents());
83
84 // Wait a frame to make sure the page has renderered.
85 WaitAFrame();
86 }
87
88 // Generate a single wheel tick, scrolling by |distance|. This will perform a
89 // smooth scroll on platforms which support it.
90 void DoSmoothWheelScroll(const gfx::Vector2d& distance) {
91 blink::WebGestureEvent event =
92 SyntheticWebGestureEventBuilder::BuildScrollBegin(
93 distance.x(), -distance.y(),
94 blink::WebGestureDevice::kWebGestureDeviceTouchpad, 1);
95 event.data.scroll_begin.delta_hint_units =
96 blink::WebGestureEvent::ScrollUnits::kPixels;
97 GetWidgetHost()->ForwardGestureEvent(event);
98
99 blink::WebGestureEvent event2 =
100 SyntheticWebGestureEventBuilder::BuildScrollUpdate(
101 distance.x(), -distance.y(), 0,
102 blink::WebGestureDevice::kWebGestureDeviceTouchpad);
103 event2.data.scroll_update.delta_units =
104 blink::WebGestureEvent::ScrollUnits::kPixels;
105 GetWidgetHost()->ForwardGestureEvent(event2);
106 }
107
108 private:
109 base::MessageLoop loop_;
110 base::RunLoop runner_;
111 FrameWatcher frame_watcher_;
112
113 DISALLOW_COPY_AND_ASSIGN(ScrollLatencyBrowserTest);
114 };
115
116 // Perform a smooth wheel scroll, and verify that our end-to-end wheel latency
117 // metric is recorded. See crbug.com/599910 for details.
118 IN_PROC_BROWSER_TEST_F(ScrollLatencyBrowserTest, SmoothWheelScroll) {
119 LoadURL();
120
121 base::HistogramTester histogram_tester;
122 DoSmoothWheelScroll(gfx::Vector2d(0, 100));
123
124 size_t num_samples = 0;
125
126 while (num_samples == 0) {
127 num_samples =
128 histogram_tester
129 .GetAllSamples(
130 "Event.Latency.ScrollBegin.Wheel.TimeToScrollUpdateSwapBegin2")
131 .size();
132 GiveItSomeTime();
133 }
134 }
135
136 } // namespace content
OLDNEW
« no previous file with comments | « cc/trees/mutator_host.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698