| 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 import sys | 4 import sys |
| 5 | 5 |
| 6 from measurements import smoothness | 6 from measurements import smoothness |
| 7 from metrics import power |
| 8 from telemetry.core import exceptions |
| 7 from telemetry.core import wpr_modes | 9 from telemetry.core import wpr_modes |
| 8 from telemetry.page import page | 10 from telemetry.page import page |
| 9 from telemetry.page import page_measurement_unittest_base | 11 from telemetry.page import page_measurement_unittest_base |
| 12 from telemetry.page import page_test |
| 10 from telemetry.unittest import options_for_unittests | 13 from telemetry.unittest import options_for_unittests |
| 11 | 14 |
| 12 class FakePlatform(object): | 15 class FakePlatform(object): |
| 13 def IsRawDisplayFrameRateSupported(self): | 16 def IsRawDisplayFrameRateSupported(self): |
| 14 return False | 17 return False |
| 15 def CanMonitorPower(self): | 18 def CanMonitorPower(self): |
| 16 return False | 19 return False |
| 17 | 20 |
| 18 | 21 |
| 19 class FakeBrowser(object): | 22 class FakeBrowser(object): |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 measurement = smoothness.Smoothness() | 127 measurement = smoothness.Smoothness() |
| 125 results = self.RunMeasurement(measurement, ps, options=self._options) | 128 results = self.RunMeasurement(measurement, ps, options=self._options) |
| 126 self.assertEquals(0, len(results.failures)) | 129 self.assertEquals(0, len(results.failures)) |
| 127 | 130 |
| 128 mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth') | 131 mostly_smooth = results.FindAllPageSpecificValuesNamed('mostly_smooth') |
| 129 self.assertEquals(len(mostly_smooth), 1) | 132 self.assertEquals(len(mostly_smooth), 1) |
| 130 self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0) | 133 self.assertGreaterEqual(mostly_smooth[0].GetRepresentativeNumber(), 0) |
| 131 | 134 |
| 132 def testCleanUpTrace(self): | 135 def testCleanUpTrace(self): |
| 133 self.TestTracingCleanedUp(smoothness.Smoothness, self._options) | 136 self.TestTracingCleanedUp(smoothness.Smoothness, self._options) |
| 137 |
| 138 def testCleanUpPowerMetric(self): |
| 139 class FailPage(page.Page): |
| 140 def __init__(self, page_set): |
| 141 super(FailPage, self).__init__( |
| 142 url='file://blank.html', |
| 143 page_set=page_set, base_dir=page_set.base_dir) |
| 144 def RunSmoothness(self, _): |
| 145 raise exceptions.IntentionalException |
| 146 |
| 147 class FakePowerMetric(power.PowerMetric): |
| 148 start_called = False |
| 149 stop_called = True |
| 150 def Start(self, _1, _2): |
| 151 self.start_called = True |
| 152 def Stop(self, _1, _2): |
| 153 self.stop_called = True |
| 154 |
| 155 ps = self.CreateEmptyPageSet() |
| 156 ps.AddPage(FailPage(ps)) |
| 157 |
| 158 class BuggyMeasurement(smoothness.Smoothness): |
| 159 fake_power = None |
| 160 # Inject fake power metric. |
| 161 def WillStartBrowser(self, browser): |
| 162 self.fake_power = self._power_metric = FakePowerMetric(browser) |
| 163 |
| 164 measurement = BuggyMeasurement() |
| 165 try: |
| 166 self.RunMeasurement(measurement, ps) |
| 167 except page_test.TestNotSupportedOnPlatformFailure: |
| 168 pass |
| 169 |
| 170 self.assertTrue(measurement.fake_power.start_called) |
| 171 self.assertTrue(measurement.fake_power.stop_called) |
| OLD | NEW |