| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 from measurements import smoothness | 4 from measurements import smoothness |
| 5 from telemetry.core import wpr_modes | 5 from telemetry.core import wpr_modes |
| 6 from telemetry.page import page |
| 6 from telemetry.page import page_measurement_unittest_base | 7 from telemetry.page import page_measurement_unittest_base |
| 7 from telemetry.unittest import options_for_unittests | 8 from telemetry.unittest import options_for_unittests |
| 8 | 9 |
| 10 class FakePlatform(object): |
| 11 def IsRawDisplayFrameRateSupported(self): |
| 12 return False |
| 13 |
| 14 |
| 15 class FakeBrowser(object): |
| 16 def __init__(self): |
| 17 self.platform = FakePlatform() |
| 18 self.category_filter = None |
| 19 |
| 20 def StartTracing(self, category_filter, _): |
| 21 self.category_filter = category_filter |
| 22 |
| 23 |
| 24 class FakeTab(object): |
| 25 def __init__(self): |
| 26 self.browser = FakeBrowser() |
| 27 |
| 28 def ExecuteJavaScript(self, js): |
| 29 pass |
| 30 |
| 9 class SmoothnessUnitTest( | 31 class SmoothnessUnitTest( |
| 10 page_measurement_unittest_base.PageMeasurementUnitTestBase): | 32 page_measurement_unittest_base.PageMeasurementUnitTestBase): |
| 11 """Smoke test for smoothness measurement | 33 """Smoke test for smoothness measurement |
| 12 | 34 |
| 13 Runs smoothness measurement on a simple page and verifies | 35 Runs smoothness measurement on a simple page and verifies |
| 14 that all metrics were added to the results. The test is purely functional, | 36 that all metrics were added to the results. The test is purely functional, |
| 15 i.e. it only checks if the metrics are present and non-zero. | 37 i.e. it only checks if the metrics are present and non-zero. |
| 16 """ | 38 """ |
| 39 def testSyntheticDelayConfiguration(self): |
| 40 attributes = { |
| 41 'synthetic_delays': { |
| 42 'cc.BeginMainFrame': { 'target_duration': 0.012 }, |
| 43 'cc.DrawAndSwap': { 'target_duration': 0.012, 'mode': 'alternating' }, |
| 44 'gpu.SwapBuffers': { 'target_duration': 0.012 } |
| 45 } |
| 46 } |
| 47 test_page = page.Page('http://dummy', None, attributes=attributes) |
| 17 | 48 |
| 49 tab = FakeTab() |
| 50 measurement = smoothness.Smoothness() |
| 51 measurement.WillRunActions(test_page, tab) |
| 52 |
| 53 expected_category_filter = [ |
| 54 'DELAY(cc.BeginMainFrame;0.012000;static)', |
| 55 'DELAY(cc.DrawAndSwap;0.012000;alternating)', |
| 56 'DELAY(gpu.SwapBuffers;0.012000;static)', |
| 57 'benchmark', |
| 58 'webkit.console' |
| 59 ] |
| 60 self.assertEquals(expected_category_filter, |
| 61 sorted(tab.browser.category_filter.split(','))) |
| 18 def setUp(self): | 62 def setUp(self): |
| 63 |
| 19 self._options = options_for_unittests.GetCopy() | 64 self._options = options_for_unittests.GetCopy() |
| 20 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF | 65 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF |
| 21 | 66 |
| 22 def testSmoothness(self): | 67 def testSmoothness(self): |
| 23 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html') | 68 ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html') |
| 24 measurement = smoothness.Smoothness() | 69 measurement = smoothness.Smoothness() |
| 25 results = self.RunMeasurement(measurement, ps, options=self._options) | 70 results = self.RunMeasurement(measurement, ps, options=self._options) |
| 26 self.assertEquals(0, len(results.failures)) | 71 self.assertEquals(0, len(results.failures)) |
| 27 | 72 |
| 28 frame_times = results.FindAllPageSpecificValuesNamed('frame_times') | 73 frame_times = results.FindAllPageSpecificValuesNamed('frame_times') |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 self.assertEquals(len(mean_mouse_wheel_latency), 1) | 92 self.assertEquals(len(mean_mouse_wheel_latency), 1) |
| 48 self.assertGreater( | 93 self.assertGreater( |
| 49 mean_mouse_wheel_latency[0].GetRepresentativeNumber(), 0) | 94 mean_mouse_wheel_latency[0].GetRepresentativeNumber(), 0) |
| 50 | 95 |
| 51 mean_touch_scroll_latency = results.FindAllPageSpecificValuesNamed( | 96 mean_touch_scroll_latency = results.FindAllPageSpecificValuesNamed( |
| 52 'mean_touch_scroll_latency') | 97 'mean_touch_scroll_latency') |
| 53 if mean_touch_scroll_latency: | 98 if mean_touch_scroll_latency: |
| 54 self.assertEquals(len(mean_touch_scroll_latency), 1) | 99 self.assertEquals(len(mean_touch_scroll_latency), 1) |
| 55 self.assertGreater( | 100 self.assertGreater( |
| 56 mean_touch_scroll_latency[0].GetRepresentativeNumber(), 0) | 101 mean_touch_scroll_latency[0].GetRepresentativeNumber(), 0) |
| OLD | NEW |