Change next_proto member type.
[chromium-blink-merge.git] / tools / perf / metrics / webrtc_stats_unittest.py
blob066f105ccc073eaee8ddb40ca6c345c338b862e6
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
3 # found in the LICENSE file.
5 import unittest
7 from metrics import webrtc_stats
8 from telemetry.unittest_util import simple_mock
11 SAMPLE_JSON = '''
15 "googFrameHeightInput":"480",
16 "googFrameWidthInput":"640",
17 "googFrameRateSent": "23",
18 "packetsLost":"-1",
19 "googRtt":"-1",
20 "packetsSent":"1",
21 "bytesSent":"0"
24 "audioInputLevel":"2048",
25 "googRtt":"-1",
26 "googCodecName":"opus",
27 "packetsSent":"4",
28 "bytesSent":"0"
33 "googFrameHeightInput":"480",
34 "googFrameWidthInput":"640",
35 "googFrameRateSent": "21",
36 "packetsLost":"-1",
37 "googRtt":"-1",
38 "packetsSent":"8",
39 "bytesSent":"6291"
42 "audioInputLevel":"1878",
43 "googRtt":"-1",
44 "googCodecName":"opus",
45 "packetsSent":"16",
46 "bytesSent":"634"
53 "googFrameRateReceived": "23",
54 "googDecodeMs":"0",
55 "packetsReceived":"8",
56 "googRenderDelayMs":"10",
57 "googMaxDecodeMs":"0"
62 "googFrameRateReceived": "23",
63 "googDecodeMs":"14",
64 "packetsReceived":"1234",
65 "googRenderDelayMs":"102",
66 "googMaxDecodeMs":"150"
70 '''
73 class FakeResults:
74 def __init__(self, current_page):
75 self._received_values = []
76 self._current_page = current_page
78 @property
79 def received_values(self):
80 return self._received_values
82 @property
83 def current_page(self):
84 return self._current_page
86 def AddValue(self, value):
87 self._received_values.append(value)
90 class WebRtcStatsUnittest(unittest.TestCase):
92 def _RunMetricOnJson(self, json_to_return):
93 stats_metric = webrtc_stats.WebRtcStatisticsMetric()
95 tab = simple_mock.MockObject()
96 page = simple_mock.MockObject()
98 stats_metric.Start(page, tab)
100 tab.ExpectCall('EvaluateJavaScript',
101 simple_mock.DONT_CARE).WillReturn(json_to_return)
102 stats_metric.Stop(page, tab)
104 page.url = simple_mock.MockObject()
105 results = FakeResults(page)
106 stats_metric.AddResults(tab, results)
107 return results
109 def testExtractsValuesAsTimeSeries(self):
110 results = self._RunMetricOnJson(SAMPLE_JSON)
112 self.assertTrue(results.received_values,
113 'Expected values for googDecodeMs and others, got none.')
115 # This also ensures we're clever enough to tell video packetsSent from audio
116 # packetsSent.
117 self.assertEqual(results.received_values[0].values,
118 [4.0, 16.0])
119 self.assertEqual(results.received_values[1].values,
120 [1.0, 8.0])
122 def testExtractsInterestingMetricsOnly(self):
123 results = self._RunMetricOnJson(SAMPLE_JSON)
125 self.assertEqual(len(results.received_values), 5)
126 self.assertEqual(results.received_values[0].name,
127 'peer_connection_0_audio_packets_sent',
128 'The result should be a ListOfScalarValues instance with '
129 'a name <peer connection id>_<statistic>.')
130 self.assertEqual(results.received_values[1].name,
131 'peer_connection_0_video_packets_sent')
132 self.assertEqual(results.received_values[2].name,
133 'peer_connection_1_video_goog_max_decode_ms')
134 self.assertEqual(results.received_values[3].name,
135 'peer_connection_1_video_packets_received')
136 self.assertEqual(results.received_values[4].name,
137 'peer_connection_1_video_goog_decode_ms')
139 def testReturnsIfJsonIsEmpty(self):
140 results = self._RunMetricOnJson('[]')
141 self.assertFalse(results.received_values)