Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new tests and remove obsolete ones as per PR13499 #14419

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions webrtc/RTCDataChannel-binaryType.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<meta charset=utf-8>
<title>RTCDataChannel.prototype.binaryType</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';

// Test is based on the following revision:
// https://rawgit.com/w3c/webrtc-pc/1cc5bfc3ff18741033d804c4a71f7891242fb5b3/webrtc.html

/*
6.2. RTCDataChannel
interface RTCDataChannel : EventTarget {
...
attribute DOMString binaryType;
...
};
*/

const validBinaryTypes = ['blob', 'arraybuffer'];
const invalidBinaryTypes = ['jellyfish', 'arraybuffer '];

/*
6.2. RTCDataChannel
binaryType
The binaryType attribute MUST, on getting, return the value to which it was last
set. On setting, if the new value is either the string "blob" or the string
"arraybuffer", then set the IDL attribute to this new value. Otherwise, throw a
SyntaxError. When an RTCDataChannel object is created, the binaryType attribute
MUST be initialized to the string "blob".
*/
for (const binaryType of validBinaryTypes) {
test((t) => {
const pc = new RTCPeerConnection();
const dc = pc.createDataChannel('test-binary-type');

dc.binaryType = binaryType;
assert_equals(dc.binaryType, binaryType, `dc.binaryType should be '${binaryType}'`);
}, `Setting binaryType to '${binaryType}' should succeed`);
}

for (const binaryType of invalidBinaryTypes) {
test((t) => {
const pc = new RTCPeerConnection();
const dc = pc.createDataChannel('test-binary-type');

assert_throws('SyntaxError', () => {
dc.binaryType = binaryType;
});
}, `Setting invalid binaryType '${binaryType}' should throw SyntaxError`);
}

/*
The default value of 'binaryType' is tested in RTCPeerConnection-createDataChannel.

Aspects on switching on 'binaryType' when receiving have been covered in
RTCDataChannel-send-receive.
*/
</script>
185 changes: 185 additions & 0 deletions webrtc/RTCDataChannel-bufferedAmountLowThreshold.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<!doctype html>
<meta charset=utf-8>
<title>RTCDataChannel.bufferedAmountLowThreshold</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';

// Disable global timeout
// IMPORTANT: You need to add a timeout to *every test* of this file!
setup({ explicit_timeout: true });

// Test is based on the following revision:
// https://rawgit.com/w3c/webrtc-pc/1cc5bfc3ff18741033d804c4a71f7891242fb5b3/webrtc.html

/*
6.2. bufferedAmountLowThreshold

The bufferedAmountLowThreshold attribute sets the threshold at which the bufferedAmount is
considered to be low. When the bufferedAmount decreases from above this threshold to equal
or below it, the bufferedamountlow event fires. The bufferedAmountLowThreshold is initially
zero on each new RTCDataChannel, but the application may change its value at any time.

13. bufferedamountlow

The RTCDataChannel object's bufferedAmount decreases from above its
bufferedAmountLowThreshold to less than or equal to its bufferedAmountLowThreshold.
*/
const messages = [
['meow', 4, 'DOMString of 4 bytes'],
[new Uint8Array(65536).fill(0xde), 65536, 'Uint8Array of 65536 bytes'],
];

for (const [message, length, description] of messages) {
promise_test(async (t) => {
const resolver = new Resolver();
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());

const dc = pc1.createDataChannel('test');

// Send once the channel opened
dc.onopen = t.step_func(() => {
dc.send(message);
});

// Done once the event has been raised
assert_equals(dc.bufferedAmountLowThreshold, 0,
'bufferedAmountLowThreshold should be 0 by default');
dc.onbufferedamountlow = t.step_func(() => {
assert_equals(dc.bufferedAmount, 0, 'bufferedAmount should be 0 once the event has fired');
resolver.resolve();
});

exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);

t.step_timeout(() => assert_unreached('bufferedamountlow event did not fire in time'), 2000);

await resolver;
}, `${description}: bufferedamountlow event should fire once bufferedAmount <= 0 (default)`, {
timeout: 5000
});

const thresholds = [
Math.floor(length / 2),
length,
length * 2,
];

for (const threshold of thresholds) {
promise_test(async (t) => {
const resolver = new Resolver();
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());

const dc = pc1.createDataChannel('test');
dc.bufferedAmountLowThreshold = threshold;

// Send once the channel opened
dc.onopen = t.step_func(() => {
dc.send(message);
});

// Done once the event has been raised
assert_equals(dc.bufferedAmountLowThreshold, threshold,
`bufferedAmountLowThreshold should be ${threshold}`);
dc.onbufferedamountlow = t.step_func(() => {
assert_less_than_equal(dc.bufferedAmount, threshold,
`bufferedAmount should be <= ${threshold} once the event has fired`);
resolver.resolve();
});

exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);

t.step_timeout(() => assert_unreached('bufferedamountlow event did not fire in time'), 2000);

await resolver;
}, `${description}: bufferedamountlow event should fire once bufferedAmount <=
${threshold} (custom)`, {
timeout: 5000
});
}

for (const threshold of thresholds) {
promise_test(async (t) => {
const resolver = new Resolver();
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());

const dc = pc1.createDataChannel('test');
dc.bufferedAmountLowThreshold = threshold;

// Send once the channel opened
dc.onopen = t.step_func(() => {
for (let i = 0; i < 10; ++i) {
dc.send(message);
}
});

// Done once the event has been raised
assert_equals(dc.bufferedAmountLowThreshold, threshold,
`bufferedAmountLowThreshold should be ${threshold}`);
dc.onbufferedamountlow = t.step_func(() => {
assert_less_than_equal(dc.bufferedAmount, threshold,
`bufferedAmount should be <= ${threshold} once the event has fired`);
resolver.resolve();
});

exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);

t.step_timeout(() => assert_unreached('bufferedamountlow event did not fire in time'), 2000);

await resolver;
}, `${description} x 10: bufferedamountlow event should fire once bufferedAmount <=
${threshold} (custom)`, {
timeout: 5000
});
}

promise_test(async (t) => {
const resolver = new Resolver();
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());

const dc1 = pc1.createDataChannel('test');

// Send once the channel opened
dc1.onopen = t.step_func(() => {
dc1.send(message);
});

// Done once the event has been raised (and the other channel did not fire)
dc1.onbufferedamountlow = t.step_func(() => {
t.step_timeout(t.step_func_done(), 100);
});

const dc2 = pc1.createDataChannel('test-2');
dc2.onbufferedamountlow = t.step_func(() => {
assert_unreached('dc2 should not fire bufferedamountlow');
});

exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);

t.step_timeout(() => assert_unreached('bufferedamountlow event did not fire in time'), 2000);

await resolver;
}, `${description}: bufferedamountlow event should not fire on other channels`, {
timeout: 5000
});

}
</script>
Loading