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