mirror of
https://github.com/servo/servo.git
synced 2025-09-05 20:48:22 +01:00
Update web-platform-tests to revision a46616a5b18e83587ddbbed756c7b96cbb4b015d
This commit is contained in:
parent
3f07cfec7c
commit
578498ba24
4001 changed files with 159517 additions and 30260 deletions
|
@ -0,0 +1,306 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>RTCPeerConnection.prototype.createDataChannel</title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
// Test is based on the following editor draft:
|
||||
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
|
||||
|
||||
/*
|
||||
6.1. RTCPeerConnection Interface Extensions
|
||||
|
||||
partial interface RTCPeerConnection {
|
||||
RTCDataChannel createDataChannel(USVString label,
|
||||
optional RTCDataChannelInit dataChannelDict);
|
||||
...
|
||||
};
|
||||
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
boolean ordered = true;
|
||||
unsigned short maxPacketLifeTime;
|
||||
unsigned short maxRetransmits;
|
||||
USVString protocol = "";
|
||||
boolean negotiated = false;
|
||||
[EnforceRange]
|
||||
unsigned short id;
|
||||
RTCPriorityType priority = "low";
|
||||
};
|
||||
*/
|
||||
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
assert_equals(pc.createDataChannel.length, 1);
|
||||
assert_throws(new TypeError(), () => pc.createDataChannel());
|
||||
}, 'createDataChannel with no argument should throw TypeError');
|
||||
|
||||
/*
|
||||
6.2. createDataChannel
|
||||
2. If connection's [[isClosed]] slot is true, throw an InvalidStateError.
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
pc.close();
|
||||
assert_equals(pc.signalingState, 'closed', 'signaling state');
|
||||
assert_throws('InvalidStateError', () => pc.createDataChannel(''));
|
||||
}, 'createDataChannel with closed connection should throw InvalidStateError');
|
||||
|
||||
/*
|
||||
6.2. createDataChannel
|
||||
4. Initialize channel's label attribute to the value of the first argument.
|
||||
5. Set channel's ordered , maxPacketLifeTime , maxRetransmits , protocol,
|
||||
negotiated , id and priority attributes to the values of the corresponding
|
||||
members of the dataChannelDict argument, using a value of null if the
|
||||
corresponding dictionary member is missing.
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
const channel = pc.createDataChannel('');
|
||||
assert_true(channel instanceof RTCDataChannel, 'is RTCDataChannel');
|
||||
assert_equals(channel.label, '', 'label');
|
||||
assert_equals(channel.ordered, true, 'ordered');
|
||||
assert_equals(channel.maxPacketLifeTime, null, 'maxPacketLifeTime');
|
||||
assert_equals(channel.maxRetransmits, null, 'maxRetransmits');
|
||||
assert_equals(channel.protocol, '', 'protocol');
|
||||
assert_equals(channel.negotiated, false, 'negotiated');
|
||||
// Since no offer/answer exchange has occurred yet, the DTLS role is unknown
|
||||
// and so the ID should be null.
|
||||
assert_equals(channel.id, null, 'id');
|
||||
assert_equals(channel.priority, 'low', 'priority');
|
||||
}, 'createDataChannel attribute default values');
|
||||
|
||||
|
||||
/*
|
||||
6.2. createDataChannel
|
||||
4. Initialize channel's label attribute to the value of the first argument.
|
||||
|
||||
[ECMA262] 7.1.12. ToString(argument)
|
||||
undefined -> "undefined"
|
||||
null -> "null"
|
||||
|
||||
[WebIDL] 3.10.15. Convert a DOMString to a sequence of Unicode scalar values
|
||||
*/
|
||||
const labels = [
|
||||
['"foo"', 'foo', 'foo'],
|
||||
['null', null, 'null'],
|
||||
['undefined', undefined, 'undefined'],
|
||||
['lone surrogate', '\uD800', '\uFFFD'],
|
||||
];
|
||||
for (const [description, label, expected] of labels) {
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection;
|
||||
const channel = pc.createDataChannel(label);
|
||||
assert_equals(channel.label, expected);
|
||||
}, `createDataChannel with label ${description} should succeed`);
|
||||
}
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
boolean ordered = true;
|
||||
...
|
||||
}
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
const channel = pc.createDataChannel('', { ordered: false });
|
||||
assert_equals(channel.ordered, false);
|
||||
}, 'createDataChannel with ordered false should succeed');
|
||||
|
||||
// true as the default value of a boolean is confusing because null is converted
|
||||
// to false while undefined is converted to true.
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
const channel1 = pc.createDataChannel('', { ordered: null });
|
||||
assert_equals(channel1.ordered, false);
|
||||
const channel2 = pc.createDataChannel('', { ordered: undefined });
|
||||
assert_equals(channel2.ordered, true);
|
||||
}, 'createDataChannel with ordered null/undefined should succeed');
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
unsigned short maxPacketLifeTime;
|
||||
...
|
||||
}
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection;
|
||||
const channel = pc.createDataChannel('', { maxPacketLifeTime: 0 });
|
||||
assert_equals(channel.maxPacketLifeTime, 0);
|
||||
}, 'createDataChannel with maxPacketLifeTime 0 should succeed');
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
unsigned short maxRetransmits;
|
||||
...
|
||||
}
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection;
|
||||
const channel = pc.createDataChannel('', { maxRetransmits: 0 });
|
||||
assert_equals(channel.maxRetransmits, 0);
|
||||
}, 'createDataChannel with maxRetransmits 0 should succeed');
|
||||
|
||||
/*
|
||||
6.2. createDataChannel
|
||||
8. If both the maxPacketLifeTime and maxRetransmits attributes are set
|
||||
(not null), throw a SyntaxError.
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection;
|
||||
assert_throws('SyntaxError', () => pc.createDataChannel('', {
|
||||
maxPacketLifeTime: 0,
|
||||
maxRetransmits: 0
|
||||
}));
|
||||
}, 'createDataChannel with both maxPacketLifeTime and maxRetransmits should throw SyntaxError');
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
USVString protocol = "";
|
||||
...
|
||||
}
|
||||
*/
|
||||
const protocols = [
|
||||
['"foo"', 'foo', 'foo'],
|
||||
['null', null, 'null'],
|
||||
['undefined', undefined, ''],
|
||||
['lone surrogate', '\uD800', '\uFFFD'],
|
||||
];
|
||||
for (const [description, protocol, expected] of protocols) {
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection;
|
||||
const channel = pc.createDataChannel('', { protocol });
|
||||
assert_equals(channel.protocol, expected);
|
||||
}, `createDataChannel with protocol ${description} should succeed`);
|
||||
}
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
boolean negotiated = false;
|
||||
...
|
||||
}
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection;
|
||||
const channel = pc.createDataChannel('', { negotiated: true });
|
||||
assert_equals(channel.negotiated, true);
|
||||
}, 'createDataChannel with negotiated true should succeed');
|
||||
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
[EnforceRange]
|
||||
unsigned short id;
|
||||
...
|
||||
}
|
||||
|
||||
createDataChannel
|
||||
10. If id is equal to 65535, which is greater than the maximum allowed ID
|
||||
of 65534 but still qualifies as an unsigned short, throw a TypeError.
|
||||
*/
|
||||
for (const id of [0, 1, 65534]) {
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
const channel = pc.createDataChannel('', { id });
|
||||
assert_equals(channel.id, id);
|
||||
}, `createDataChannel with id ${id} should succeed`);
|
||||
}
|
||||
|
||||
for (const id of [-1, 65535, 65536]) {
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
assert_throws(new TypeError(), () => pc.createDataChannel('', { id }));
|
||||
}, `createDataChannel with id ${id} should throw TypeError`);
|
||||
}
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
dictionary RTCDataChannelInit {
|
||||
RTCPriorityType priority = "low";
|
||||
...
|
||||
}
|
||||
|
||||
4.9.1. RTCPriorityType Enum
|
||||
enum RTCPriorityType {
|
||||
"very-low",
|
||||
"low",
|
||||
"medium",
|
||||
"high"
|
||||
};
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
const channel = pc.createDataChannel('', { priority: 'high' });
|
||||
assert_equals(channel.priority, 'high');
|
||||
}, 'createDataChannel with priority "high" should succeed');
|
||||
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
assert_throws(new TypeError(),
|
||||
() => pc.createDataChannel('', { priority: 'invalid' }));
|
||||
}, 'createDataChannel with invalid priority should throw TypeError');
|
||||
|
||||
/*
|
||||
6.2. createDataChannel
|
||||
6. If negotiated is false and label is longer than 65535 bytes long,
|
||||
throw a TypeError.
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
assert_throws(new TypeError(), () =>
|
||||
pc.createDataChannel('', {
|
||||
label: ' '.repeat(65536),
|
||||
negotiated: false
|
||||
}));
|
||||
}, 'createDataChannel with negotiated false and long label should throw TypeError');
|
||||
|
||||
/*
|
||||
6.2. createDataChannel
|
||||
7. If negotiated is false and protocol is longer than 65535 bytes long,
|
||||
throw a TypeError.
|
||||
*/
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
assert_throws(new TypeError(), () =>
|
||||
pc.createDataChannel('', {
|
||||
protocol: ' '.repeat(65536),
|
||||
negotiated: false
|
||||
}));
|
||||
}, 'createDataChannel with negotiated false and long protocol should throw TypeError');
|
||||
|
||||
test(() => {
|
||||
const pc = new RTCPeerConnection();
|
||||
pc.createDataChannel('', {
|
||||
label: ' '.repeat(65536),
|
||||
protocol: ' '.repeat(65536),
|
||||
negotiated: true
|
||||
});
|
||||
}, 'createDataChannel with negotiated true and long label and long protocol should succeed');
|
||||
|
||||
/*
|
||||
TODO
|
||||
6.2. createDataChannel
|
||||
11. If the id attribute is null (due to no ID being passed into
|
||||
createDataChannel), and the DTLS role of the SCTP transport has already
|
||||
been negotiated, then initialize id to a value generated by the user
|
||||
agent, according to [RTCWEB-DATA-PROTOCOL], and skip to the next step.
|
||||
If no available ID could be generated, or if the value of the id member
|
||||
of the dictionary is taken by an existing RTCDataChannel , throw a
|
||||
ResourceInUse exception.
|
||||
|
||||
Untestable
|
||||
6.2. createDataChannel
|
||||
9. If an attribute, either maxPacketLifeTime or maxRetransmits , has been
|
||||
set to indicate unreliable mode, and that value exceeds the maximum
|
||||
value supported by the user agent, the value must be set to the user
|
||||
agents maximum value.
|
||||
*/
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue