| 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 | 4 |
| 5 import random | 5 import random |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from metrics import smoothness | 8 from metrics import smoothness |
| 9 from metrics import statistics | 9 from metrics import statistics |
| 10 from metrics import rendering_stats | 10 from metrics import rendering_stats |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 renderer_process_markers = timeline.FindTimelineMarkers( | 177 renderer_process_markers = timeline.FindTimelineMarkers( |
| 178 RENDERER_PROCESS_MARKER) | 178 RENDERER_PROCESS_MARKER) |
| 179 self.assertEquals(len(renderer_process_markers), 1) | 179 self.assertEquals(len(renderer_process_markers), 1) |
| 180 renderer_process = renderer_process_markers[0].start_thread.parent | 180 renderer_process = renderer_process_markers[0].start_thread.parent |
| 181 timeline_markers = timeline.FindTimelineMarkers( | 181 timeline_markers = timeline.FindTimelineMarkers( |
| 182 SYNTHETIC_GESTURE_MARKER) | 182 SYNTHETIC_GESTURE_MARKER) |
| 183 stats = rendering_stats.RenderingStats(renderer_process, timeline_markers) | 183 stats = rendering_stats.RenderingStats(renderer_process, timeline_markers) |
| 184 | 184 |
| 185 # Make a results object and add results to it from the smoothness metric. | 185 # Make a results object and add results to it from the smoothness metric. |
| 186 results = PageMeasurementResults() | 186 results = PageMeasurementResults() |
| 187 results.WillMeasurePage(page.Page('http://foo.com/', None)) | 187 p0 = page.Page('http://foo.com/', None) |
| 188 results.WillMeasurePage(p0) |
| 188 smoothness_metric = smoothness.SmoothnessMetric(None) | 189 smoothness_metric = smoothness.SmoothnessMetric(None) |
| 189 smoothness_metric.SetStats(stats) | 190 smoothness_metric.SetStats(stats) |
| 190 smoothness_metric.AddResults(None, results) | 191 smoothness_metric.AddResults(None, results) |
| 191 results.DidMeasurePage() | 192 results.DidMeasurePage() |
| 192 | 193 |
| 194 frame_times = results.FindPageSpecificValuesForPage(p0, 'frame_times')[0] |
| 193 self.assertEquals( | 195 self.assertEquals( |
| 194 expected_frame_times, | 196 expected_frame_times, |
| 195 results.page_results[0]['frame_times'].value) | 197 frame_times.values) |
| 198 |
| 199 mean_frame_time = results.FindPageSpecificValuesForPage( |
| 200 p0, 'mean_frame_time')[0] |
| 196 self.assertAlmostEquals( | 201 self.assertAlmostEquals( |
| 197 1000.0 * (total_time_seconds / num_frames_sent), | 202 1000.0 * (total_time_seconds / num_frames_sent), |
| 198 results.page_results[0]['mean_frame_time'].value, | 203 mean_frame_time.value, |
| 199 places=2) | 204 places=2) |
| 200 | 205 |
| 201 # We don't verify the correctness of the discrepancy computation itself, | 206 # We don't verify the correctness of the discrepancy computation itself, |
| 202 # because we have a separate unit test for that purpose. | 207 # because we have a separate unit test for that purpose. |
| 208 jank = results.FindPageSpecificValuesForPage(p0, 'jank')[0] |
| 203 self.assertAlmostEquals( | 209 self.assertAlmostEquals( |
| 204 statistics.FrameDiscrepancy(stats.frame_timestamps, True), | 210 statistics.FrameDiscrepancy(stats.frame_timestamps, True), |
| 205 results.page_results[0]['jank'].value, | 211 jank.value, |
| 206 places=4) | 212 places=4) |
| 207 | 213 |
| 208 # We do not verify the correctness of Percentile here; Percentile should | 214 # We do not verify the correctness of Percentile here; Percentile should |
| 209 # have its own test. | 215 # have its own test. |
| 210 # The 17 here represents a threshold of 17 ms; this should match the value | 216 # The 17 here represents a threshold of 17 ms; this should match the value |
| 211 # in the smoothness metric. | 217 # in the smoothness metric. |
| 218 mostly_smooth = results.FindPageSpecificValuesForPage( |
| 219 p0, 'mostly_smooth')[0] |
| 212 self.assertEquals( | 220 self.assertEquals( |
| 213 statistics.Percentile(expected_frame_times, 95.0) < 17.0, | 221 statistics.Percentile(expected_frame_times, 95.0) < 17.0, |
| 214 results.page_results[0]['mostly_smooth'].value) | 222 mostly_smooth.value) |
| OLD | NEW |