• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4import sys
5
6from measurements import smoothness
7from telemetry.core import wpr_modes
8from telemetry.page import page
9from telemetry.page import page_measurement_unittest_base
10# pylint: disable=W0401,W0614
11from telemetry.page.actions.all_page_actions import *
12from telemetry.unittest import options_for_unittests
13
14class FakePlatform(object):
15  def IsRawDisplayFrameRateSupported(self):
16    return False
17  def CanMonitorPower(self):
18    return False
19
20
21class FakeBrowser(object):
22  def __init__(self):
23    self.platform = FakePlatform()
24    self.category_filter = None
25
26  def StartTracing(self, category_filter, _):
27    self.category_filter = category_filter
28
29
30class 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)
35
36  def RunSmoothness(self, action_runner):
37    action_runner.Wait(1)
38
39
40class FakeTab(object):
41  def __init__(self):
42    self.browser = FakeBrowser()
43
44  def ExecuteJavaScript(self, js):
45    pass
46
47class SmoothnessUnitTest(
48      page_measurement_unittest_base.PageMeasurementUnitTestBase):
49  """Smoke test for smoothness measurement
50
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.
54  """
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 }
61    }
62
63    tab = FakeTab()
64    measurement = smoothness.Smoothness()
65    measurement.WillRunActions(test_page, tab)
66
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)',
71        'benchmark'
72    ]
73    actual_category_filter = tab.browser.category_filter.split(',')
74    actual_category_filter.sort()
75
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')
80
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)
87
88  def setUp(self):
89    self._options = options_for_unittests.GetCopy()
90    self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
91
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))
97
98    frame_times = results.FindAllPageSpecificValuesNamed('frame_times')
99    self.assertEquals(len(frame_times), 1)
100    self.assertGreater(frame_times[0].GetRepresentativeNumber(), 0)
101
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)
105
106    jank = results.FindAllPageSpecificValuesNamed('jank')
107    self.assertEquals(len(jank), 1)
108    self.assertGreater(jank[0].GetRepresentativeNumber(), 0)
109
110    mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth')
111    self.assertEquals(len(mostly_smooth), 1)
112    self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0)
113
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)
118      self.assertGreater(
119          mean_input_event_latency[0].GetRepresentativeNumber(), 0)
120
121  def testSmoothnessForPageWithNoGesture(self):
122    ps = self.CreateEmptyPageSet()
123    ps.AddPage(AnimatedPage(ps))
124
125    measurement = smoothness.Smoothness()
126    results = self.RunMeasurement(measurement, ps, options=self._options)
127    self.assertEquals(0, len(results.failures))
128
129    mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth')
130    self.assertEquals(len(mostly_smooth), 1)
131    self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0)
132
133  def testCleanUpTrace(self):
134    self.TestTracingCleanedUp(smoothness.Smoothness, self._options)
135