| <!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> |
| var localChannel; |
| var remoteChannel; |
| |
| function closeDataChannels() { |
| localChannel.close(); |
| remoteChannel.close(); |
| closeConnections(); |
| } |
| |
| var longString = "abcdefgh"; |
| for (var cptr = 0; cptr < 14; ++cptr) |
| longString += longString; |
| |
| function sendMessages(channel) |
| { |
| channel.send(longString); |
| channel.send(longString); |
| } |
| |
| function receiveMessages(event) { |
| if (++counter === 1) |
| return; |
| finishTest(); |
| } |
| |
| var finishTest; |
| |
| promise_test((test) => { |
| counter = 0; |
| var gotEvent = false; |
| return new Promise((resolve, reject) => { |
| finishTest = resolve; |
| createConnections((localConnection) => { |
| localChannel = localConnection.createDataChannel('sendDataChannel'); |
| localChannel.onopen = () => { sendMessages(localChannel); }; |
| localChannel.onbufferedamountlow = () => { |
| gotEvent = true; |
| } |
| assert_equals(localChannel.bufferedAmountLowThreshold, 0, "default bufferedAmountLowThreshold value"); |
| }, (remoteConnection) => { |
| remoteConnection.ondatachannel = (event) => { |
| remoteChannel = event.channel; |
| remoteChannel.onmessage = receiveMessages; |
| }; |
| }); |
| }).then (() => { |
| return waitFor(500); |
| }).then (() => { |
| closeDataChannels(); |
| assert_true(gotEvent, "got onbufferedamountlow event"); |
| }); |
| }, "Default buffer threshold"); |
| |
| function sendContinuouslyMessages(channel) |
| { |
| try { |
| while (channel.bufferedAmount < 200000) |
| channel.send(longString); |
| |
| setTimeout(() => sendContinuouslyMessages(channel), 1); |
| } catch(e) { |
| console.log("channel send is throwing"); |
| } |
| } |
| |
| promise_test((test) => { |
| counter = 0; |
| var gotEvent = false; |
| return new Promise((resolve, reject) => { |
| finishTest = resolve; |
| createConnections((localConnection) => { |
| localChannel = localConnection.createDataChannel('sendDataChannel'); |
| localChannel.onopen = () => { |
| sendContinuouslyMessages(localChannel); |
| localChannel.onbufferedamountlow = () => { |
| gotEvent = true; |
| } |
| }; |
| localChannel.bufferedAmountLowThreshold = 200000; |
| }, (remoteConnection) => { |
| remoteConnection.ondatachannel = (event) => { |
| remoteChannel = event.channel; |
| remoteChannel.onmessage = receiveMessages; |
| }; |
| }); |
| }).then (() => { |
| return waitFor(500); |
| }).then (() => { |
| closeDataChannels(); |
| assert_true(gotEvent, "got onbufferedamountlow event"); |
| }); |
| }, "Large buffer threshold reached"); |
| |
| promise_test((test) => { |
| counter = 0; |
| var gotEvent = false; |
| return new Promise((resolve, reject) => { |
| finishTest = resolve; |
| createConnections((localConnection) => { |
| localChannel = localConnection.createDataChannel('sendDataChannel'); |
| localChannel.onopen = () => { |
| sendContinuouslyMessages(localChannel); |
| localChannel.onbufferedamountlow = () => { |
| gotEvent = true; |
| } |
| }; |
| localChannel.bufferedAmountLowThreshold = 100000; |
| }, (remoteConnection) => { |
| remoteConnection.ondatachannel = (event) => { |
| remoteChannel = event.channel; |
| remoteChannel.onmessage = receiveMessages; |
| }; |
| }); |
| }).then (() => { |
| return waitFor(500); |
| }).then (() => { |
| closeDataChannels(); |
| assert_false(gotEvent, "got onbufferedamountlow event"); |
| }); |
| }, "Medium buffer threshold not reached"); |
| </script> |
| </body> |
| </html> |