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

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

Issue 2631433002: Rename RTCPeerConnection.updateIce to setConfiguration and make it work. (Closed)
Patch Set: Rebase. Created 3 years, 10 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:[]});
26 // Now test successful cases of setConfiguration. Changes should trigger an
27 // ICE restart in the next offer. To do this, first we need to trigger an
28 // initial ICE gathering phase and wait until it completes.
29 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that
30 // instead of a "null" candidate.
31 gPeerConnection.onicecandidate = iceCandidateCallback1;
32 createOfferAndSetLocalDescription();
33 }
34
35 function iceCandidateCallback1(candidate) {
36 if (gPeerConnection.iceGatheringState === 'complete') {
37 gPeerConnection.onicecandidate = iceCandidateCallback2;
38 // Policy changed.
39 gPeerConnection.setConfiguration(
40 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced',
41 rtcpMuxPolicy:'require', certificates:[]});
42 createOfferAndSetLocalDescription();
43 }
44 }
45
46 function iceCandidateCallback2(candidate) {
47 if (gPeerConnection.iceGatheringState === 'complete') {
48 gPeerConnection.onicecandidate = iceCandidateCallback3;
49 // Servers changed.
50 gPeerConnection.setConfiguration(
51 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all',
52 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[]});
53 createOfferAndSetLocalDescription();
54 }
55 }
56
57 function iceCandidateCallback3(candidate) {
58 // Only wait for 'gathering', since it will take a while for the requests to
59 // 'foo.invalid' to time out.
60 if (gPeerConnection.iceGatheringState === 'gathering') {
61 reportTestSuccess();
62 }
63 }
64
65 function testSetConfigurationErrors() {
66 // Generate certificate so we can test the InvalidModificationError from
67 // attempting to change certificates.
68 RTCPeerConnection.generateCertificate({ name:'ECDSA', namedCurve:'P-256' })
69 .then(function(certificate) {
70 gCertificate = certificate;
71 continueTestSetConfigurationErrors();
72 },
73 function() {
74 failTest('Failed to generate certificate.');
75 }
76 );
77 }
78
79 // Continued after certificate generated.
80 function continueTestSetConfigurationErrors() {
81 gPeerConnection = new RTCPeerConnection(
82 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
83 rtcpMuxPolicy:'require', certificates:[]});
84 // If bundlePolicy, rtcpMuxPolicy or certificates are changed, an
85 // InvalidModificationError should be thrown.
86 assertThrows(gPeerConnection.setConfiguration,
87 {iceServers:[], iceTransportPolicy:'all',
88 bundlePolicy:'max-bundle', rtcpMuxPolicy:'require',
89 certificates:[]});
90 assertThrows(gPeerConnection.setConfiguration,
91 {iceServers:[], iceTransportPolicy:'all',
92 bundlePolicy:'balanced', rtcpMuxPolicy:'negotiate',
93 certificates:[]});
94 assertThrows(gPeerConnection.setConfiguration,
95 {iceServers:[], iceTransportPolicy:'all',
96 bundlePolicy:'balanced', rtcpMuxPolicy:'require',
97 certificates:[gCertificate]});
98 // Failure to parse URL should result in SyntaxError.
99 assertThrows(gPeerConnection.setConfiguration,
100 {iceServers:[{url:'stunnnn:foo.invalid'}],
101 iceTransportPolicy:'all', bundlePolicy:'max-bundle',
102 rtcpMuxPolicy:'require', certificates:[]});
103 // TURN server with missing username should result in InvalidAccessError.
104 assertThrows(gPeerConnection.setConfiguration,
105 {iceServers:[{url:'turn:foo.invalid'}],
106 iceTransportPolicy:'all', bundlePolicy:'max-bundle',
107 rtcpMuxPolicy:'require', certificates:[]});
108 // Sanity check that a configuration can be successfully set, and thus
109 // there's not something unexpected causing the above exceptions.
110 gPeerConnection.setConfiguration(
111 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced',
112 rtcpMuxPolicy:'require', certificates:[]});
113 reportTestSuccess();
114 }
115
116 function assertThrows(func) {
117 try {
118 func.apply(arguments.slice(start=1));
119 failTest('Expected exception to be thrown by: ' + code);
120 } catch (e) {
121 }
122 }
123
124 // Helper function to create and apply offer.
125 function createOfferAndSetLocalDescription() {
126 gPeerConnection.createOffer({offerToReceiveAudio:1})
127 .then(function(offer) {
128 console.log("Setting offer:\n" + offer.sdp);
129 gPeerConnection.setLocalDescription(offer).then(
130 function() {},
131 function() { failTest('Failed to set local description.') }
132 );
133 },
134 function() {
135 failTest('Failed to generate offer.')
136 }
137 );
138 }
139
140 </script>
141 </head>
142 <body>
143 </body>
144 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698