| 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 metrics import webrtc_stats | 7 from metrics import webrtc_stats |
| 8 from telemetry.unittest import simple_mock | 8 from telemetry.unittest import simple_mock |
| 9 | 9 |
| 10 | 10 |
| 11 SAMPLE_JSON = ''' | 11 SAMPLE_JSON = ''' |
| 12 [[ | 12 [[ |
| 13 [ | 13 [ |
| 14 { | 14 { |
| 15 "googFrameHeightInput":"480", | 15 "googFrameHeightInput":"480", |
| 16 "googFrameWidthInput":"640", | 16 "googFrameWidthInput":"640", |
| 17 "googFrameRateSent": "23", |
| 17 "packetsLost":"-1", | 18 "packetsLost":"-1", |
| 18 "googRtt":"-1", | 19 "googRtt":"-1", |
| 19 "packetsSent":"0", | 20 "packetsSent":"1", |
| 20 "bytesSent":"0" | 21 "bytesSent":"0" |
| 21 }, | 22 }, |
| 22 { | 23 { |
| 23 "audioInputLevel":"2048", | 24 "audioInputLevel":"2048", |
| 24 "googRtt":"-1", | 25 "googRtt":"-1", |
| 25 "googCodecName":"opus", | 26 "googCodecName":"opus", |
| 26 "packetsSent":"4", | 27 "packetsSent":"4", |
| 27 "bytesSent":"0" | 28 "bytesSent":"0" |
| 28 } | 29 } |
| 29 ], | 30 ], |
| 30 [ | 31 [ |
| 31 { | 32 { |
| 32 "googFrameHeightInput":"480", | 33 "googFrameHeightInput":"480", |
| 33 "googFrameWidthInput":"640", | 34 "googFrameWidthInput":"640", |
| 35 "googFrameRateSent": "21", |
| 34 "packetsLost":"-1", | 36 "packetsLost":"-1", |
| 35 "googRtt":"-1", | 37 "googRtt":"-1", |
| 36 "packetsSent":"8", | 38 "packetsSent":"8", |
| 37 "bytesSent":"6291" | 39 "bytesSent":"6291" |
| 38 }, | 40 }, |
| 39 { | 41 { |
| 40 "audioInputLevel":"1878", | 42 "audioInputLevel":"1878", |
| 41 "googRtt":"-1", | 43 "googRtt":"-1", |
| 42 "googCodecName":"opus", | 44 "googCodecName":"opus", |
| 43 "packetsSent":"16", | 45 "packetsSent":"16", |
| 44 "bytesSent":"634" | 46 "bytesSent":"634" |
| 45 } | 47 } |
| 46 ] | 48 ] |
| 47 ], | 49 ], |
| 48 [ | 50 [ |
| 49 [ | 51 [ |
| 50 { | 52 { |
| 53 "googFrameRateReceived": "23", |
| 51 "googDecodeMs":"0", | 54 "googDecodeMs":"0", |
| 52 "packetsReceived":"8", | 55 "packetsReceived":"8", |
| 53 "googRenderDelayMs":"10", | 56 "googRenderDelayMs":"10", |
| 54 "googMaxDecodeMs":"0" | 57 "googMaxDecodeMs":"0" |
| 55 } | 58 } |
| 56 ], | 59 ], |
| 57 [ | 60 [ |
| 58 { | 61 { |
| 62 "googFrameRateReceived": "23", |
| 59 "googDecodeMs":"14", | 63 "googDecodeMs":"14", |
| 60 "packetsReceived":"1234", | 64 "packetsReceived":"1234", |
| 61 "googRenderDelayMs":"102", | 65 "googRenderDelayMs":"102", |
| 62 "googMaxDecodeMs":"150" | 66 "googMaxDecodeMs":"150" |
| 63 } | 67 } |
| 64 ] | 68 ] |
| 65 ]] | 69 ]] |
| 66 ''' | 70 ''' |
| 67 | 71 |
| 68 | 72 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 results = FakeResults(page) | 105 results = FakeResults(page) |
| 102 stats_metric.AddResults(tab, results) | 106 stats_metric.AddResults(tab, results) |
| 103 return results | 107 return results |
| 104 | 108 |
| 105 def testExtractsValuesAsTimeSeries(self): | 109 def testExtractsValuesAsTimeSeries(self): |
| 106 results = self._RunMetricOnJson(SAMPLE_JSON) | 110 results = self._RunMetricOnJson(SAMPLE_JSON) |
| 107 | 111 |
| 108 self.assertTrue(results.received_values, | 112 self.assertTrue(results.received_values, |
| 109 'Expected values for googDecodeMs and others, got none.') | 113 'Expected values for googDecodeMs and others, got none.') |
| 110 | 114 |
| 111 # TODO(phoglund): this is actually a bug; make the metric clever enough to | 115 # This also ensures we're clever enough to tell video packetsSent from audio |
| 112 # distinguish packetsSent on audio from packetsSent on video, etc. | 116 # packetsSent. |
| 113 self.assertEqual(results.received_values[0].values, | 117 self.assertEqual(results.received_values[0].values, |
| 114 [0.0, 4.0, 8.0, 16.0]) | 118 [4.0, 16.0]) |
| 115 self.assertEqual(results.received_values[1].values, | 119 self.assertEqual(results.received_values[1].values, |
| 116 [8.0, 1234.0]) | 120 [1.0, 8.0]) |
| 117 | 121 |
| 118 def testExtractsInterestingMetricsOnly(self): | 122 def testExtractsInterestingMetricsOnly(self): |
| 119 results = self._RunMetricOnJson(SAMPLE_JSON) | 123 results = self._RunMetricOnJson(SAMPLE_JSON) |
| 120 | 124 |
| 121 self.assertEqual(len(results.received_values), 4) | 125 self.assertEqual(len(results.received_values), 5) |
| 122 self.assertEqual(results.received_values[0].name, | 126 self.assertEqual(results.received_values[0].name, |
| 123 'peer_connection_0_packets_sent', | 127 'peer_connection_0_audio_packets_sent', |
| 124 'The result should be a ListOfScalarValues instance with ' | 128 'The result should be a ListOfScalarValues instance with ' |
| 125 'a name <peer connection id>_<statistic>.') | 129 'a name <peer connection id>_<statistic>.') |
| 126 self.assertEqual(results.received_values[1].name, | 130 self.assertEqual(results.received_values[1].name, |
| 127 'peer_connection_1_packets_received') | 131 'peer_connection_0_video_packets_sent') |
| 128 self.assertEqual(results.received_values[2].name, | 132 self.assertEqual(results.received_values[2].name, |
| 129 'peer_connection_1_goog_decode_ms') | 133 'peer_connection_1_video_goog_max_decode_ms') |
| 130 self.assertEqual(results.received_values[3].name, | 134 self.assertEqual(results.received_values[3].name, |
| 131 'peer_connection_1_goog_max_decode_ms') | 135 'peer_connection_1_video_packets_received') |
| 136 self.assertEqual(results.received_values[4].name, |
| 137 'peer_connection_1_video_goog_decode_ms') |
| 132 | 138 |
| 133 def testReturnsIfJsonIsEmpty(self): | 139 def testReturnsIfJsonIsEmpty(self): |
| 134 results = self._RunMetricOnJson('[]') | 140 results = self._RunMetricOnJson('[]') |
| 135 self.assertFalse(results.received_values) | 141 self.assertFalse(results.received_values) |
| 136 | 142 |
| OLD | NEW |