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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media/webrtc/webrtc_browsertest_base.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webrtc/peerconnection_getstats.js
diff --git a/chrome/test/data/webrtc/peerconnection_getstats.js b/chrome/test/data/webrtc/peerconnection_getstats.js
index 9258a3656f768a57bb8905d10787190ccaa162a8..6062daa4970f9d1a724aa572a71b4c1e3b0caf71 100644
--- a/chrome/test/data/webrtc/peerconnection_getstats.js
+++ b/chrome/test/data/webrtc/peerconnection_getstats.js
@@ -4,14 +4,34 @@
* found in the LICENSE file.
*/
+var kExpectedStats = [
hta - Chromium 2016/11/24 15:45:00 Naming nits: I'd call this "kMustHaveStats" (could
+ 'certificate',
+ 'codec',
+ 'candidate-pair',
+ 'local-candidate',
+ 'remote-candidate',
+ 'stream',
+ 'track',
+ 'peer-connection',
+ 'inbound-rtp',
+ 'outbound-rtp',
+ 'transport',
+];
+// TODO(hbos): Update browser test to include data channels and make this
+// mandatory. crbug.com/627816
+var kOptionalStats = [
+ 'data-channel',
+];
+
// Public interface to tests. These are expected to be called with
// ExecuteJavascript invocations from the browser tests and will return answers
// through the DOM automation controller.
/**
- * Verifies that the promise-based |RTCPeerConnection.getStats| returns stats.
+ * Verifies that the promise-based |RTCPeerConnection.getStats| returns all
+ * expected stats and no unexpected stats.
*
- * Returns ok-got-stats on success.
+ * Returns ok-expected-stats on success.
*/
function verifyStatsGeneratedPromise() {
peerConnection_().getStats()
@@ -19,26 +39,47 @@ function verifyStatsGeneratedPromise() {
if (report == null || report.size == 0)
throw new failTest('report is null or empty.');
// Sanity check that applies to all stats.
- var ids = new Set();
- report.forEach(function(stats) {
+ let ids = new Set();
+ let expected = new Set(kExpectedStats);
+ let optional = new Set(kOptionalStats);
+ let missing_expected = new Set(kExpectedStats);
+ let unexpected = new Set();
+ for (let stats of report.values()) {
if (typeof(stats.id) !== 'string')
throw failTest('stats.id is not a string.');
if (ids.has(stats.id))
throw failTest('stats.id is not a unique identifier.');
ids.add(stats.id);
- if (typeof(stats.timestamp) !== 'number' || stats.timestamp <= 0)
- throw failTest('stats.timestamp is not a positive number.');
+ if (typeof(stats.timestamp) !== 'number' ||
+ !isFinite(stats.timestamp) || stats.timestamp <= 0) {
+ throw failTest('stats.timestamp is not a positive finite number.');
+ }
if (typeof(stats.type) !== 'string')
throw failTest('stats.type is not a string.');
- });
- // TODO(hbos): When the new stats collection API is more mature (and
- // certainly before unflagging the new stats API) add a whitelist of
- // allowed stats to prevent accidentally exposing stats to the web that
- // are not in the spec and that verifies type information. Status at
- // crbug.com/627816. Stats collection is tested in the WebRTC repo and
- // automatically surfaced to Blink, but there should be a process of
- // having to land a Blink CL in order to expose a new RTCStats dictionary.
- returnToTest('ok-got-stats');
+
+ if (expected.has(stats.type)) {
+ missing_expected.delete(stats.type);
+ } else if (!optional.has(stats.type)) {
+ unexpected.add(stats.type);
+ }
+ }
+ if (missing_expected.size > 0 || unexpected.size > 0) {
+ // Log all stats before throwing exception.
+ var all_stats = [];
+ for (let stats of report.values()) {
+ all_stats.push(stats);
+ }
+ console.log('RTCStatsReport: ' + JSON.stringify(all_stats, null, ' '));
+ if (missing_expected.size > 0) {
+ throw new failTest('Missing stats of type: ' +
+ Array.from(missing_expected.values()));
+ }
+ if (unexpected.size > 0) {
+ throw new failTest('Unexpected stats of type: ' +
+ Array.from(unexpected.values()));
+ }
+ }
+ returnToTest('ok-expected-stats');
},
function(e) {
throw failTest('Promise was rejected: ' + e);
« 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