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.
7 from metrics
import webrtc_stats
8 from telemetry
.unittest_util
import simple_mock
15 "googFrameHeightInput":"480",
16 "googFrameWidthInput":"640",
17 "googFrameRateSent": "23",
24 "audioInputLevel":"2048",
26 "googCodecName":"opus",
33 "googFrameHeightInput":"480",
34 "googFrameWidthInput":"640",
35 "googFrameRateSent": "21",
42 "audioInputLevel":"1878",
44 "googCodecName":"opus",
53 "googFrameRateReceived": "23",
55 "packetsReceived":"8",
56 "googRenderDelayMs":"10",
62 "googFrameRateReceived": "23",
64 "packetsReceived":"1234",
65 "googRenderDelayMs":"102",
66 "googMaxDecodeMs":"150"
74 def __init__(self
, current_page
):
75 self
._received
_values
= []
76 self
._current
_page
= current_page
79 def received_values(self
):
80 return self
._received
_values
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
)
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
117 self
.assertEqual(results
.received_values
[0].values
,
119 self
.assertEqual(results
.received_values
[1].values
,
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
)