blob: 3f2c1b7936940d170964a7c6574bc6bed4b2b449 [file] [log] [blame]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing bufferedAmountLowThreashold RTCDataChannel attribute and event</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script src ="../routines.js"></script>
<script>
window.addEventListener("unhandledrejection", event => {
event.preventDefault();
});
var localChannel;
var remoteChannel;
function closeDataChannels() {
localChannel.close();
remoteChannel.close();
closeConnections();
}
var longString = "abcdefgh";
for (var cptr = 0; cptr < 10; ++cptr)
longString += longString;
function receiveMessages(event) {
if (++counter === 1)
return;
}
function sendContinuouslyMessages(channel)
{
try {
while (channel.bufferedAmount < 200000)
channel.send(longString);
setTimeout(() => sendContinuouslyMessages(channel), 0);
} catch(e) {
}
}
promise_test((test) => {
counter = 0;
var gotEvent = false;
return new Promise((resolve, reject) => {
createConnections((localConnection) => {
localChannel = localConnection.createDataChannel('sendDataChannel');
localChannel.onopen = () => {
sendContinuouslyMessages(localChannel);
localChannel.onbufferedamountlow = () => {
resolve();
}
};
localChannel.bufferedAmountLowThreshold = 200000;
}, (remoteConnection) => {
remoteConnection.ondatachannel = (event) => {
remoteChannel = event.channel;
remoteChannel.onmessage = receiveMessages;
};
});
setTimeout(() => reject('timed out'), 5000);
}).then (() => {
closeDataChannels();
});
}, "Large buffer threshold reached");
</script>
</body>
</html>