| 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 unittest | 5 import unittest |
| 6 | 6 |
| 7 from telemetry.testing import simple_mock | 7 from telemetry.testing import simple_mock |
| 8 | 8 |
| 9 from metrics import webrtc_stats | 9 from metrics import webrtc_stats |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 @property | 100 @property |
| 101 def current_page(self): | 101 def current_page(self): |
| 102 return self._current_page | 102 return self._current_page |
| 103 | 103 |
| 104 def AddValue(self, value): | 104 def AddValue(self, value): |
| 105 self._received_values.append(value) | 105 self._received_values.append(value) |
| 106 | 106 |
| 107 | 107 |
| 108 class WebRtcStatsUnittest(unittest.TestCase): | 108 class WebRtcStatsUnittest(unittest.TestCase): |
| 109 | 109 |
| 110 def _RunMetricOnJson(self, json_to_return): | 110 def _RunMetricOnJson(self, json_to_return, stats_metric): |
| 111 stats_metric = webrtc_stats.WebRtcStatisticsMetric() | |
| 112 | |
| 113 tab = simple_mock.MockObject() | 111 tab = simple_mock.MockObject() |
| 114 page = simple_mock.MockObject() | 112 page = simple_mock.MockObject() |
| 115 | 113 |
| 116 stats_metric.Start(page, tab) | 114 stats_metric.Start(page, tab) |
| 117 | 115 |
| 118 tab.ExpectCall('EvaluateJavaScript', | 116 tab.ExpectCall('EvaluateJavaScript', |
| 119 simple_mock.DONT_CARE).WillReturn(json_to_return) | 117 simple_mock.DONT_CARE).WillReturn(json_to_return) |
| 120 stats_metric.Stop(page, tab) | 118 stats_metric.Stop(page, tab) |
| 121 | 119 |
| 122 page.url = simple_mock.MockObject() | 120 page.url = simple_mock.MockObject() |
| 123 results = FakeResults(page) | 121 results = FakeResults(page) |
| 124 stats_metric.AddResults(tab, results) | 122 stats_metric.AddResults(tab, results) |
| 125 return results | 123 return results |
| 126 | 124 |
| 127 def testExtractsValuesAsTimeSeries(self): | 125 def testExtractsValuesAsTimeSeries(self): |
| 128 results = self._RunMetricOnJson(SAMPLE_JSON) | 126 stats_metric = webrtc_stats.WebRtcStatisticsMetric() |
| 127 results = self._RunMetricOnJson(SAMPLE_JSON, stats_metric) |
| 129 | 128 |
| 130 self.assertTrue(results.received_values, | 129 self.assertTrue(results.received_values, |
| 131 'Expected values for googDecodeMs and others, got none.') | 130 'Expected values for googDecodeMs and others, got none.') |
| 132 self.assertEqual(results.received_values[1].name, | 131 self.assertEqual(results.received_values[1].name, |
| 133 'peer_connection_0_audio_goog_rtt') | 132 'peer_connection_0_audio_goog_rtt') |
| 134 self.assertEqual(results.received_values[1].values, | 133 self.assertEqual(results.received_values[1].values, |
| 135 [20.0, 17.0]) | 134 [20.0, 17.0]) |
| 136 self.assertEqual(results.received_values[7].name, | 135 self.assertEqual(results.received_values[7].name, |
| 137 'peer_connection_1_video_goog_rtt') | 136 'peer_connection_1_video_goog_rtt') |
| 138 self.assertEqual(results.received_values[7].values, | 137 self.assertEqual(results.received_values[7].values, |
| 139 [100.0, 101.0]) | 138 [100.0, 101.0]) |
| 140 | 139 |
| 141 def testExtractsInterestingMetricsOnly(self): | 140 def testExtractsInterestingMetricsOnly(self): |
| 142 results = self._RunMetricOnJson(SAMPLE_JSON) | 141 stats_metric = webrtc_stats.WebRtcStatisticsMetric() |
| 142 results = self._RunMetricOnJson(SAMPLE_JSON, stats_metric) |
| 143 | 143 |
| 144 self.assertTrue(len(results.received_values) > 0) | 144 self.assertTrue(len(results.received_values) > 0) |
| 145 self.assertIn('peer_connection_0', results.received_values[0].name, | 145 self.assertIn('peer_connection_0', results.received_values[0].name, |
| 146 'The result should be a ListOfScalarValues instance with ' | 146 'The result should be a ListOfScalarValues instance with ' |
| 147 'a name <peer connection id>_<statistic>.') | 147 'a name <peer connection id>_<statistic>.') |
| 148 all_names = [value.name for value in results.received_values] | 148 all_names = [value.name for value in results.received_values] |
| 149 self.assertIn('peer_connection_0_audio_goog_rtt', all_names) | 149 self.assertIn('peer_connection_0_audio_goog_rtt', all_names) |
| 150 self.assertNotIn('peer_connection_1_audio_goog_rtt', all_names, | 150 self.assertNotIn('peer_connection_1_audio_goog_rtt', all_names, |
| 151 'Peer connection 1 does not have a goog-rtt in ' | 151 'Peer connection 1 does not have a goog-rtt in ' |
| 152 'the JSON above, unlike peer connection 0 which does.') | 152 'the JSON above, unlike peer connection 0 which does.') |
| 153 self.assertIn('peer_connection_0_video_goog_rtt', all_names) | 153 self.assertIn('peer_connection_0_video_goog_rtt', all_names) |
| 154 self.assertIn('peer_connection_1_video_goog_rtt', all_names) | 154 self.assertIn('peer_connection_1_video_goog_rtt', all_names) |
| 155 # The audio_audio is intentional since the code distinguishes audio reports | 155 # The audio_audio is intentional since the code distinguishes audio reports |
| 156 # from video reports (even though audio_input_level is quite obvious). | 156 # from video reports (even though audio_input_level is quite obvious). |
| 157 self.assertNotIn('peer_connection_0_audio_audio_input_level', all_names, | 157 self.assertNotIn('peer_connection_0_audio_audio_input_level', all_names, |
| 158 'Input level is in the JSON for both connections but ' | 158 'Input level is in the JSON for both connections but ' |
| 159 'should not be reported since it is not interesting.') | 159 'should not be reported since it is not interesting.') |
| 160 self.assertNotIn('peer_connection_1_audio_audio_input_level', all_names) | 160 self.assertNotIn('peer_connection_1_audio_audio_input_level', all_names) |
| 161 | 161 |
| 162 def testExtractsParticularMetricsOnlyIfSpecified(self): |
| 163 only_goog_rtt_and_max_decode = ['googRtt', 'googMaxDecodeMs'] |
| 164 stats_metric = webrtc_stats.WebRtcStatisticsMetric( |
| 165 particular_metrics=only_goog_rtt_and_max_decode) |
| 166 results = self._RunMetricOnJson(SAMPLE_JSON, stats_metric) |
| 167 |
| 168 received_names = [value.name for value in results.received_values] |
| 169 expected_names = ['peer_connection_0_audio_goog_rtt', |
| 170 'peer_connection_0_video_goog_rtt', |
| 171 'peer_connection_1_video_goog_max_decode_ms', |
| 172 'peer_connection_1_video_goog_rtt'] |
| 173 self.assertEqual(expected_names, received_names) |
| 174 |
| 162 def testReturnsIfJsonIsEmpty(self): | 175 def testReturnsIfJsonIsEmpty(self): |
| 163 results = self._RunMetricOnJson('[]') | 176 stats_metric = webrtc_stats.WebRtcStatisticsMetric() |
| 177 results = self._RunMetricOnJson('[]', stats_metric) |
| 164 self.assertFalse(results.received_values) | 178 self.assertFalse(results.received_values) |
| OLD | NEW |