diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /dom/media/webrtc/tests/mochitests | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webrtc/tests/mochitests')
-rw-r--r-- | dom/media/webrtc/tests/mochitests/head.js | 2 | ||||
-rw-r--r-- | dom/media/webrtc/tests/mochitests/iceTestUtils.js | 21 | ||||
-rw-r--r-- | dom/media/webrtc/tests/mochitests/test_peerConnection_glean.html | 182 |
3 files changed, 202 insertions, 3 deletions
diff --git a/dom/media/webrtc/tests/mochitests/head.js b/dom/media/webrtc/tests/mochitests/head.js index 1fd559217a..cc0992b469 100644 --- a/dom/media/webrtc/tests/mochitests/head.js +++ b/dom/media/webrtc/tests/mochitests/head.js @@ -413,7 +413,7 @@ function setupEnvironment() { // If either fake audio or video is desired we enable fake streams. // If loopback devices are set they will be chosen instead of fakes in gecko. ["media.navigator.streams.fake", WANT_FAKE_AUDIO || WANT_FAKE_VIDEO], - ["media.getusermedia.audiocapture.enabled", true], + ["media.getusermedia.audio.capture.enabled", true], ["media.getusermedia.screensharing.enabled", true], ["media.getusermedia.window.focus_source.enabled", false], ["media.recorder.audio_node.enabled", true], diff --git a/dom/media/webrtc/tests/mochitests/iceTestUtils.js b/dom/media/webrtc/tests/mochitests/iceTestUtils.js index 9e76e3f7df..23237f563b 100644 --- a/dom/media/webrtc/tests/mochitests/iceTestUtils.js +++ b/dom/media/webrtc/tests/mochitests/iceTestUtils.js @@ -75,6 +75,18 @@ async function iceConnected(pc) { }); } +async function dtlsConnected(pc) { + return new Promise((resolve, reject) => { + pc.addEventListener("connectionstatechange", () => { + if (["connected", "completed"].includes(pc.connectionState)) { + resolve(); + } else if (pc.connectionState == "failed") { + reject(new Error(`Connection failed`)); + } + }); + }); +} + // Set up trickle, but does not wait for it to complete. Can be used by itself // in cases where we do not expect any new candidates, but want to still set up // the signal handling in case new candidates _do_ show up. @@ -87,7 +99,8 @@ async function connect( answerer, timeout, context, - noTrickleWait = false + noTrickleWait = false, + waitForDtls = false ) { const trickle1 = trickleIce(offerer, answerer); const trickle2 = trickleIce(answerer, offerer); @@ -110,8 +123,12 @@ async function connect( } }; + const connectionPromises = waitForDtls + ? [dtlsConnected(offerer), dtlsConnected(answerer)] + : [iceConnected(offerer), iceConnected(answerer)]; + await Promise.race([ - Promise.all([iceConnected(offerer), iceConnected(answerer)]), + Promise.all(connectionPromises), throwOnTimeout(timeout, context), ]); } finally { diff --git a/dom/media/webrtc/tests/mochitests/test_peerConnection_glean.html b/dom/media/webrtc/tests/mochitests/test_peerConnection_glean.html index 1faf464566..a382949823 100644 --- a/dom/media/webrtc/tests/mochitests/test_peerConnection_glean.html +++ b/dom/media/webrtc/tests/mochitests/test_peerConnection_glean.html @@ -4,6 +4,7 @@ <head> <script type="application/javascript" src="pc.js"></script> <script type="application/javascript" src="sdpUtils.js"></script> + <script type="application/javascript" src="iceTestUtils.js"></script> </head> <body> @@ -580,6 +581,187 @@ ok(preferredVideoCodec == 6, "checkLoggingMultipleTransceivers glean should show preferred video codec VP8 " + preferredVideoCodec); }, + async function checkDtlsHandshakeSuccess() { + const pc1 = new RTCPeerConnection(); + const pc2 = new RTCPeerConnection(); + await gleanResetTestValues(); + let client_successes = await GleanTest.webrtcdtls.clientHandshakeResult.SUCCESS.testGetValue() || 0; + let server_successes = await GleanTest.webrtcdtls.serverHandshakeResult.SUCCESS.testGetValue() || 0; + let cipher_count = await GleanTest.webrtcdtls.cipher["0x1301"].testGetValue() || 0; + let srtp_cipher_count = await GleanTest.webrtcdtls.srtpCipher["0x0007"].testGetValue() || 0; + is(client_successes, 0); + is(server_successes, 0); + is(cipher_count, 0); + is(srtp_cipher_count, 0); + + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + pc1.addTrack(stream.getTracks()[0]); + + await connect(pc1, pc2, 32000, "DTLS connected", true, true); + + client_successes = await GleanTest.webrtcdtls.clientHandshakeResult.SUCCESS.testGetValue() || 0; + server_successes = await GleanTest.webrtcdtls.serverHandshakeResult.SUCCESS.testGetValue() || 0; + cipher_count = await GleanTest.webrtcdtls.cipher["0x1301"].testGetValue() || 0; + srtp_cipher_count = await GleanTest.webrtcdtls.srtpCipher["0x0007"].testGetValue() || 0; + is(client_successes, 1); + is(server_successes, 1); + is(cipher_count, 2); + is(srtp_cipher_count, 2); + }, + + async function checkDtlsCipherPrefs() { + await withPrefs([["security.tls13.aes_128_gcm_sha256", false], + ["security.tls13.aes_256_gcm_sha384", false], + ["security.tls13.chacha20_poly1305_sha256", true]], + async () => { + const pc1 = new RTCPeerConnection(); + const pc2 = new RTCPeerConnection(); + await gleanResetTestValues(); + let cipher_count = await GleanTest.webrtcdtls.cipher["0x1303"].testGetValue() || 0; + is(cipher_count, 0); + + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + pc1.addTrack(stream.getTracks()[0]); + + await connect(pc1, pc2, 32000, "DTLS connected", true, true); + + cipher_count = await GleanTest.webrtcdtls.cipher["0x1303"].testGetValue() || 0; + is(cipher_count, 2); + }); + }, + + async function checkDtlsHandshakeFailure() { + // We don't have many failures we can induce here, but messing up the + // fingerprint is one way. + const offerer = new RTCPeerConnection(); + const answerer = new RTCPeerConnection(); + await gleanResetTestValues(); + let client_failures = await GleanTest.webrtcdtls.clientHandshakeResult.SSL_ERROR_BAD_CERTIFICATE.testGetValue() || 0; + let server_failures = await GleanTest.webrtcdtls.serverHandshakeResult.SSL_ERROR_BAD_CERT_ALERT.testGetValue() || 0; + is(client_failures, 0); + is(server_failures, 0); + + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + offerer.addTrack(stream.getTracks()[0]); + + trickleIce(offerer, answerer); + trickleIce(answerer, offerer); + await offerer.setLocalDescription(); + let badSdp = offerer.localDescription.sdp; + // Tweak the last digit in the fingerprint sent to the answerer. Answerer + // (which will be the DTLS client) will get an SSL_ERROR_BAD_CERTIFICATE + // error, and the offerer (which will be the DTLS server) will get an + // SSL_ERROR_BAD_CERT_ALERT. + const lastDigit = badSdp.match(/a=fingerprint:.*([0-9A-F])$/m)[1]; + const newLastDigit = lastDigit == '0' ? '1' : '0'; + badSdp = badSdp.replace(/(a=fingerprint:.*)[0-9A-F]$/m, "$1" + newLastDigit); + info(badSdp); + await answerer.setRemoteDescription({sdp: badSdp, type: "offer"}); + await answerer.setLocalDescription(); + await offerer.setRemoteDescription(answerer.localDescription); + + const throwOnTimeout = async () => { + await wait(32000); + throw new Error( + `ICE did not complete within ${timeout} ms`); + }; + + const connectionPromises = [connectionStateReached(offerer, "failed"), + connectionStateReached(answerer, "failed")]; + + await Promise.race([ + Promise.all(connectionPromises), + throwOnTimeout() + ]); + + client_failures = await GleanTest.webrtcdtls.clientHandshakeResult.SSL_ERROR_BAD_CERTIFICATE.testGetValue() || 0; + server_failures = await GleanTest.webrtcdtls.serverHandshakeResult.SSL_ERROR_BAD_CERT_ALERT.testGetValue() || 0; + is(client_failures, 1); + is(server_failures, 1); + }, + + async function checkDtlsVersion1_3() { + // 1.3 should be the default + const pc1 = new RTCPeerConnection(); + const pc2 = new RTCPeerConnection(); + await gleanResetTestValues(); + let count1_0 = await GleanTest.webrtcdtls.protocolVersion["1.0"].testGetValue() || 0; + let count1_2 = await GleanTest.webrtcdtls.protocolVersion["1.2"].testGetValue() || 0; + let count1_3 = await GleanTest.webrtcdtls.protocolVersion["1.3"].testGetValue() || 0; + is(count1_0, 0); + is(count1_2, 0); + is(count1_3, 0); + + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + pc1.addTrack(stream.getTracks()[0]); + + await connect(pc1, pc2, 32000, "DTLS connected", true, true); + + count1_0 = await GleanTest.webrtcdtls.protocolVersion["1.0"].testGetValue() || 0; + count1_2 = await GleanTest.webrtcdtls.protocolVersion["1.2"].testGetValue() || 0; + count1_3 = await GleanTest.webrtcdtls.protocolVersion["1.3"].testGetValue() || 0; + is(count1_0, 0); + is(count1_2, 0); + is(count1_3, 2); + }, + + async function checkDtlsVersion1_2() { + // Make 1.2 the default + await withPrefs([["media.peerconnection.dtls.version.max", 771]], + async () => { + const pc1 = new RTCPeerConnection(); + const pc2 = new RTCPeerConnection(); + await gleanResetTestValues(); + let count1_0 = await GleanTest.webrtcdtls.protocolVersion["1.0"].testGetValue() || 0; + let count1_2 = await GleanTest.webrtcdtls.protocolVersion["1.2"].testGetValue() || 0; + let count1_3 = await GleanTest.webrtcdtls.protocolVersion["1.3"].testGetValue() || 0; + is(count1_0, 0); + is(count1_2, 0); + is(count1_3, 0); + + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + pc1.addTrack(stream.getTracks()[0]); + + await connect(pc1, pc2, 32000, "DTLS connected", true, true); + + count1_0 = await GleanTest.webrtcdtls.protocolVersion["1.0"].testGetValue() || 0; + count1_2 = await GleanTest.webrtcdtls.protocolVersion["1.2"].testGetValue() || 0; + count1_3 = await GleanTest.webrtcdtls.protocolVersion["1.3"].testGetValue() || 0; + is(count1_0, 0); + is(count1_2, 2); + is(count1_3, 0); + }); + }, + + async function checkDtlsVersion1_0() { + // Make 1.0 the default + await withPrefs([["media.peerconnection.dtls.version.max", 770], + ["media.peerconnection.dtls.version.min", 770]], + async () => { + const pc1 = new RTCPeerConnection(); + const pc2 = new RTCPeerConnection(); + await gleanResetTestValues(); + let count1_0 = await GleanTest.webrtcdtls.protocolVersion["1.0"].testGetValue() || 0; + let count1_2 = await GleanTest.webrtcdtls.protocolVersion["1.2"].testGetValue() || 0; + let count1_3 = await GleanTest.webrtcdtls.protocolVersion["1.3"].testGetValue() || 0; + is(count1_0, 0); + is(count1_2, 0); + is(count1_3, 0); + + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + pc1.addTrack(stream.getTracks()[0]); + + await connect(pc1, pc2, 32000, "DTLS connected", true, true); + + count1_0 = await GleanTest.webrtcdtls.protocolVersion["1.0"].testGetValue() || 0; + count1_2 = await GleanTest.webrtcdtls.protocolVersion["1.2"].testGetValue() || 0; + count1_3 = await GleanTest.webrtcdtls.protocolVersion["1.3"].testGetValue() || 0; + is(count1_0, 2); + is(count1_2, 0); + is(count1_3, 0); + }); + }, + ]; runNetworkTest(async () => { |