diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/webrtc/tests/mochitests/test_peerConnection_callbacks.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webrtc/tests/mochitests/test_peerConnection_callbacks.html')
-rw-r--r-- | dom/media/webrtc/tests/mochitests/test_peerConnection_callbacks.html | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/dom/media/webrtc/tests/mochitests/test_peerConnection_callbacks.html b/dom/media/webrtc/tests/mochitests/test_peerConnection_callbacks.html new file mode 100644 index 0000000000..4c890e4400 --- /dev/null +++ b/dom/media/webrtc/tests/mochitests/test_peerConnection_callbacks.html @@ -0,0 +1,86 @@ +<!DOCTYPE HTML> +<html> +<head> + <script type="application/javascript" src="pc.js"></script> +</head> +<body> +<pre id="test"> +<script type="application/javascript"> + createHTML({ + title: "PeerConnection using callback functions", + bug: "1119593", + visible: true + }); + +// This still aggressively uses promises, but it is testing that the callback functions +// are properly in place. + +// wrapper that turns a callback-based function call into a promise +function pcall(o, f, beforeArg) { + return new Promise((resolve, reject) => { + var args = [resolve, reject]; + if (typeof beforeArg !== 'undefined') { + args.unshift(beforeArg); + } + info('Calling ' + f.name); + f.apply(o, args); + }); +} + +var pc1 = new RTCPeerConnection(); +var pc2 = new RTCPeerConnection(); + +var pc2_haveRemoteOffer = new Promise(resolve => { + pc2.onsignalingstatechange = + e => (e.target.signalingState == "have-remote-offer") && resolve(); +}); +var pc1_stable = new Promise(resolve => { + pc1.onsignalingstatechange = + e => (e.target.signalingState == "stable") && resolve(); +}); + +pc1.onicecandidate = e => { + pc2_haveRemoteOffer + .then(() => !e.candidate || pcall(pc2, pc2.addIceCandidate, e.candidate)) + .catch(generateErrorCallback()); +}; +pc2.onicecandidate = e => { + pc1_stable + .then(() => !e.candidate || pcall(pc1, pc1.addIceCandidate, e.candidate)) + .catch(generateErrorCallback()); +}; + +var v1, v2; +var delivered = new Promise(resolve => { + pc2.onaddstream = e => { + v2.srcObject = e.stream; + resolve(e.stream); + }; +}); + +runNetworkTest(function() { + v1 = createMediaElement('video', 'v1'); + v2 = createMediaElement('video', 'v2'); + var canPlayThrough = new Promise(resolve => v2.canplaythrough = resolve); + is(v2.currentTime, 0, "v2.currentTime is zero at outset"); + + // not testing legacy gUM here + return navigator.mediaDevices.getUserMedia({ video: true, audio: true }) + .then(stream => pc1.addStream(v1.srcObject = stream)) + .then(() => pcall(pc1, pc1.createOffer)) + .then(offer => pcall(pc1, pc1.setLocalDescription, offer)) + .then(() => pcall(pc2, pc2.setRemoteDescription, pc1.localDescription)) + .then(() => pcall(pc2, pc2.createAnswer)) + .then(answer => pcall(pc2, pc2.setLocalDescription, answer)) + .then(() => pcall(pc1, pc1.setRemoteDescription, pc2.localDescription)) + .then(() => delivered) + // .then(() => canPlayThrough) // why doesn't this fire? + .then(() => waitUntil(() => v2.currentTime > 0)) + .then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")")) + .then(() => ok(true, "Connected.")) + .then(() => { v1.pause(); v2.pause(); }); +}); +</script> +</pre> +</body> +</html> |