Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: tools/perf/metrics/webrtc_stats_unittest.py

Issue 561803002: Implements peer connection stats measurements in WebRTC call test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@telemetry
Patch Set: Now tracking peer connections for all webrtc pages. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 import unittest
6
7 from metrics import webrtc_stats
8 from telemetry.unittest import simple_mock
9
10
11 SAMPLE_JSON = '''
12 [[
13 [
14 {
15 "googFrameHeightInput":"480",
16 "googFrameWidthInput":"640",
17 "packetsLost":"-1",
18 "googRtt":"-1",
19 "packetsSent":"0",
20 "bytesSent":"0"
21 },
22 {
23 "audioInputLevel":"2048",
24 "googRtt":"-1",
25 "googCodecName":"opus",
26 "packetsSent":"4",
27 "bytesSent":"0"
28 }
29 ],
30 [
31 {
32 "googFrameHeightInput":"480",
33 "googFrameWidthInput":"640",
34 "packetsLost":"-1",
35 "googRtt":"-1",
36 "packetsSent":"8",
37 "bytesSent":"6291"
38 },
39 {
40 "audioInputLevel":"1878",
41 "googRtt":"-1",
42 "googCodecName":"opus",
43 "packetsSent":"16",
44 "bytesSent":"634"
45 }
46 ]
47 ],
48 [
49 [
50 {
51 "googDecodeMs":"0",
52 "packetsReceived":"8",
53 "googRenderDelayMs":"10",
54 "googMaxDecodeMs":"0"
55 }
56 ],
57 [
58 {
59 "googDecodeMs":"14",
60 "packetsReceived":"1234",
61 "googRenderDelayMs":"102",
62 "googMaxDecodeMs":"150"
63 }
64 ]
65 ]]
66 '''
67
68
69 class FakeResults:
70 def __init__(self, current_page):
71 self._received_values = []
72 self._current_page = current_page
73
74 @property
75 def received_values(self):
76 return self._received_values
77
78 @property
79 def current_page(self):
80 return self._current_page
81
82 def AddValue(self, value):
83 self._received_values.append(value)
84
85
86 class WebRtcStatsUnittest(unittest.TestCase):
87
88 def _RunMetricOnJson(self, json_to_return):
89 stats_metric = webrtc_stats.WebRtcStatisticsMetric()
90
91 tab = simple_mock.MockObject()
92 page = simple_mock.MockObject()
93
94 stats_metric.Start(page, tab)
95
96 tab.ExpectCall('EvaluateJavaScript',
97 simple_mock.DONT_CARE).WillReturn(json_to_return)
98 stats_metric.Stop(page, tab)
99
100 page.url = simple_mock.MockObject()
101 results = FakeResults(page)
102 stats_metric.AddResults(tab, results)
103 return results
104
105 def testExtractsValuesAsTimeSeries(self):
106 results = self._RunMetricOnJson(SAMPLE_JSON)
107
108 self.assertTrue(results.received_values,
109 'Expected values for googDecodeMs and others, got none.')
110
111 # TODO(phoglund): this is actually a bug; make the metric clever enough to
112 # distinguish packetsSent on audio from packetsSent on video, etc.
113 self.assertEqual(results.received_values[0].values,
114 [0.0, 4.0, 8.0, 16.0])
115 self.assertEqual(results.received_values[1].values,
116 [8.0, 1234.0])
117
118 def testExtractsInterestingMetricsOnly(self):
119 results = self._RunMetricOnJson(SAMPLE_JSON)
120
121 self.assertEqual(len(results.received_values), 4)
122 self.assertEqual(results.received_values[0].name,
123 'peer_connection_0_packets_sent',
124 'The result should be a ListOfScalarValues instance with '
125 'a name <peer connection id>_<statistic>.')
126 self.assertEqual(results.received_values[1].name,
127 'peer_connection_1_packets_received')
128 self.assertEqual(results.received_values[2].name,
129 'peer_connection_1_goog_decode_ms')
130 self.assertEqual(results.received_values[3].name,
131 'peer_connection_1_goog_max_decode_ms')
132
133 def testReturnsIfJsonIsEmpty(self):
134 results = self._RunMetricOnJson('[]')
135 self.assertFalse(results.received_values)
136
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698