tor-browser

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

commit b913a5c92a973439ce0ef4c795c2f18086447427
parent e2d169db608ad0eeaa53e596590452b56f51f8e1
Author: Byron Campen <docfaraday@gmail.com>
Date:   Wed, 29 Oct 2025 12:35:15 +0000

Bug 1988096: Use labels in these DataChannel tests. r=jib

Differential Revision: https://phabricator.services.mozilla.com/D269064

Diffstat:
Mtesting/web-platform/tests/webrtc/RTCDataChannel-close.html | 13+++++++------
Mtesting/web-platform/tests/webrtc/RTCDataChannel-id.html | 12++++++------
Mtesting/web-platform/tests/webrtc/RTCDataChannel-send.html | 26+++++++++++++-------------
Mtesting/web-platform/tests/webrtc/RTCDataChannelEvent-constructor.html | 2+-
Mtesting/web-platform/tests/webrtc/RTCPeerConnection-helper.js | 10+++++++---
5 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/testing/web-platform/tests/webrtc/RTCDataChannel-close.html b/testing/web-platform/tests/webrtc/RTCDataChannel-close.html @@ -12,7 +12,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { const mode = `${options.negotiated? "negotiated " : ""}datachannel`; promise_test(async t => { - const [channel1, channel2] = await createDataChannelPair(t, options); + const [channel1, channel2] = await createDataChannelPairWithLabel(t, 'dc_close_causes_remote_events_1', options); const haveClosed = new Promise(r => channel2.onclose = r); let closingSeen = false; channel1.onclosing = t.unreached_func(); @@ -30,7 +30,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { promise_test(async t => { // This is the same test as above, but using addEventListener // rather than the "onclose" attribute. - const [channel1, channel2] = await createDataChannelPair(t, options); + const [channel1, channel2] = await createDataChannelPairWithLabel(t, 'dc_close_causes_remote_events_2', options); const haveClosed = new Promise(r => channel2.addEventListener('close', r)); let closingSeen = false; channel1.addEventListener('closing', t.unreached_func()); @@ -87,7 +87,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { promise_test(async t => { const pc1 = new RTCPeerConnection(); t.add_cleanup(() => pc1.close()); - const [channel1, channel2] = await createDataChannelPair(t, options, pc1); + const [channel1, channel2] = await createDataChannelPairWithLabel(t, 'pc_close_causes_remote_events', options, pc1); const events = []; let error = null; channel2.addEventListener('error', t.step_func(event => { @@ -114,7 +114,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { promise_test(async t => { let pc1 = new RTCPeerConnection(); t.add_cleanup(() => pc1.close()); - let [channel1, channel2] = await createDataChannelPair(t, options, pc1); + let [channel1, channel2] = await createDataChannelPairWithLabel(t, 'pc_close_after_dc_close', options, pc1); // The expected sequence of events when closing a DC is that // channel1 goes to closing, channel2 fires onclose, and when // the close is confirmed, channel1 fires onclose. @@ -154,6 +154,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { if (!options.negotiated) { await tokenDataChannel; } + let closeExpectedCount = 0; let errorExpectedCount = 0; let resolveCountIsZero; @@ -164,9 +165,9 @@ for (const options of [{}, {negotiated: true, id: 0}]) { if ('id' in options) { options.id = i; } - pc1.createDataChannel('', options); + pc1.createDataChannel(`dc${i} pc1`, options); if (options.negotiated) { - const channel = pc2.createDataChannel('', options); + const channel = pc2.createDataChannel(`dc${i} pc2`, options); channel.addEventListener('error', t.step_func(event => { assert_true(event instanceof RTCErrorEvent, 'error event ' + event); errorExpectedCount -= 1; diff --git a/testing/web-platform/tests/webrtc/RTCDataChannel-id.html b/testing/web-platform/tests/webrtc/RTCDataChannel-id.html @@ -26,7 +26,7 @@ promise_test(async (t) => { const pc = new RTCPeerConnection; t.add_cleanup(() => pc.close()); - const dc1 = pc.createDataChannel(''); + const dc1 = pc.createDataChannel('client_ids'); const ids = new UniqueSet(); const offer = await pc.createOffer(); @@ -56,7 +56,7 @@ promise_test(async (t) => { const pc = new RTCPeerConnection; t.add_cleanup(() => pc.close()); - const dc1 = pc.createDataChannel(''); + const dc1 = pc.createDataChannel('server_ids'); const ids = new UniqueSet(); const offer = await pc.createOffer(); @@ -92,7 +92,7 @@ promise_test(async (t) => { t.add_cleanup(() => pc1.close()); t.add_cleanup(() => pc2.close()); - const dc1 = pc1.createDataChannel('', { + const dc1 = pc1.createDataChannel('ignore_id_prop', { negotiated: false, id: 42 }); @@ -100,7 +100,7 @@ promise_test(async (t) => { dc1.send(':('); }); - const dc2 = pc2.createDataChannel('', { + const dc2 = pc2.createDataChannel('ignore_id_prop', { negotiated: false, id: 42 }); @@ -139,7 +139,7 @@ promise_test(async (t) => { // Create 10 DCEP-negotiated channels with pc1 // Note: These should not have any associated valid ID at this point for (let i = 0; i < 10; ++i) { - const dc = pc1.createDataChannel('before-connection'); + const dc = pc1.createDataChannel(`before-connection-${i}`); assert_equals(dc.id, null, 'Channel id must be null before DTLS role has been determined'); dcs.push(dc); } @@ -179,7 +179,7 @@ promise_test(async (t) => { // Create 10 channels with pc1 for (let i = 0; i < 10; ++i) { - const dc = pc1.createDataChannel('after-connection'); + const dc = pc1.createDataChannel(`after-connection-${i}`); assert_equals(dc.id % 2, 1, `Channel created by the DTLS server role must be odd (was ${dc.id})`); dcs.push(dc); diff --git a/testing/web-platform/tests/webrtc/RTCDataChannel-send.html b/testing/web-platform/tests/webrtc/RTCDataChannel-send.html @@ -79,7 +79,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { attribute to data. */ promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'string', options) .then(([channel1, channel2]) => { channel1.send(helloString); return awaitMessage(channel2) @@ -92,7 +92,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { }, `${mode} should be able to send simple string and receive as string`); promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'unicode', options) .then(([channel1, channel2]) => { channel1.send(unicodeString); return awaitMessage(channel2) @@ -104,7 +104,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { }); }, `${mode} should be able to send unicode string and receive as unicode string`); promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'recv_string', options) .then(([channel1, channel2]) => { channel2.binaryType = 'arraybuffer'; channel1.send(helloString); @@ -117,7 +117,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { }); }, `${mode} should ignore binaryType and always receive string message as string`); promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'emptystring', options) .then(([channel1, channel2]) => { channel1.send(emptyString); // Send a non-empty string in case the implementation ignores empty messages @@ -153,7 +153,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { Float32Array or Float64Array or DataView) ArrayBufferView; */ promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'array_to_arraybuffer', options) .then(([channel1, channel2]) => { channel2.binaryType = 'arraybuffer'; channel1.send(helloBuffer); @@ -175,7 +175,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { ArrayBuffer in bytes. */ promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'arraybuffer', options) .then(([channel1, channel2]) => { channel2.binaryType = 'arraybuffer'; channel1.send(helloBuffer.buffer); @@ -189,7 +189,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { }, `${mode} should be able to send ArrayBuffer message and receive as ArrayBuffer`); promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'empty_arraybuffer', options) .then(([channel1, channel2]) => { channel2.binaryType = 'arraybuffer'; channel1.send(emptyBuffer.buffer); @@ -212,7 +212,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { the bufferedAmount attribute by the size of data, in bytes. */ promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'blob_to_arraybuffer', options) .then(([channel1, channel2]) => { channel2.binaryType = 'arraybuffer'; channel1.send(helloBlob); @@ -233,7 +233,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { to a new Blob object that represents data as its raw data. */ promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'arraybuffer_to_blob', options) .then(([channel1, channel2]) => { channel2.binaryType = 'blob'; channel1.send(helloBuffer); @@ -261,7 +261,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { be initialized to the string "blob". */ promise_test(t => { - return createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'arraybuffer_recv', options) .then(([channel1, channel2]) => { assert_equals(channel2.binaryType, 'arraybuffer', 'Expect initial binaryType value to be arraybuffer'); @@ -293,7 +293,7 @@ for (const options of [{}, {negotiated: true, id: 0}]) { } }); - createDataChannelPair(t, options) + return createDataChannelPairWithLabel(t, 'multitype', options) .then(([channel1, channel2]) => { channel2.binaryType = 'arraybuffer'; channel2.addEventListener('message', onMessage); @@ -340,8 +340,8 @@ for (const options of [{}, {negotiated: true, id: 0}]) { const pc2 = new RTCPeerConnection(); pc1.addTransceiver('audio'); pc1.addTransceiver('video'); - const channel1 = pc1.createDataChannel('foo', {id: 1, ordered: false, negotiated: true}); - const channel2 = pc2.createDataChannel('foo', {id: 1, ordered: false, negotiated: true}); + const channel1 = pc1.createDataChannel('foo1', {id: 1, ordered: false, negotiated: true}); + const channel2 = pc2.createDataChannel('foo2', {id: 1, ordered: false, negotiated: true}); const channel1Open = new Promise(r => channel1.onopen = r); const channel2Open = new Promise(r => channel2.onopen = r); exchangeIceCandidates(pc1, pc2); diff --git a/testing/web-platform/tests/webrtc/RTCDataChannelEvent-constructor.html b/testing/web-platform/tests/webrtc/RTCDataChannelEvent-constructor.html @@ -33,7 +33,7 @@ test(t => { const pc = new RTCPeerConnection(); t.add_cleanup(() => pc.close()); - const dc = pc.createDataChannel(''); + const dc = pc.createDataChannel('constructor'); const event = new RTCDataChannelEvent('type', { channel: dc }); assert_true(event instanceof RTCDataChannelEvent); assert_equals(event.channel, dc); diff --git a/testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js b/testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js @@ -271,19 +271,19 @@ async function listenForSSRCs(t, receiver) { // It does the heavy lifting of performing signaling handshake, // ICE candidate exchange, and waiting for data channel at two // end points to open. Can do both negotiated and non-negotiated setup. -async function createDataChannelPair(t, options, +async function createDataChannelPairWithLabel(t, label, options, pc1 = createPeerConnectionWithCleanup(t), pc2 = createPeerConnectionWithCleanup(t)) { let pair = [], bothOpen; try { if (options.negotiated) { - pair = [pc1, pc2].map(pc => pc.createDataChannel('', options)); + pair = [pc1, pc2].map(pc => pc.createDataChannel(label, options)); bothOpen = Promise.all(pair.map(dc => new Promise((r, e) => { dc.onopen = r; dc.onerror = ({error}) => e(error); }))); } else { - pair = [pc1.createDataChannel('', options)]; + pair = [pc1.createDataChannel(label, options)]; bothOpen = Promise.all([ new Promise((r, e) => { pair[0].onopen = r; @@ -307,6 +307,10 @@ async function createDataChannelPair(t, options, } } +async function createDataChannelPair(t, options, pc1, pc2) { + return createDataChannelPairWithLabel(t, '', options, pc1, pc2); +} + // Wait for RTP and RTCP stats to arrive async function waitForRtpAndRtcpStats(pc) { // If remote stats are never reported, return after 5 seconds.