1 # Copyright 2013 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.
6 from telemetry
.core
import exceptions
7 from telemetry
.core
import wpr_modes
8 from telemetry
import decorators
9 from telemetry
.page
import page
10 from telemetry
.unittest_util
import options_for_unittests
11 from telemetry
.unittest_util
import page_test_test_case
13 from measurements
import smoothness
16 class FakeTracingController(object):
18 self
.category_filter
= None
19 def Start(self
, _options
, category_filter
, _timeout
):
20 self
.category_filter
= category_filter
22 class FakePlatform(object):
24 self
.tracing_controller
= FakeTracingController()
27 class FakeBrowser(object):
29 self
.platform
= FakePlatform()
32 class AnimatedPage(page
.Page
):
33 def __init__(self
, page_set
):
34 super(AnimatedPage
, self
).__init
__(
35 url
='file://animated_page.html',
36 page_set
=page_set
, base_dir
=page_set
.base_dir
)
38 def RunPageInteractions(self
, action_runner
):
39 action_runner
.Wait(.2)
42 class FakeTab(object):
44 self
.browser
= FakeBrowser()
46 def ExecuteJavaScript(self
, js
):
49 class SmoothnessUnitTest(page_test_test_case
.PageTestTestCase
):
50 """Smoke test for smoothness measurement
52 Runs smoothness measurement on a simple page and verifies
53 that all metrics were added to the results. The test is purely functional,
54 i.e. it only checks if the metrics are present and non-zero.
56 def testSyntheticDelayConfiguration(self
):
57 test_page
= page
.Page('http://dummy', None)
58 test_page
.synthetic_delays
= {
59 'cc.BeginMainFrame': { 'target_duration': 0.012 },
60 'cc.DrawAndSwap': { 'target_duration': 0.012, 'mode': 'alternating' },
61 'gpu.PresentingFrame': { 'target_duration': 0.012 }
65 measurement
= smoothness
.Smoothness()
66 measurement
.WillStartBrowser(tab
.browser
.platform
)
67 measurement
.WillNavigateToPage(test_page
, tab
)
68 measurement
.WillRunActions(test_page
, tab
)
70 expected_category_filter
= set([
71 'DELAY(cc.BeginMainFrame;0.012000;static)',
72 'DELAY(cc.DrawAndSwap;0.012000;alternating)',
73 'DELAY(gpu.PresentingFrame;0.012000;static)',
76 tracing_controller
= tab
.browser
.platform
.tracing_controller
77 actual_category_filter
= (
78 tracing_controller
.category_filter
.included_categories
)
80 # FIXME: Put blink.console into the expected above and remove these two
81 # remove entries when the blink.console change has rolled into chromium.
82 actual_category_filter
.remove('webkit.console')
83 actual_category_filter
.remove('blink.console')
85 if expected_category_filter
!= actual_category_filter
:
86 sys
.stderr
.write("Expected category filter: %s\n" %
87 repr(expected_category_filter
))
88 sys
.stderr
.write("Actual category filter filter: %s\n" %
89 repr(actual_category_filter
))
90 self
.assertEquals(expected_category_filter
, actual_category_filter
)
93 self
._options
= options_for_unittests
.GetCopy()
94 self
._options
.browser_options
.wpr_mode
= wpr_modes
.WPR_OFF
96 def testSmoothness(self
):
97 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
98 measurement
= smoothness
.Smoothness()
99 results
= self
.RunMeasurement(measurement
, ps
, options
=self
._options
)
100 self
.assertEquals(0, len(results
.failures
))
102 frame_times
= results
.FindAllPageSpecificValuesNamed('frame_times')
103 self
.assertEquals(len(frame_times
), 1)
104 self
.assertGreater(frame_times
[0].GetRepresentativeNumber(), 0)
106 mean_frame_time
= results
.FindAllPageSpecificValuesNamed('mean_frame_time')
107 self
.assertEquals(len(mean_frame_time
), 1)
108 self
.assertGreater(mean_frame_time
[0].GetRepresentativeNumber(), 0)
110 frame_time_discrepancy
= results
.FindAllPageSpecificValuesNamed(
111 'frame_time_discrepancy')
112 self
.assertEquals(len(frame_time_discrepancy
), 1)
113 self
.assertGreater(frame_time_discrepancy
[0].GetRepresentativeNumber(), 0)
115 percentage_smooth
= results
.FindAllPageSpecificValuesNamed(
117 self
.assertEquals(len(percentage_smooth
), 1)
118 self
.assertGreaterEqual(percentage_smooth
[0].GetRepresentativeNumber(), 0)
120 mean_input_event_latency
= results
.FindAllPageSpecificValuesNamed(
121 'mean_input_event_latency')
122 if mean_input_event_latency
:
123 self
.assertEquals(len(mean_input_event_latency
), 1)
125 mean_input_event_latency
[0].GetRepresentativeNumber(), 0)
127 @decorators.Enabled('android') # SurfaceFlinger is android-only
128 def testSmoothnessSurfaceFlingerMetricsCalculated(self
):
129 ps
= self
.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
130 measurement
= smoothness
.Smoothness()
131 results
= self
.RunMeasurement(measurement
, ps
, options
=self
._options
)
132 self
.assertEquals(0, len(results
.failures
))
134 avg_surface_fps
= results
.FindAllPageSpecificValuesNamed('avg_surface_fps')
135 self
.assertEquals(1, len(avg_surface_fps
))
136 self
.assertGreater(avg_surface_fps
[0].GetRepresentativeNumber
, 0)
138 jank_count
= results
.FindAllPageSpecificValuesNamed('jank_count')
139 self
.assertEquals(1, len(jank_count
))
140 self
.assertGreater(jank_count
[0].GetRepresentativeNumber(), -1)
142 max_frame_delay
= results
.FindAllPageSpecificValuesNamed('max_frame_delay')
143 self
.assertEquals(1, len(max_frame_delay
))
144 self
.assertGreater(max_frame_delay
[0].GetRepresentativeNumber
, 0)
146 frame_lengths
= results
.FindAllPageSpecificValuesNamed('frame_lengths')
147 self
.assertEquals(1, len(frame_lengths
))
148 self
.assertGreater(frame_lengths
[0].GetRepresentativeNumber
, 0)
150 @decorators.Disabled('mac', 'chromeos') # http://crbug.com/403903
151 def testSmoothnessForPageWithNoGesture(self
):
152 ps
= self
.CreateEmptyPageSet()
153 ps
.AddUserStory(AnimatedPage(ps
))
155 measurement
= smoothness
.Smoothness()
156 results
= self
.RunMeasurement(measurement
, ps
, options
=self
._options
)
157 self
.assertEquals(0, len(results
.failures
))
159 percentage_smooth
= results
.FindAllPageSpecificValuesNamed(
161 self
.assertEquals(len(percentage_smooth
), 1)
162 self
.assertGreaterEqual(percentage_smooth
[0].GetRepresentativeNumber(), 0)
164 def testCleanUpTrace(self
):
165 self
.TestTracingCleanedUp(smoothness
.Smoothness
, self
._options
)