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

Side by Side Diff: chrome/test/data/webrtc/peerconnection_getstats.js

Issue 2530873002: Expected stats list added to promise-based getStats WebRtcBrowserTest. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « chrome/browser/media/webrtc/webrtc_browsertest_base.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright 2016 The Chromium Authors. All rights reserved. 2 * Copyright 2016 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 var kExpectedStats = [
hta - Chromium 2016/11/24 15:45:00 Naming nits: I'd call this "kMustHaveStats" (could
8 'certificate',
9 'codec',
10 'candidate-pair',
11 'local-candidate',
12 'remote-candidate',
13 'stream',
14 'track',
15 'peer-connection',
16 'inbound-rtp',
17 'outbound-rtp',
18 'transport',
19 ];
20 // TODO(hbos): Update browser test to include data channels and make this
21 // mandatory. crbug.com/627816
22 var kOptionalStats = [
23 'data-channel',
24 ];
25
7 // Public interface to tests. These are expected to be called with 26 // Public interface to tests. These are expected to be called with
8 // ExecuteJavascript invocations from the browser tests and will return answers 27 // ExecuteJavascript invocations from the browser tests and will return answers
9 // through the DOM automation controller. 28 // through the DOM automation controller.
10 29
11 /** 30 /**
12 * Verifies that the promise-based |RTCPeerConnection.getStats| returns stats. 31 * Verifies that the promise-based |RTCPeerConnection.getStats| returns all
32 * expected stats and no unexpected stats.
13 * 33 *
14 * Returns ok-got-stats on success. 34 * Returns ok-expected-stats on success.
15 */ 35 */
16 function verifyStatsGeneratedPromise() { 36 function verifyStatsGeneratedPromise() {
17 peerConnection_().getStats() 37 peerConnection_().getStats()
18 .then(function(report) { 38 .then(function(report) {
19 if (report == null || report.size == 0) 39 if (report == null || report.size == 0)
20 throw new failTest('report is null or empty.'); 40 throw new failTest('report is null or empty.');
21 // Sanity check that applies to all stats. 41 // Sanity check that applies to all stats.
22 var ids = new Set(); 42 let ids = new Set();
23 report.forEach(function(stats) { 43 let expected = new Set(kExpectedStats);
44 let optional = new Set(kOptionalStats);
45 let missing_expected = new Set(kExpectedStats);
46 let unexpected = new Set();
47 for (let stats of report.values()) {
24 if (typeof(stats.id) !== 'string') 48 if (typeof(stats.id) !== 'string')
25 throw failTest('stats.id is not a string.'); 49 throw failTest('stats.id is not a string.');
26 if (ids.has(stats.id)) 50 if (ids.has(stats.id))
27 throw failTest('stats.id is not a unique identifier.'); 51 throw failTest('stats.id is not a unique identifier.');
28 ids.add(stats.id); 52 ids.add(stats.id);
29 if (typeof(stats.timestamp) !== 'number' || stats.timestamp <= 0) 53 if (typeof(stats.timestamp) !== 'number' ||
30 throw failTest('stats.timestamp is not a positive number.'); 54 !isFinite(stats.timestamp) || stats.timestamp <= 0) {
55 throw failTest('stats.timestamp is not a positive finite number.');
56 }
31 if (typeof(stats.type) !== 'string') 57 if (typeof(stats.type) !== 'string')
32 throw failTest('stats.type is not a string.'); 58 throw failTest('stats.type is not a string.');
33 }); 59
34 // TODO(hbos): When the new stats collection API is more mature (and 60 if (expected.has(stats.type)) {
35 // certainly before unflagging the new stats API) add a whitelist of 61 missing_expected.delete(stats.type);
36 // allowed stats to prevent accidentally exposing stats to the web that 62 } else if (!optional.has(stats.type)) {
37 // are not in the spec and that verifies type information. Status at 63 unexpected.add(stats.type);
38 // crbug.com/627816. Stats collection is tested in the WebRTC repo and 64 }
39 // automatically surfaced to Blink, but there should be a process of 65 }
40 // having to land a Blink CL in order to expose a new RTCStats dictionary. 66 if (missing_expected.size > 0 || unexpected.size > 0) {
41 returnToTest('ok-got-stats'); 67 // Log all stats before throwing exception.
68 var all_stats = [];
69 for (let stats of report.values()) {
70 all_stats.push(stats);
71 }
72 console.log('RTCStatsReport: ' + JSON.stringify(all_stats, null, ' '));
73 if (missing_expected.size > 0) {
74 throw new failTest('Missing stats of type: ' +
75 Array.from(missing_expected.values()));
76 }
77 if (unexpected.size > 0) {
78 throw new failTest('Unexpected stats of type: ' +
79 Array.from(unexpected.values()));
80 }
81 }
82 returnToTest('ok-expected-stats');
42 }, 83 },
43 function(e) { 84 function(e) {
44 throw failTest('Promise was rejected: ' + e); 85 throw failTest('Promise was rejected: ' + e);
45 }); 86 });
46 } 87 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/webrtc_browsertest_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698