RTCDataChannel-iceRestart.html (2455B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <meta name="timeout" content="long"> 4 <title>RTCDataChannel interactions with ICE restart</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="RTCPeerConnection-helper.js"></script> 8 <script> 9 'use strict'; 10 11 async function checkCanPassData(channel1, channel2) { 12 channel1.send('hello'); 13 const message = await awaitMessage(channel2); 14 assert_equals(message, 'hello'); 15 } 16 17 async function pingPongData(channel1, channel2, size=1) { 18 channel1.send('hello'); 19 const request = await awaitMessage(channel2); 20 assert_equals(request, 'hello'); 21 const response = 'x'.repeat(size); 22 channel2.send(response); 23 const responseReceived = await awaitMessage(channel1); 24 assert_equals(response, responseReceived); 25 } 26 27 promise_test(async t => { 28 const pc1 = new RTCPeerConnection(); 29 t.add_cleanup(() => pc1.close()); 30 const pc2 = new RTCPeerConnection(); 31 t.add_cleanup(() => pc2.close()); 32 33 const [channel1, channel2] = await createDataChannelPair(t, {}, pc1, pc2); 34 channel2.addEventListener('error', t.unreached_func()); 35 channel2.addEventListener('error', t.unreached_func()); 36 37 await checkCanPassData(channel1, channel2); 38 await checkCanPassData(channel2, channel1); 39 40 pc1.restartIce(); 41 await exchangeOfferAnswer(pc1, pc2); 42 43 await checkCanPassData(channel1, channel2); 44 await checkCanPassData(channel2, channel1); 45 channel1.close(); 46 channel2.close(); 47 }, `Data channel remains usable after ICE restart`); 48 49 promise_test(async t => { 50 const pc1 = new RTCPeerConnection(); 51 t.add_cleanup(() => pc1.close()); 52 const pc2 = new RTCPeerConnection(); 53 t.add_cleanup(() => pc2.close()); 54 55 const [channel1, channel2] = await createDataChannelPair(t, {}, pc1, pc2); 56 channel2.addEventListener('error', t.unreached_func()); 57 channel2.addEventListener('error', t.unreached_func()); 58 59 await pingPongData(channel1, channel2); 60 pc1.restartIce(); 61 62 await pc1.setLocalDescription(); 63 await pingPongData(channel1, channel2); 64 await pc2.setRemoteDescription(pc1.localDescription); 65 await pingPongData(channel1, channel2); 66 await pc2.setLocalDescription(await pc2.createAnswer()); 67 await pingPongData(channel1, channel2); 68 await pc1.setRemoteDescription(pc2.localDescription); 69 await pingPongData(channel1, channel2); 70 channel1.close(); 71 channel2.close(); 72 }, `Data channel remains usable at each step of an ICE restart`); 73 74 75 76 </script>