test_peerConnection_codecNegotiationFailure.html (3398B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 <script type="application/javascript" src="iceTestUtils.js"></script> 6 </head> 7 <body> 8 <pre id="test"> 9 <script type="application/javascript"> 10 createHTML({ 11 bug: "1683934", 12 title: "RTCPeerConnection check codec negotiation failure" 13 }); 14 15 function makeWeirdCodecs(sdp) { 16 return sdp 17 .replaceAll('VP8', 'VEEEEEEEEP8') 18 .replaceAll('VP9', 'VEEEEEEEEP9') 19 .replaceAll('H264', 'HERP264') 20 .replaceAll('AV1', 'HEYV1'); 21 } 22 23 const tests = [ 24 async function offererWeirdCodecs() { 25 const pc1 = new RTCPeerConnection(); 26 const pc2 = new RTCPeerConnection(); 27 28 const stream = await navigator.mediaDevices.getUserMedia({video: true}); 29 pc1.addTrack(stream.getTracks()[0]); 30 pc2.addTrack(stream.getTracks()[0]); 31 32 const offer = await pc1.createOffer(); 33 offer.sdp = makeWeirdCodecs(offer.sdp); 34 // It is not an error to receive an offer with no codecs we support 35 await pc2.setRemoteDescription(offer); 36 await pc2.setLocalDescription(); 37 await wait(2000); 38 }, 39 40 async function answererWeirdCodecs() { 41 const pc1 = new RTCPeerConnection(); 42 const pc2 = new RTCPeerConnection(); 43 44 const stream = await navigator.mediaDevices.getUserMedia({video: true}); 45 pc1.addTrack(stream.getTracks()[0]); 46 pc2.addTrack(stream.getTracks()[0]); 47 48 await pc1.setLocalDescription(); 49 await pc2.setRemoteDescription(pc1.localDescription); 50 const answer = await pc2.createAnswer(); 51 answer.sdp = makeWeirdCodecs(answer.sdp); 52 try { 53 await pc1.setRemoteDescription(answer); 54 ok(false, "Should have thrown"); 55 } catch (e) { 56 ok(true, "Should have thrown"); 57 } 58 }, 59 60 async function reoffererWeirdCodecs() { 61 const pc1 = new RTCPeerConnection(); 62 const pc2 = new RTCPeerConnection(); 63 64 const stream = await navigator.mediaDevices.getUserMedia({video: true}); 65 pc1.addTrack(stream.getTracks()[0]); 66 pc2.addTrack(stream.getTracks()[0]); 67 68 await connect(pc1, pc2, 32000, "Initial connection"); 69 70 const offer = await pc1.createOffer(); 71 offer.sdp = makeWeirdCodecs(offer.sdp); 72 // It is not an error to receive an offer with no codecs we support 73 await pc2.setRemoteDescription(offer); 74 await pc2.setLocalDescription(); 75 await wait(2000); 76 }, 77 78 async function reanswererWeirdCodecs() { 79 const pc1 = new RTCPeerConnection(); 80 const pc2 = new RTCPeerConnection(); 81 82 const stream = await navigator.mediaDevices.getUserMedia({video: true}); 83 pc1.addTrack(stream.getTracks()[0]); 84 pc2.addTrack(stream.getTracks()[0]); 85 86 await connect(pc1, pc2, 32000, "Initial connection"); 87 await pc1.setLocalDescription(); 88 await pc2.setRemoteDescription(pc1.localDescription); 89 const answer = await pc2.createAnswer(); 90 answer.sdp = makeWeirdCodecs(answer.sdp); 91 try { 92 await pc1.setRemoteDescription(answer); 93 ok(false, "Should have thrown"); 94 } catch (e) { 95 ok(true, "Should have thrown"); 96 } 97 }, 98 99 ]; 100 101 runNetworkTest(async () => { 102 for (const test of tests) { 103 info(`Running test: ${test.name}`); 104 await test(); 105 info(`Done running test: ${test.name}`); 106 } 107 }); 108 109 </script> 110 </pre> 111 </body> 112 </html>