OLD | NEW |
---|---|
(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 | |
perkj_chrome
2017/01/17 09:08:01
? void RTCPeerConnectionHandler::OnIceGatheringCha
Taylor_Brandstetter
2017/01/17 18:56:19
Yes: https://cs.chromium.org/chromium/src/third_pa
| |
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:[]}); | |
perkj_chrome
2017/01/17 09:08:01
end with setting a valid configuration to verify t
Taylor_Brandstetter
2017/01/17 18:56:19
Done.
| |
108 reportTestSuccess(); | |
109 } | |
110 | |
111 function assertThrows(func) { | |
112 try { | |
113 func.apply(arguments.slice(start=1)); | |
114 failTest('Expected exception to be thrown by: ' + code); | |
115 } catch (e) { | |
116 } | |
117 } | |
118 | |
119 // Helper function to create and apply offer. | |
120 function createOfferAndSetLocalDescription() { | |
121 gPeerConnection.createOffer({offerToReceiveAudio:1}) | |
122 .then(function(offer) { | |
123 console.log("Setting offer:\n" + offer.sdp); | |
124 gPeerConnection.setLocalDescription(offer).then( | |
125 function() {}, | |
126 function() { failTest('Failed to set local description.') } | |
127 ); | |
128 }, | |
129 function() { | |
130 failTest('Failed to generate offer.') | |
131 } | |
132 ); | |
133 } | |
134 | |
135 </script> | |
136 </head> | |
137 <body> | |
138 </body> | |
139 </html> | |
OLD | NEW |