Home | History | Annotate | Download | only in measurements
      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.
      4 from measurements import smoothness
      5 from telemetry.core import wpr_modes
      6 from telemetry.page import page_measurement_unittest_base
      7 from telemetry.unittest import options_for_unittests
      8 from metrics import timeline
      9 
     10 class SmoothnessUnitTest(
     11       page_measurement_unittest_base.PageMeasurementUnitTestBase):
     12   """Smoke test for smoothness measurement
     13 
     14      Runs smoothness measurement on a simple page and verifies
     15      that all metrics were added to the results. The test is purely functional,
     16      i.e. it only checks if the metrics are present and non-zero.
     17   """
     18 
     19   def setUp(self):
     20     self._options = options_for_unittests.GetCopy()
     21     self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
     22 
     23   def testSmoothnessWithSmoothnessMetric(self):
     24     ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
     25     measurement = smoothness.Smoothness()
     26     results = self.RunMeasurement(measurement, ps, options=self._options)
     27     self.assertEquals(0, len(results.failures))
     28 
     29     frame_times = results.FindAllPageSpecificValuesNamed('frame_times')
     30     self.assertEquals(len(frame_times), 1)
     31     self.assertGreater(frame_times[0].GetRepresentativeNumber(), 0)
     32 
     33     mean_frame_time = results.FindAllPageSpecificValuesNamed('mean_frame_time')
     34     self.assertEquals(len(mean_frame_time), 1)
     35     self.assertGreater(mean_frame_time[0].GetRepresentativeNumber(), 0)
     36 
     37     jank = results.FindAllPageSpecificValuesNamed('jank')
     38     self.assertEquals(len(jank), 1)
     39     self.assertGreater(jank[0].GetRepresentativeNumber(), 0)
     40 
     41     mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth')
     42     self.assertEquals(len(mostly_smooth), 1)
     43     self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0)
     44 
     45 
     46   def testSmoothnessWithTimelineMetric(self):
     47     ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
     48     measurement = smoothness.Smoothness()
     49     timeline_options = self._options
     50     timeline_options.metric = 'timeline'
     51     results = self.RunMeasurement(measurement, ps, options = timeline_options)
     52     self.assertEquals(0, len(results.failures))
     53 
     54     for category in timeline.TimelineThreadCategories.values():
     55       clock_time_name = timeline.ThreadTimePercentageName(category)
     56       clock_time = results.FindAllPageSpecificValuesNamed(clock_time_name)
     57       self.assertEquals(len(clock_time), 1)
     58 
     59       cpu_time_name = timeline.ThreadCPUTimePercentageName(category)
     60       cpu_time = results.FindAllPageSpecificValuesNamed(cpu_time_name)
     61       self.assertEquals(len(cpu_time), 1)
     62