Skip to content

Commit

Permalink
Update RTCDataChannel bufferedamountlow implementation.
Browse files Browse the repository at this point in the history
Maintain bufferedamount value in blink layer. Increase bufferedamount on send
and decrease it on OnBufferedAmountChange updates from webrtc layer. Fire
bufferedamountlow when bufferedamount goes below bufferedamountlowthreshold.

This change builds upon the corresponding webrtc change:
https://webrtc-review.googlesource.com/c/src/+/123237

Design doc: http://doc/1lorHBn-GMn5U0T0RQANxrsW0pXhw8XGZM-xZyVUOW90
Standard: https://w3c.github.io/webrtc-pc/#event-datachannel-bufferedamountlow

Bug: 878682
Change-Id: Ifebc79f71f924ecb5cedce1c94e18440663337f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1474764
Commit-Queue: Marina Ciocea <[email protected]>
Reviewed-by: Henrik Boström <[email protected]>
Cr-Commit-Position: refs/heads/master@{#639846}
  • Loading branch information
cdmarina authored and chromium-wpt-export-bot committed Mar 12, 2019
1 parent c46639d commit 791052b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions webrtc/RTCDataChannel-bufferedAmount.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,59 @@
assert_unreached(`Unexpected promise rejection: ${err}`)));
}, 'bufferedAmount should increase by byte length for each message sent');

promise_test(async t => {
const [channel1, channel2] = await createDataChannelPair();
channel1.addEventListener('bufferedamountlow', t.step_func_done(() => {
assert_true(channel1.bufferedAmount <= channel1.bufferedAmountLowThreshold);
}));
const eventWatcher = new EventWatcher(t, channel1, ['bufferedamountlow']);
channel1.send(helloString);
await eventWatcher.wait_for(['bufferedamountlow']);
}, 'Data channel bufferedamountlow event fires after send() is complete');

promise_test(async t => {
const [channel1, channel2] = await createDataChannelPair();
channel1.send(helloString);
assert_equals(channel1.bufferedAmount, helloString.length);
await awaitMessage(channel2);
assert_equals(channel1.bufferedAmount, 0);
}, 'Data channel bufferedamount is data.length on send(data)');

promise_test(async t => {
const [channel1, channel2] = await createDataChannelPair();
channel1.send(helloString);
assert_equals(channel1.bufferedAmount, helloString.length);
assert_equals(channel1.bufferedAmount, helloString.length);
}, 'Data channel bufferedamount returns the same amount if no more data is' +
' sent on the channel');

promise_test(async t => {
const [channel1, channel2] = await createDataChannelPair();
let eventFireCount = 0;
channel1.addEventListener('bufferedamountlow', t.step_func(() => {
assert_true(channel1.bufferedAmount <= channel1.bufferedAmountLowThreshold);
assert_equals(++eventFireCount, 1);
}));
const eventWatcher = new EventWatcher(t, channel1, ['bufferedamountlow']);
channel1.send(helloString);
assert_equals(channel1.bufferedAmount, helloString.length);
channel1.send(helloString);
assert_equals(channel1.bufferedAmount, 2 * helloString.length);
await eventWatcher.wait_for(['bufferedamountlow']);
}, 'Data channel bufferedamountlow event fires only once after multiple' +
' consecutive send() calls');

promise_test(async t => {
const [channel1, channel2] = await createDataChannelPair();
const eventWatcher = new EventWatcher(t, channel1, ['bufferedamountlow']);
channel1.send(helloString);
assert_equals(channel1.bufferedAmount, helloString.length);
await eventWatcher.wait_for(['bufferedamountlow']);
assert_equals(await awaitMessage(channel2), helloString);
channel1.send(helloString);
assert_equals(channel1.bufferedAmount, helloString.length);
await eventWatcher.wait_for(['bufferedamountlow']);
assert_equals(await awaitMessage(channel2), helloString);
}, 'Data channel bufferedamountlow event fires after each sent message');

</script>

0 comments on commit 791052b

Please sign in to comment.