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 measurements import smoothness
7 from telemetry.core import wpr_modes
8 from telemetry.page import page
9 from telemetry.page import page_measurement_unittest_base
10 # pylint: disable=W0401,W0614
11 from telemetry.page.actions.all_page_actions import *
12 from telemetry.unittest import options_for_unittests
14 class FakePlatform(object):
15 def IsRawDisplayFrameRateSupported(self):
17 def CanMonitorPower(self):
21 class FakeBrowser(object):
23 self.platform = FakePlatform()
24 self.category_filter = None
26 def StartTracing(self, category_filter, _):
27 self.category_filter = category_filter
30 class AnimatedPage(page.Page):
31 def __init__(self, page_set):
32 super(AnimatedPage, self).__init__(
33 url='file://animated_page.html',
34 page_set=page_set, base_dir=page_set.base_dir)
36 def RunSmoothness(self, action_runner):
40 class FakeTab(object):
42 self.browser = FakeBrowser()
44 def ExecuteJavaScript(self, js):
47 class SmoothnessUnitTest(
48 page_measurement_unittest_base.PageMeasurementUnitTestBase):
49 """Smoke test for smoothness measurement
51 Runs smoothness measurement on a simple page and verifies
52 that all metrics were added to the results. The test is purely functional,
53 i.e. it only checks if the metrics are present and non-zero.
55 def testSyntheticDelayConfiguration(self):
56 test_page = page.Page('http://dummy', None)
57 test_page.synthetic_delays = {
58 'cc.BeginMainFrame': { 'target_duration': 0.012 },
59 'cc.DrawAndSwap': { 'target_duration': 0.012, 'mode': 'alternating' },
60 'gpu.PresentingFrame': { 'target_duration': 0.012 }
64 measurement = smoothness.Smoothness()
65 measurement.WillRunActions(test_page, tab)
67 expected_category_filter = [
68 'DELAY(cc.BeginMainFrame;0.012000;static)',
69 'DELAY(cc.DrawAndSwap;0.012000;alternating)',
70 'DELAY(gpu.PresentingFrame;0.012000;static)',
73 actual_category_filter = tab.browser.category_filter.split(',')
74 actual_category_filter.sort()
76 # FIXME: Put blink.console into the expected above and remove these two
77 # remove entries when the blink.console change has rolled into chromium.
78 actual_category_filter.remove('webkit.console')
79 actual_category_filter.remove('blink.console')
81 if expected_category_filter != actual_category_filter:
82 sys.stderr.write("Expected category filter: %s\n" %
83 repr(expected_category_filter))
84 sys.stderr.write("Actual category filter filter: %s\n" %
85 repr(actual_category_filter))
86 self.assertEquals(expected_category_filter, actual_category_filter)
89 self._options = options_for_unittests.GetCopy()
90 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
92 def testSmoothness(self):
93 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
94 measurement = smoothness.Smoothness()
95 results = self.RunMeasurement(measurement, ps, options=self._options)
96 self.assertEquals(0, len(results.failures))
98 frame_times = results.FindAllPageSpecificValuesNamed('frame_times')
99 self.assertEquals(len(frame_times), 1)
100 self.assertGreater(frame_times[0].GetRepresentativeNumber(), 0)
102 mean_frame_time = results.FindAllPageSpecificValuesNamed('mean_frame_time')
103 self.assertEquals(len(mean_frame_time), 1)
104 self.assertGreater(mean_frame_time[0].GetRepresentativeNumber(), 0)
106 jank = results.FindAllPageSpecificValuesNamed('jank')
107 self.assertEquals(len(jank), 1)
108 self.assertGreater(jank[0].GetRepresentativeNumber(), 0)
110 mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth')
111 self.assertEquals(len(mostly_smooth), 1)
112 self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0)
114 mean_input_event_latency = results.FindAllPageSpecificValuesNamed(
115 'mean_input_event_latency')
116 if mean_input_event_latency:
117 self.assertEquals(len(mean_input_event_latency), 1)
119 mean_input_event_latency[0].GetRepresentativeNumber(), 0)
121 def testSmoothnessForPageWithNoGesture(self):
122 ps = self.CreateEmptyPageSet()
123 ps.AddPage(AnimatedPage(ps))
125 measurement = smoothness.Smoothness()
126 results = self.RunMeasurement(measurement, ps, options=self._options)
127 self.assertEquals(0, len(results.failures))
129 mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth')
130 self.assertEquals(len(mostly_smooth), 1)
131 self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0)
133 def testCleanUpTrace(self):
134 self.TestTracingCleanedUp(smoothness.Smoothness, self._options)