diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/webrtc/RTCPeerConnection-GC.https.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webrtc/RTCPeerConnection-GC.https.html')
-rw-r--r-- | testing/web-platform/tests/webrtc/RTCPeerConnection-GC.https.html | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webrtc/RTCPeerConnection-GC.https.html b/testing/web-platform/tests/webrtc/RTCPeerConnection-GC.https.html new file mode 100644 index 0000000000..76ae3087e4 --- /dev/null +++ b/testing/web-platform/tests/webrtc/RTCPeerConnection-GC.https.html @@ -0,0 +1,92 @@ +<!doctype html> +<html> +<head> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/gc.js"></script> +<script src="RTCPeerConnection-helper.js"></script> +</head> +<body> +<script> +'use strict'; + +// Check that RTCPeerConnection is not collected by GC while displaying video. + +promise_test(async t => { + const canvas = document.createElement('canvas'); + canvas.width = canvas.height = 160; + const ctx = canvas.getContext("2d"); + ctx.fillStyle = "blue"; + const drawCanvas = () => { + ctx.fillRect(0, 0, canvas.width, canvas.height); + }; + + let pc1 = new RTCPeerConnection(); + let pc2 = new RTCPeerConnection(); + + // Attach video to pc1. + const [inputTrack] = canvas.captureStream().getTracks(); + pc1.addTrack(inputTrack); + + const destVideo = document.createElement('video'); + destVideo.autoplay = true; + const onVideoChange = async () => { + const start = performance.now(); + const width = destVideo.videoWidth; + const height = destVideo.videoHeight; + const resizeEvent = new Promise(r => destVideo.onresize = r); + while (destVideo.videoWidth == width && destVideo.videoHeight == height) { + if (performance.now() - start > 5000) { + throw new Error("Timeout waiting for video size change"); + } + drawCanvas(); + await Promise.race([ + resizeEvent, + new Promise(r => requestAnimationFrame(r)), + ]); + } + }; + + // Setup cleanup. We cannot keep references to pc1 or pc2 so do a best-effort with GC. + t.add_cleanup(async () => { + inputTrack.stop(); + destVideo.srcObject = null; + await garbageCollect(); + }); + + // Setup pc1->pc2. + let haveTrackEvent = new Promise(r => pc2.ontrack = r); + exchangeIceCandidates(pc1, pc2); + await pc1.setLocalDescription(); + await pc2.setRemoteDescription(pc1.localDescription); + await pc2.setLocalDescription(); + await pc1.setRemoteDescription(pc2.localDescription); + + // Display pc2 received track in video element. + const loadedMetadata = new Promise(r => destVideo.onloadedmetadata = r); + destVideo.srcObject = new MediaStream([(await haveTrackEvent).track]); + + // Wait for video on the other side. + await onVideoChange(); + const color = getVideoSignal(destVideo); + assert_not_equals(color, 0); + + // Remove RTCPeerConnection references and garbage collect. + pc1 = null; + pc2 = null; + haveTrackEvent = null; + await garbageCollect(); + + // Check that a change to video input is reflected in the output, i.e., the + // peer connections were not garbage collected. + canvas.width = canvas.height = 240; + ctx.fillStyle = "red"; + await onVideoChange(); + assert_not_equals(color, getVideoSignal(destVideo)); + }, "GC does not collect a peer connection pipe rendering to a video element"); +</script> +</body> +</html> + |