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

Side by Side Diff: content/test/data/media/peerconnection-setConfiguration.html

Issue 2706563003: Create the API that returns the RTCConfiguration of the PeerConnection.
Patch Set: rebaselining 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 unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script>
4 <script type="text/javascript" src="webrtc_test_common.js"></script>
5 <script type="text/javascript">
6 $ = function(id) {
7 return document.getElementById(id);
8 };
9
10 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) {
11 failTest('Error: ' + errorMsg + '\nScript: ' + url +
12 '\nLine: ' + lineNumber + '\nColumn: ' + column +
13 '\nStackTrace: ' + errorObj);
14 }
15
16 var gPeerConnection = null;
17 var gCertificate = null;
18
19 // This test creates and sets three offers, calling setConfiguration in
20 // between each offer, expecting an ICE restart to be triggered by the next
21 // offer.
22 function testSetConfiguration() {
23 gPeerConnection = new RTCPeerConnection(
24 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
25 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:0});
26 // Change ICE candidate pool size, which will succeed before
27 // setLocalDescription is called.
28 gPeerConnection.setConfiguration(
29 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
30 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1});
31 // Now test successful cases of setConfiguration. Changes should trigger an
32 // ICE restart in the next offer. To do this, first we need to trigger an
33 // initial ICE gathering phase and wait until it completes.
34 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that
35 // instead of a "null" candidate.
36 gPeerConnection.onicecandidate = iceCandidateCallback1;
37 createOfferAndSetLocalDescription();
38 }
39
40 function iceCandidateCallback1(candidate) {
41 if (gPeerConnection.iceGatheringState === 'complete') {
42 gPeerConnection.onicecandidate = iceCandidateCallback2;
43 // Policy changed.
44 gPeerConnection.setConfiguration(
45 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced',
46 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1});
47 createOfferAndSetLocalDescription();
48 }
49 }
50
51 function iceCandidateCallback2(candidate) {
52 if (gPeerConnection.iceGatheringState === 'complete') {
53 gPeerConnection.onicecandidate = iceCandidateCallback3;
54 // Servers changed.
55 gPeerConnection.setConfiguration(
56 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all',
57 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[],
58 iceCandidatePoolSize:1});
59 createOfferAndSetLocalDescription();
60 }
61 }
62
63 function iceCandidateCallback3(candidate) {
64 // Only wait for 'gathering', since it will take a while for the requests to
65 // 'foo.invalid' to time out.
66 if (gPeerConnection.iceGatheringState === 'gathering') {
67 reportTestSuccess();
68 }
69 }
70
71 function testSetConfigurationErrors() {
72 // Generate certificate so we can test the InvalidModificationError from
73 // attempting to change certificates.
74 RTCPeerConnection.generateCertificate({ name:'ECDSA', namedCurve:'P-256' })
75 .then(function(certificate) {
76 gCertificate = certificate;
77 continueTestSetConfigurationErrors();
78 },
79 function() {
80 failTest('Failed to generate certificate.');
81 }
82 );
83 }
84
85 // Continued after certificate generated.
86 function continueTestSetConfigurationErrors() {
87 gPeerConnection = new RTCPeerConnection(
88 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
89 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1});
90 // If bundlePolicy, rtcpMuxPolicy or certificates are changed, an
91 // InvalidModificationError should be thrown.
92 assertThrows(gPeerConnection.setConfiguration,
93 {iceServers:[], iceTransportPolicy:'all',
94 bundlePolicy:'max-bundle', rtcpMuxPolicy:'require',
95 certificates:[], iceCandidatePoolSize:1});
96 assertThrows(gPeerConnection.setConfiguration,
97 {iceServers:[], iceTransportPolicy:'all',
98 bundlePolicy:'balanced', rtcpMuxPolicy:'negotiate',
99 certificates:[]});
100 assertThrows(gPeerConnection.setConfiguration,
101 {iceServers:[], iceTransportPolicy:'all',
102 bundlePolicy:'balanced', rtcpMuxPolicy:'require',
103 certificates:[gCertificate], iceCandidatePoolSize:1});
104 // Failure to parse URL should result in SyntaxError.
105 assertThrows(gPeerConnection.setConfiguration,
106 {iceServers:[{url:'stunnnn:foo.invalid'}],
107 iceTransportPolicy:'all', bundlePolicy:'max-bundle',
108 rtcpMuxPolicy:'require', certificates:[],
109 iceCandidatePoolSize:1});
110 // TURN server with missing username should result in InvalidAccessError.
111 assertThrows(gPeerConnection.setConfiguration,
112 {iceServers:[{url:'turn:foo.invalid'}],
113 iceTransportPolicy:'all', bundlePolicy:'max-bundle',
114 rtcpMuxPolicy:'require', certificates:[],
115 iceCandidatePoolSize:1});
116 // Sanity check that a configuration can be successfully set, and thus
117 // there's not something unexpected causing the above exceptions.
118 gPeerConnection.setConfiguration(
119 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
120 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1});
121 // Lastly: only after applying a local description, changing the candidate
122 // pool size is not allowed.
123 gPeerConnection.createOffer({offerToReceiveAudio:1})
124 .then(function(offer) {
125 console.log("Setting offer:\n" + offer.sdp);
126 gPeerConnection.setLocalDescription(offer).then(
127 function() {
128 // Pool size absent, which means it should default to 0, which is
129 // different than its current value of 1.
130 assertThrows(gPeerConnection.setConfiguration,
131 {iceServers:[], iceTransportPolicy:'all',
132 bundlePolicy:'balanced', rtcpMuxPolicy:'require',
133 certificates:[]});
134 reportTestSuccess();
135 },
136 function() { failTest('Failed to set local description.') }
137 );
138 },
139 function() {
140 failTest('Failed to generate offer.')
141 }
142 );
143 }
144
145 function assertThrows(func) {
146 try {
147 func.apply(arguments.slice(start=1));
148 failTest('Expected exception to be thrown by: ' + code);
149 } catch (e) {
150 }
151 }
152
153 // Helper function to create and apply offer.
154 function createOfferAndSetLocalDescription() {
155 gPeerConnection.createOffer({offerToReceiveAudio:1})
156 .then(function(offer) {
157 console.log("Setting offer:\n" + offer.sdp);
158 gPeerConnection.setLocalDescription(offer).then(
159 function() {},
160 function() { failTest('Failed to set local description.') }
161 );
162 },
163 function() {
164 failTest('Failed to generate offer.')
165 }
166 );
167 }
168
169 </script>
170 </head>
171 <body>
172 </body>
173 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698