Skip to content

Commit

Permalink
Test that repeated open/write/echo/close of datachannels works.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D214430

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1902850
gecko-commit: 4812f4312d4baa81453530b5397c6e77080d9e78
gecko-reviewers: jib
  • Loading branch information
docfaraday authored and moz-wptsync-bot committed Jul 4, 2024
1 parent 347966d commit 22c15c2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions webrtc/RTCDataChannel-close.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@
assert_true(closingSeen, 'Closing event was seen');
}, `Close ${mode} causes closing and close event to be called`);

promise_test(async t => {
const pc1 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc2.close());
const mainChannel1 = pc1.createDataChannel('not-counted', options);
exchangeIceCandidates(pc1, pc2);
await exchangeOfferAnswer(pc1, pc2);
if (!options.negotiated) {
await new Promise(r => pc2.ondatachannel = r);
}

for (let i = 1; i <= 10; i++) {
if ('id' in options) {
options.id = i;
}
const sender = pc1.createDataChannel(`dc ${i}`, options);
const senderOpen = new Promise(r => sender.onopen = r);
let receiver;
if (options.negotiated) {
receiver = pc2.createDataChannel(`dc ${i}`, options);
} else {
receiver = (await new Promise(r => pc2.ondatachannel = r)).channel;
}
receiver.onmessage = ({data}) => receiver.send(data);
await senderOpen;
sender.send(`ping ${i}`);
const {data} = await new Promise(r => sender.onmessage = r);
assert_equals(data, `ping ${i}`);
sender.close();
await new Promise(r => receiver.onclose = r);
}
}, `Repeated open/send/echo/close ${mode} works`);

promise_test(async t => {
const pc1 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
Expand Down

0 comments on commit 22c15c2

Please sign in to comment.