Skip to content

Commit

Permalink
Support sending/receiving empty strings/bytes over DataChannels.
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D166008

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1315782
gecko-commit: a7e62fe868405e98cd48097ed0ca58302a98840c
gecko-reviewers: jesup
  • Loading branch information
jan-ivar authored and pull[bot] committed Jan 30, 2024
1 parent 5182b30 commit 1224711
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions webrtc/RTCDataChannel-bufferedAmount.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
const helloBuffer = Uint8Array.of(0x68, 0x65, 0x6c, 0x6c, 0x6f);
const helloBlob = new Blob([helloBuffer]);

const emptyBuffer = Uint8Array.of();
const emptyBlob = new Blob([emptyBuffer]);

// Unicode string with multiple code units
const unicodeString = '世界你好';
// UTF-8 encoded buffer representation of the string
Expand Down Expand Up @@ -96,6 +99,17 @@
}, `${mode} bufferedAmount should increase to byte length of encoded` +
`unicode string sent`);

promise_test(async (t) => {
const [dc1, dc2] = await createDataChannelPair(t, options);

dc1.send("");
assert_equals(dc1.bufferedAmount, 0,
'Expect bufferedAmount to stay at zero after sending empty string');

await awaitMessage(dc2);
assert_equals(dc1.bufferedAmount, 0, 'Expect sender bufferedAmount unchanged');
}, `${mode} bufferedAmount should stay at zero for empty string sent`);

/*
6.2. send()
3. Execute the sub step that corresponds to the type of the methods argument:
Expand All @@ -116,6 +130,18 @@
'Expect sender bufferedAmount to be reduced after message is sent');
}, `${mode} bufferedAmount should increase to byte length of buffer sent`);

promise_test(async (t) => {
const [dc1, dc2] = await createDataChannelPair(t, options);

dc1.send(emptyBuffer.buffer);
assert_equals(dc1.bufferedAmount, 0,
'Expect bufferedAmount to stay at zero after sending empty buffer');

await awaitMessage(dc2);
assert_equals(dc1.bufferedAmount, 0,
'Expect sender bufferedAmount unchanged');
}, `${mode} bufferedAmount should stay at zero for empty buffer sent`);

/*
6.2. send()
3. Execute the sub step that corresponds to the type of the methods argument:
Expand All @@ -135,6 +161,18 @@
'Expect sender bufferedAmount to be reduced after message is sent');
}, `${mode} bufferedAmount should increase to size of blob sent`);

promise_test(async (t) => {
const [dc1, dc2] = await createDataChannelPair(t, options);

dc1.send(emptyBlob);
assert_equals(dc1.bufferedAmount, 0,
'Expect bufferedAmount to stay at zero after sending empty blob');

await awaitMessage(dc2);
assert_equals(dc1.bufferedAmount, 0,
'Expect sender bufferedAmount unchanged');
}, `${mode} bufferedAmount should stay at zero for empty blob sent`);

// Test sending 3 messages: helloBuffer, unicodeString, helloBlob
promise_test(async (t) => {
const resolver = new Resolver();
Expand Down

0 comments on commit 1224711

Please sign in to comment.