OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
4 <script type="text/javascript" src="webrtc_test_common.js"></script> | 4 <script type="text/javascript" src="webrtc_test_common.js"></script> |
5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
6 $ = function(id) { | 6 $ = function(id) { |
7 return document.getElementById(id); | 7 return document.getElementById(id); |
8 }; | 8 }; |
9 | 9 |
10 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { | 10 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { |
11 failTest('Error: ' + errorMsg + '\nScript: ' + url + | 11 failTest('Error: ' + errorMsg + '\nScript: ' + url + |
12 '\nLine: ' + lineNumber + '\nColumn: ' + column + | 12 '\nLine: ' + lineNumber + '\nColumn: ' + column + |
13 '\nStackTrace: ' + errorObj); | 13 '\nStackTrace: ' + errorObj); |
14 } | 14 } |
15 | 15 |
16 var gPeerConnection = null; | 16 var gPeerConnection = null; |
17 var gCertificate = null; | 17 var gCertificate = null; |
18 | 18 |
19 // This test creates and sets three offers, calling setConfiguration in | 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 | 20 // between each offer, expecting an ICE restart to be triggered by the next |
21 // offer. | 21 // offer. |
22 function testSetConfiguration() { | 22 function testSetConfiguration() { |
23 gPeerConnection = new RTCPeerConnection( | 23 gPeerConnection = new RTCPeerConnection( |
24 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', | 24 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', |
25 rtcpMuxPolicy:'require', certificates:[]}); | 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}); |
26 // Now test successful cases of setConfiguration. Changes should trigger an | 31 // 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 | 32 // 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. | 33 // initial ICE gathering phase and wait until it completes. |
29 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that | 34 // TODO(deadbeef): Once onicegatheringstatechange is implemented, use that |
30 // instead of a "null" candidate. | 35 // instead of a "null" candidate. |
31 gPeerConnection.onicecandidate = iceCandidateCallback1; | 36 gPeerConnection.onicecandidate = iceCandidateCallback1; |
32 createOfferAndSetLocalDescription(); | 37 createOfferAndSetLocalDescription(); |
33 } | 38 } |
34 | 39 |
35 function iceCandidateCallback1(candidate) { | 40 function iceCandidateCallback1(candidate) { |
36 if (gPeerConnection.iceGatheringState === 'complete') { | 41 if (gPeerConnection.iceGatheringState === 'complete') { |
37 gPeerConnection.onicecandidate = iceCandidateCallback2; | 42 gPeerConnection.onicecandidate = iceCandidateCallback2; |
38 // Policy changed. | 43 // Policy changed. |
39 gPeerConnection.setConfiguration( | 44 gPeerConnection.setConfiguration( |
40 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', | 45 {iceServers:[], iceTransportPolicy:'relay', bundlePolicy:'balanced', |
41 rtcpMuxPolicy:'require', certificates:[]}); | 46 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1}); |
42 createOfferAndSetLocalDescription(); | 47 createOfferAndSetLocalDescription(); |
43 } | 48 } |
44 } | 49 } |
45 | 50 |
46 function iceCandidateCallback2(candidate) { | 51 function iceCandidateCallback2(candidate) { |
47 if (gPeerConnection.iceGatheringState === 'complete') { | 52 if (gPeerConnection.iceGatheringState === 'complete') { |
48 gPeerConnection.onicecandidate = iceCandidateCallback3; | 53 gPeerConnection.onicecandidate = iceCandidateCallback3; |
49 // Servers changed. | 54 // Servers changed. |
50 gPeerConnection.setConfiguration( | 55 gPeerConnection.setConfiguration( |
51 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all', | 56 {iceServers:[{urls:'stun:foo.invalid'}], iceTransportPolicy:'all', |
52 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[]}); | 57 bundlePolicy:'balanced', rtcpMuxPolicy:'require', certificates:[], |
| 58 iceCandidatePoolSize:1}); |
53 createOfferAndSetLocalDescription(); | 59 createOfferAndSetLocalDescription(); |
54 } | 60 } |
55 } | 61 } |
56 | 62 |
57 function iceCandidateCallback3(candidate) { | 63 function iceCandidateCallback3(candidate) { |
58 // Only wait for 'gathering', since it will take a while for the requests to | 64 // Only wait for 'gathering', since it will take a while for the requests to |
59 // 'foo.invalid' to time out. | 65 // 'foo.invalid' to time out. |
60 if (gPeerConnection.iceGatheringState === 'gathering') { | 66 if (gPeerConnection.iceGatheringState === 'gathering') { |
61 reportTestSuccess(); | 67 reportTestSuccess(); |
62 } | 68 } |
(...skipping 10 matching lines...) Expand all Loading... |
73 function() { | 79 function() { |
74 failTest('Failed to generate certificate.'); | 80 failTest('Failed to generate certificate.'); |
75 } | 81 } |
76 ); | 82 ); |
77 } | 83 } |
78 | 84 |
79 // Continued after certificate generated. | 85 // Continued after certificate generated. |
80 function continueTestSetConfigurationErrors() { | 86 function continueTestSetConfigurationErrors() { |
81 gPeerConnection = new RTCPeerConnection( | 87 gPeerConnection = new RTCPeerConnection( |
82 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', | 88 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', |
83 rtcpMuxPolicy:'require', certificates:[]}); | 89 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1}); |
84 // If bundlePolicy, rtcpMuxPolicy or certificates are changed, an | 90 // If bundlePolicy, rtcpMuxPolicy or certificates are changed, an |
85 // InvalidModificationError should be thrown. | 91 // InvalidModificationError should be thrown. |
86 assertThrows(gPeerConnection.setConfiguration, | 92 assertThrows(gPeerConnection.setConfiguration, |
87 {iceServers:[], iceTransportPolicy:'all', | 93 {iceServers:[], iceTransportPolicy:'all', |
88 bundlePolicy:'max-bundle', rtcpMuxPolicy:'require', | 94 bundlePolicy:'max-bundle', rtcpMuxPolicy:'require', |
89 certificates:[]}); | 95 certificates:[], iceCandidatePoolSize:1}); |
90 assertThrows(gPeerConnection.setConfiguration, | 96 assertThrows(gPeerConnection.setConfiguration, |
91 {iceServers:[], iceTransportPolicy:'all', | 97 {iceServers:[], iceTransportPolicy:'all', |
92 bundlePolicy:'balanced', rtcpMuxPolicy:'negotiate', | 98 bundlePolicy:'balanced', rtcpMuxPolicy:'negotiate', |
93 certificates:[]}); | 99 certificates:[]}); |
94 assertThrows(gPeerConnection.setConfiguration, | 100 assertThrows(gPeerConnection.setConfiguration, |
95 {iceServers:[], iceTransportPolicy:'all', | 101 {iceServers:[], iceTransportPolicy:'all', |
96 bundlePolicy:'balanced', rtcpMuxPolicy:'require', | 102 bundlePolicy:'balanced', rtcpMuxPolicy:'require', |
97 certificates:[gCertificate]}); | 103 certificates:[gCertificate], iceCandidatePoolSize:1}); |
98 // Failure to parse URL should result in SyntaxError. | 104 // Failure to parse URL should result in SyntaxError. |
99 assertThrows(gPeerConnection.setConfiguration, | 105 assertThrows(gPeerConnection.setConfiguration, |
100 {iceServers:[{url:'stunnnn:foo.invalid'}], | 106 {iceServers:[{url:'stunnnn:foo.invalid'}], |
101 iceTransportPolicy:'all', bundlePolicy:'max-bundle', | 107 iceTransportPolicy:'all', bundlePolicy:'max-bundle', |
102 rtcpMuxPolicy:'require', certificates:[]}); | 108 rtcpMuxPolicy:'require', certificates:[], |
| 109 iceCandidatePoolSize:1}); |
103 // TURN server with missing username should result in InvalidAccessError. | 110 // TURN server with missing username should result in InvalidAccessError. |
104 assertThrows(gPeerConnection.setConfiguration, | 111 assertThrows(gPeerConnection.setConfiguration, |
105 {iceServers:[{url:'turn:foo.invalid'}], | 112 {iceServers:[{url:'turn:foo.invalid'}], |
106 iceTransportPolicy:'all', bundlePolicy:'max-bundle', | 113 iceTransportPolicy:'all', bundlePolicy:'max-bundle', |
107 rtcpMuxPolicy:'require', certificates:[]}); | 114 rtcpMuxPolicy:'require', certificates:[], |
| 115 iceCandidatePoolSize:1}); |
108 // Sanity check that a configuration can be successfully set, and thus | 116 // Sanity check that a configuration can be successfully set, and thus |
109 // there's not something unexpected causing the above exceptions. | 117 // there's not something unexpected causing the above exceptions. |
110 gPeerConnection.setConfiguration( | 118 gPeerConnection.setConfiguration( |
111 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', | 119 {iceServers:[], iceTransportPolicy:'all', bundlePolicy:'balanced', |
112 rtcpMuxPolicy:'require', certificates:[]}); | 120 rtcpMuxPolicy:'require', certificates:[], iceCandidatePoolSize:1}); |
113 reportTestSuccess(); | 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 ); |
114 } | 143 } |
115 | 144 |
116 function assertThrows(func) { | 145 function assertThrows(func) { |
117 try { | 146 try { |
118 func.apply(arguments.slice(start=1)); | 147 func.apply(arguments.slice(start=1)); |
119 failTest('Expected exception to be thrown by: ' + code); | 148 failTest('Expected exception to be thrown by: ' + code); |
120 } catch (e) { | 149 } catch (e) { |
121 } | 150 } |
122 } | 151 } |
123 | 152 |
(...skipping 11 matching lines...) Expand all Loading... |
135 failTest('Failed to generate offer.') | 164 failTest('Failed to generate offer.') |
136 } | 165 } |
137 ); | 166 ); |
138 } | 167 } |
139 | 168 |
140 </script> | 169 </script> |
141 </head> | 170 </head> |
142 <body> | 171 <body> |
143 </body> | 172 </body> |
144 </html> | 173 </html> |
OLD | NEW |