| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 os | 5 import os |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from telemetry import decorators | 8 from telemetry import decorators |
| 9 from telemetry.core import platform | 9 from telemetry.core import platform |
| 10 from telemetry.core import wpr_modes | 10 from telemetry.core import wpr_modes |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 fake_tbm_metrics = (FakeSmoothMetric(), FakeLoadingMetric()) | 107 fake_tbm_metrics = (FakeSmoothMetric(), FakeLoadingMetric()) |
| 108 tbm_module._GetAllTimelineBasedMetrics = lambda: fake_tbm_metrics | 108 tbm_module._GetAllTimelineBasedMetrics = lambda: fake_tbm_metrics |
| 109 | 109 |
| 110 def tearDown(self): | 110 def tearDown(self): |
| 111 tbm_module._GetAllTimelineBasedMetrics = self.actual_get_all_tbm_metrics | 111 tbm_module._GetAllTimelineBasedMetrics = self.actual_get_all_tbm_metrics |
| 112 | 112 |
| 113 def testGetRendererThreadsToInteractionRecordsMap(self): | 113 def testGetRendererThreadsToInteractionRecordsMap(self): |
| 114 d = TimelineBasedMetricTestData() | 114 d = TimelineBasedMetricTestData() |
| 115 # Insert 2 interaction records to renderer_thread and 1 to foo_thread | 115 # Insert 2 interaction records to renderer_thread and 1 to foo_thread |
| 116 d.AddInteraction(d.renderer_thread, ts=0, duration=20, | 116 d.AddInteraction(d.renderer_thread, ts=0, duration=20, |
| 117 marker='Interaction.LogicalName1/is_smooth') | 117 marker='Interaction.LogicalName1') |
| 118 d.AddInteraction(d.renderer_thread, ts=25, duration=5, | 118 d.AddInteraction(d.renderer_thread, ts=25, duration=5, |
| 119 marker='Interaction.LogicalName2/') | 119 marker='Interaction.LogicalName2') |
| 120 d.AddInteraction(d.foo_thread, ts=50, duration=15, | 120 d.AddInteraction(d.foo_thread, ts=50, duration=15, |
| 121 marker='Interaction.LogicalName3/is_smooth') | 121 marker='Interaction.LogicalName3') |
| 122 d.FinalizeImport() | 122 d.FinalizeImport() |
| 123 | 123 |
| 124 self.assertEquals(2, len(d.threads_to_records_map)) | 124 self.assertEquals(2, len(d.threads_to_records_map)) |
| 125 | 125 |
| 126 # Assert the 2 interaction records of renderer_thread are in the map. | 126 # Assert the 2 interaction records of renderer_thread are in the map. |
| 127 self.assertIn(d.renderer_thread, d.threads_to_records_map) | 127 self.assertIn(d.renderer_thread, d.threads_to_records_map) |
| 128 interactions = d.threads_to_records_map[d.renderer_thread] | 128 interactions = d.threads_to_records_map[d.renderer_thread] |
| 129 self.assertEquals(2, len(interactions)) | 129 self.assertEquals(2, len(interactions)) |
| 130 self.assertTrue(interactions[0].is_smooth) | |
| 131 self.assertEquals(0, interactions[0].start) | 130 self.assertEquals(0, interactions[0].start) |
| 132 self.assertEquals(20, interactions[0].end) | 131 self.assertEquals(20, interactions[0].end) |
| 133 | 132 |
| 134 self.assertEquals(25, interactions[1].start) | 133 self.assertEquals(25, interactions[1].start) |
| 135 self.assertEquals(30, interactions[1].end) | 134 self.assertEquals(30, interactions[1].end) |
| 136 | 135 |
| 137 # Assert the 1 interaction records of foo_thread is in the map. | 136 # Assert the 1 interaction records of foo_thread is in the map. |
| 138 self.assertIn(d.foo_thread, d.threads_to_records_map) | 137 self.assertIn(d.foo_thread, d.threads_to_records_map) |
| 139 interactions = d.threads_to_records_map[d.foo_thread] | 138 interactions = d.threads_to_records_map[d.foo_thread] |
| 140 self.assertEquals(1, len(interactions)) | 139 self.assertEquals(1, len(interactions)) |
| 141 self.assertTrue(interactions[0].is_smooth) | |
| 142 self.assertEquals(50, interactions[0].start) | 140 self.assertEquals(50, interactions[0].start) |
| 143 self.assertEquals(65, interactions[0].end) | 141 self.assertEquals(65, interactions[0].end) |
| 144 | 142 |
| 145 def testAddResults(self): | 143 def testAddResults(self): |
| 146 d = TimelineBasedMetricTestData() | 144 d = TimelineBasedMetricTestData() |
| 147 d.AddInteraction(d.renderer_thread, ts=0, duration=20, | 145 d.AddInteraction(d.renderer_thread, ts=0, duration=20, |
| 148 marker='Interaction.LogicalName1/is_smooth') | 146 marker='Interaction.LogicalName1') |
| 149 d.AddInteraction(d.foo_thread, ts=25, duration=5, | 147 d.AddInteraction(d.foo_thread, ts=25, duration=5, |
| 150 marker='Interaction.LogicalName2') | 148 marker='Interaction.LogicalName2') |
| 151 d.FinalizeImport() | 149 d.FinalizeImport() |
| 152 d.AddResults() | 150 d.AddResults() |
| 153 self.assertEquals(1, len(d.results.FindAllPageSpecificValuesNamed( | 151 self.assertEquals(1, len(d.results.FindAllPageSpecificValuesNamed( |
| 154 'LogicalName1-FakeSmoothMetric'))) | 152 'LogicalName1-FakeSmoothMetric'))) |
| 155 self.assertEquals(1, len(d.results.FindAllPageSpecificValuesNamed( | 153 self.assertEquals(1, len(d.results.FindAllPageSpecificValuesNamed( |
| 156 'LogicalName2-FakeLoadingMetric'))) | 154 'LogicalName2-FakeLoadingMetric'))) |
| 157 | 155 |
| 158 def testDuplicateInteractionsInDifferentThreads(self): | 156 def testDuplicateInteractionsInDifferentThreads(self): |
| 159 d = TimelineBasedMetricTestData() | 157 d = TimelineBasedMetricTestData() |
| 160 d.AddInteraction(d.renderer_thread, ts=10, duration=5, | 158 d.AddInteraction(d.renderer_thread, ts=10, duration=5, |
| 161 marker='Interaction.LogicalName/is_smooth,repeatable') | 159 marker='Interaction.LogicalName/repeatable') |
| 162 d.AddInteraction(d.foo_thread, ts=20, duration=5, | 160 d.AddInteraction(d.foo_thread, ts=20, duration=5, |
| 163 marker='Interaction.LogicalName/is_smooth') | 161 marker='Interaction.LogicalName') |
| 164 self.assertRaises(tbm_module.InvalidInteractions, d.FinalizeImport) | 162 self.assertRaises(tbm_module.InvalidInteractions, d.FinalizeImport) |
| 165 | 163 |
| 166 def testDuplicateRepeatableInteractionsInDifferentThreads(self): | 164 def testDuplicateRepeatableInteractionsInDifferentThreads(self): |
| 167 d = TimelineBasedMetricTestData() | 165 d = TimelineBasedMetricTestData() |
| 168 d.AddInteraction(d.renderer_thread, ts=10, duration=5, | 166 d.AddInteraction(d.renderer_thread, ts=10, duration=5, |
| 169 marker='Interaction.LogicalName/is_smooth,repeatable') | 167 marker='Interaction.LogicalName/repeatable') |
| 170 d.AddInteraction(d.foo_thread, ts=20, duration=5, | 168 d.AddInteraction(d.foo_thread, ts=20, duration=5, |
| 171 marker='Interaction.LogicalName/is_smooth,repeatable') | 169 marker='Interaction.LogicalName/repeatable') |
| 172 self.assertRaises(tbm_module.InvalidInteractions, d.FinalizeImport) | 170 self.assertRaises(tbm_module.InvalidInteractions, d.FinalizeImport) |
| 173 | 171 |
| 174 | 172 |
| 175 def testDuplicateUnrepeatableInteractionsInSameThread(self): | 173 def testDuplicateUnrepeatableInteractionsInSameThread(self): |
| 176 d = TimelineBasedMetricTestData() | 174 d = TimelineBasedMetricTestData() |
| 177 d.AddInteraction(d.renderer_thread, ts=10, duration=5, | 175 d.AddInteraction(d.renderer_thread, ts=10, duration=5, |
| 178 marker='Interaction.LogicalName/is_smooth') | 176 marker='Interaction.LogicalName') |
| 179 d.AddInteraction(d.renderer_thread, ts=20, duration=5, | 177 d.AddInteraction(d.renderer_thread, ts=20, duration=5, |
| 180 marker='Interaction.LogicalName/is_smooth') | 178 marker='Interaction.LogicalName') |
| 181 d.FinalizeImport() | 179 d.FinalizeImport() |
| 182 self.assertRaises(tbm_module.InvalidInteractions, d.AddResults) | 180 self.assertRaises(tbm_module.InvalidInteractions, d.AddResults) |
| 183 | 181 |
| 184 def testDuplicateRepeatableInteractions(self): | 182 def testDuplicateRepeatableInteractions(self): |
| 185 d = TimelineBasedMetricTestData() | 183 d = TimelineBasedMetricTestData() |
| 186 d.AddInteraction(d.renderer_thread, ts=10, duration=5, | 184 d.AddInteraction(d.renderer_thread, ts=10, duration=5, |
| 187 marker='Interaction.LogicalName/is_smooth,repeatable') | 185 marker='Interaction.LogicalName/repeatable') |
| 188 d.AddInteraction(d.renderer_thread, ts=20, duration=5, | 186 d.AddInteraction(d.renderer_thread, ts=20, duration=5, |
| 189 marker='Interaction.LogicalName/is_smooth,repeatable') | 187 marker='Interaction.LogicalName/repeatable') |
| 190 d.FinalizeImport() | 188 d.FinalizeImport() |
| 191 d.AddResults() | 189 d.AddResults() |
| 192 self.assertEquals(1, len(d.results.pages_that_succeeded)) | 190 self.assertEquals(1, len(d.results.pages_that_succeeded)) |
| 193 | 191 |
| 194 def testDuplicateRepeatableInteractionsWithDifferentMetrics(self): | |
| 195 d = TimelineBasedMetricTestData() | |
| 196 | |
| 197 responsive_marker = 'Interaction.LogicalName/repeatable' | |
| 198 d.AddInteraction( | |
| 199 d.renderer_thread, ts=10, duration=5, marker=responsive_marker) | |
| 200 smooth_marker = 'Interaction.LogicalName/is_smooth,repeatable' | |
| 201 d.AddInteraction(d.renderer_thread, ts=20, duration=5, marker=smooth_marker) | |
| 202 d.FinalizeImport() | |
| 203 self.assertRaises(tbm_module.InvalidInteractions, d.AddResults) | |
| 204 | |
| 205 | |
| 206 class TestTimelinebasedMeasurementPage(page_module.Page): | 192 class TestTimelinebasedMeasurementPage(page_module.Page): |
| 207 | 193 |
| 208 def __init__(self, ps, base_dir, trigger_animation=False, | 194 def __init__(self, ps, base_dir, trigger_animation=False, |
| 209 trigger_jank=False, trigger_slow=False): | 195 trigger_jank=False, trigger_slow=False): |
| 210 super(TestTimelinebasedMeasurementPage, self).__init__( | 196 super(TestTimelinebasedMeasurementPage, self).__init__( |
| 211 'file://interaction_enabled_page.html', ps, base_dir) | 197 'file://interaction_enabled_page.html', ps, base_dir) |
| 212 self._trigger_animation = trigger_animation | 198 self._trigger_animation = trigger_animation |
| 213 self._trigger_jank = trigger_jank | 199 self._trigger_jank = trigger_jank |
| 214 self._trigger_slow = trigger_slow | 200 self._trigger_slow = trigger_slow |
| 215 | 201 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 # Since window.performance.now() uses wall-time instead of thread time, | 259 # Since window.performance.now() uses wall-time instead of thread time, |
| 274 # we only assert the biggest jank > 50ms here to account for the fact | 260 # we only assert the biggest jank > 50ms here to account for the fact |
| 275 # that the browser may deschedule during the jank loop. | 261 # that the browser may deschedule during the jank loop. |
| 276 v = results.FindAllPageSpecificValuesNamed( | 262 v = results.FindAllPageSpecificValuesNamed( |
| 277 'JankThreadJSRun-responsive-biggest_jank_thread_time') | 263 'JankThreadJSRun-responsive-biggest_jank_thread_time') |
| 278 self.assertGreaterEqual(v[0].value, 50) | 264 self.assertGreaterEqual(v[0].value, 50) |
| 279 | 265 |
| 280 v = results.FindAllPageSpecificValuesNamed( | 266 v = results.FindAllPageSpecificValuesNamed( |
| 281 'JankThreadJSRun-responsive-total_big_jank_thread_time') | 267 'JankThreadJSRun-responsive-total_big_jank_thread_time') |
| 282 self.assertGreaterEqual(v[0].value, 50) | 268 self.assertGreaterEqual(v[0].value, 50) |
| OLD | NEW |