tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RTCDataChannel-GC.html (1619B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4 <meta charset=utf-8>
      5 <meta name="timeout" content="long">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/common/gc.js"></script>
      9 <script src="RTCPeerConnection-helper.js"></script>
     10 </head>
     11 <body>
     12 <script>
     13 'use strict';
     14 
     15 // Check that RTCDataChannel is not collected by GC while observing remote pc close
     16 
     17 async function didRemotePcClose(t, closeRemotePc) {
     18  let pc1 = new RTCPeerConnection(), pc2 = new RTCPeerConnection();
     19  t.add_cleanup(async () => await garbageCollect());
     20  pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
     21  pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);
     22  let dc1 = pc1.createDataChannel("");
     23  const haveOpened = new Promise(r => dc1.onopen = r);
     24  let closed = false;
     25  const haveClosed = new Promise(r => dc1.onclose = () => r(closed = true));
     26  dc1 = null;
     27  await pc1.setLocalDescription();
     28  await pc2.setRemoteDescription(pc1.localDescription);
     29  await pc2.setLocalDescription();
     30  await pc1.setRemoteDescription(pc2.localDescription);
     31  await haveOpened;
     32  if (closeRemotePc) pc2.close();
     33  pc1 = pc2 = null;
     34  await garbageCollect();
     35  await Promise.race([haveClosed, new Promise(r => t.step_timeout(r, 10000))]);
     36  return closed;
     37 }
     38 
     39 promise_test(async t => {
     40  assert_true(await didRemotePcClose(t, true));
     41 }, "Control: detected remote PC being closed using a data channel");
     42 
     43 promise_test(async t => {
     44  assert_false(await didRemotePcClose(t, false));
     45 }, "While remote PC remains open, its datachannel should not be collected");
     46 
     47 </script>
     48 </body>
     49 </html>