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

Unified Diff: tools/perf/page_sets/webrtc_cases/multiple-peerconnections.js

Issue 2761163003: Use local pages for webrtc telemetry tests. (Closed)
Patch Set: Exclude all of webrtc_cases in PRESUBMIT.py and add a comment explaining it is because these are te… Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: tools/perf/page_sets/webrtc_cases/multiple-peerconnections.js
diff --git a/tools/perf/page_sets/webrtc_cases/multiple-peerconnections.js b/tools/perf/page_sets/webrtc_cases/multiple-peerconnections.js
new file mode 100644
index 0000000000000000000000000000000000000000..4401d10bd24937f23ce03c23a8a19e15137b583a
--- /dev/null
+++ b/tools/perf/page_sets/webrtc_cases/multiple-peerconnections.js
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2017 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+/*jshint esversion: 6 */
+
+'use strict';
+
+var $ = document.getElementById.bind(document);
+
+var testTable = $('test-table');
+var nPeerConnectionsInput = $('num-peerconnections');
+var startTestButton = $('start-test');
+var cpuOveruseDetectionCheckbox = $('cpuoveruse-detection');
+
+startTestButton.onclick = startTest;
+
+function logError(err) {
+ console.err(err);
+}
+
+function addNewVideoElement() {
+ var newRow = testTable.insertRow(-1);
+ var newCell = newRow.insertCell(-1);
+ var video = document.createElement('video');
+ video.autoplay = true;
+ newCell.appendChild(video);
+ return video;
+}
+
+function PeerConnection(id, cpuOveruseDetection) {
+ this.id = id;
+ this.cpuOveruseDetection = cpuOveruseDetection;
+
+ this.localConnection = null;
+ this.remoteConnection = null;
+
+ this.remoteView = addNewVideoElement();
+
+ this.start = function() {
+ var onGetUserMediaSuccess = this.onGetUserMediaSuccess.bind(this);
+ navigator.mediaDevices.getUserMedia({
+ audio: true,
+ video: true
+ })
+ .then(onGetUserMediaSuccess)
+ .catch(logError);
+ };
+
+ this.onGetUserMediaSuccess = function(stream) {
+ // Create local peer connection.
+ this.localConnection = new RTCPeerConnection(null, {
+ 'optional': [{
+ 'googCpuOveruseDetection': this.cpuOveruseDetection
+ }]
+ });
+ this.localConnection.onicecandidate = (event) => {
+ this.onIceCandidate(this.remoteConnection, event);
+ };
+ this.localConnection.addStream(stream);
+
+ // Create remote peer connection.
+ this.remoteConnection = new RTCPeerConnection(null, {
+ 'optional': [{
+ 'googCpuOveruseDetection': this.cpuOveruseDetection
+ }]
+ });
+ this.remoteConnection.onicecandidate = (event) => {
+ this.onIceCandidate(this.localConnection, event);
+ };
+ this.remoteConnection.onaddstream = (e) => {
+ this.remoteView.srcObject = e.stream;
+ };
+
+ // Initiate call.
+ var onCreateOfferSuccess = this.onCreateOfferSuccess.bind(this);
+ this.localConnection.createOffer({
+ offerToReceiveAudio: 1,
+ offerToReceiveVideo: 1
+ })
+ .then(onCreateOfferSuccess, logError);
+ };
+
+ this.onCreateOfferSuccess = function(desc) {
+ this.localConnection.setLocalDescription(desc);
+ this.remoteConnection.setRemoteDescription(desc);
+
+ var onCreateAnswerSuccess = this.onCreateAnswerSuccess.bind(this);
+ this.remoteConnection.createAnswer()
+ .then(onCreateAnswerSuccess, logError);
+ };
+
+ this.onCreateAnswerSuccess = function(desc) {
+ this.remoteConnection.setLocalDescription(desc);
+ this.localConnection.setRemoteDescription(desc);
+ };
+
+ this.onIceCandidate = function(connection, event) {
+ if (event.candidate) {
+ connection.addIceCandidate(new RTCIceCandidate(event.candidate));
+ }
+ };
+}
+
+function startTest() {
+ var cpuOveruseDetection = cpuOveruseDetectionCheckbox.checked;
+ var nPeerConnections = nPeerConnectionsInput.value;
+ for (var i = 0; i < nPeerConnections; ++i) {
+ new PeerConnection(i, cpuOveruseDetection).start();
+ }
+}
« no previous file with comments | « tools/perf/page_sets/webrtc_cases/multiple-peerconnections.html ('k') | tools/perf/page_sets/webrtc_cases/resolution.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698