Fix a lot of RTCDataChannel parameter checks
Bug: 949297
Change-Id: I5f0255f9c5b51f0325cb232bf66affbce04a107e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1552080
Commit-Queue: Harald Alvestrand <hta@chromium.org>
Reviewed-by: Henrik Boström <hbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#647702}
diff --git a/webrtc/RTCPeerConnection-createDataChannel.html b/webrtc/RTCPeerConnection-createDataChannel.html
index ae74b62..4ae9e78 100644
--- a/webrtc/RTCPeerConnection-createDataChannel.html
+++ b/webrtc/RTCPeerConnection-createDataChannel.html
@@ -60,7 +60,7 @@
};
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -72,7 +72,7 @@
6.2. createDataChannel
2. If connection's [[isClosed]] slot is true, throw an InvalidStateError.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
pc.close();
assert_equals(pc.signalingState, 'closed', 'signaling state');
@@ -128,7 +128,7 @@
[...] When a RTCDataChannel object is created, the binaryType attribute MUST
be initialized to the string "blob".
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -151,14 +151,14 @@
assert_equals(dc.binaryType, 'blob');
}, 'createDataChannel attribute default values');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
const dc = pc.createDataChannel('test', {
ordered: false,
- maxPacketLifeTime: null,
maxRetransmits: 1,
+ // Note: maxPacketLifeTime is not set in this test.
protocol: 'custom',
negotiated: true,
id: 3,
@@ -178,6 +178,14 @@
assert_equals(dc.bufferedAmount, 0);
assert_equals(dc.bufferedAmountLowThreshold, 0);
assert_equals(dc.binaryType, 'blob');
+
+ const dc2 = pc.createDataChannel('test2', {
+ ordered: false,
+ maxPacketLifeTime: 42
+ });
+ assert_equals(dc2.label, 'test2');
+ assert_equals(dc2.maxPacketLifeTime, 42);
+ assert_equals(dc.maxRetransmits, null);
}, 'createDataChannel with provided parameters should initialize attributes to provided values');
/*
@@ -198,7 +206,7 @@
['lone surrogate', '\uD800', '\uFFFD'],
];
for (const [description, label, expected] of labels) {
- test((t) => {
+ test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -213,7 +221,7 @@
11. Let channel have an [[Ordered]] internal slot initialized to option's
ordered member.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -223,7 +231,7 @@
// true as the default value of a boolean is confusing because null is converted
// to false while undefined is converted to true.
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -239,7 +247,7 @@
7. Let channel have an [[MaxPacketLifeTime]] internal slot initialized to
option's maxPacketLifeTime member, if present, otherwise null.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -253,7 +261,7 @@
10. Let channel have an [[MaxRetransmits]] internal slot initialized to
option's maxRetransmits member, if present, otherwise null.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -266,17 +274,17 @@
18. If both [[MaxPacketLifeTime]] and [[MaxRetransmits]] attributes are set (not null),
throw a TypeError.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
pc.createDataChannel('', {
- maxPacketLifeTime: null,
- maxRetransmits: null
+ maxPacketLifeTime: undefined,
+ maxRetransmits: undefined
});
-}, 'createDataChannel with both maxPacketLifeTime and maxRetransmits null should succeed');
+}, 'createDataChannel with both maxPacketLifeTime and maxRetransmits undefined should succeed');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -303,7 +311,7 @@
['lone surrogate', '\uD800', '\uFFFD'],
];
for (const [description, protocol, expected] of protocols) {
- test((t) => {
+ test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -319,7 +327,7 @@
ID of 65534 but still qualifies as an unsigned short, throw a TypeError.
*/
for (const id of [0, 1, 65534]) {
- test((t) => {
+ test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -329,7 +337,7 @@
}
for (const id of [-1, 65535, 65536]) {
- test((t) => {
+ test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -343,7 +351,7 @@
17. Let channel have an [[DataChannelPriority]] internal slot initialized to option's
priority member.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -351,7 +359,7 @@
assert_equals(dc.priority, 'high');
}, 'createDataChannel with priority "high" should succeed');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -363,7 +371,7 @@
6.2. createDataChannel
5. If [[DataChannelLabel]] is longer than 65535 bytes, throw a TypeError.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -377,7 +385,7 @@
}));
}, 'createDataChannel with too long label should throw TypeError');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -411,13 +419,14 @@
13. If [[DataChannelProtocol]] is longer than 65535 bytes long, throw a TypeError.
*/
-test(() => {
+test(t => {
const pc = new RTCPeerConnection;
- const channel = pc.createDataChannel('', { negotiated: true });
+ t.add_cleanup(() => pc.close());
+ const channel = pc.createDataChannel('', { negotiated: true, id: 42 });
assert_equals(channel.negotiated, true);
-}, 'createDataChannel with negotiated true should succeed');
+}, 'createDataChannel with negotiated true and id should succeed');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -434,7 +443,7 @@
}));
}, 'createDataChannel with too long protocol should throw TypeError');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -451,7 +460,7 @@
}));
}, 'createDataChannel with too long protocol (2 byte unicode) should throw TypeError');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -476,7 +485,7 @@
is intentional. Data channels negotiated in-band should have IDs selected based on the
DTLS role, as specified in [RTCWEB-DATA-PROTOCOL].
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -486,7 +495,7 @@
assert_equals(dc.negotiated, false, 'Expect dc.negotiated to be false');
}, 'createDataChannel with negotiated false should succeed');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection;
t.add_cleanup(() => pc.close());
@@ -502,7 +511,7 @@
6.2. createDataChannel
16. If [[Negotiated]] is true and [[DataChannelId]] is null, throw a TypeError.
*/
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -512,17 +521,6 @@
}));
}, 'createDataChannel with negotiated true and id not defined should throw TypeError');
-test((t) => {
- const pc = new RTCPeerConnection();
- t.add_cleanup(() => pc.close());
-
- assert_throws(new TypeError(), () =>
- pc.createDataChannel('test', {
- negotiated: true,
- id: null
- }));
-}, 'createDataChannel with negotiated true and id null should throw TypeError');
-
/*
4.4.1.6. Set the RTCSessionSessionDescription
2.2.6. If description is of type "answer" or "pranswer", then run the
@@ -544,7 +542,7 @@
If the [[DataChannelId]] slot is null after this step, it will be populated once
the DTLS role is determined during the process of setting an RTCSessionDescription.
*/
-promise_test(async (t) => {
+promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
@@ -597,7 +595,7 @@
'Expect negotiatedDc.id to be 42 after remote description has been set');
}, 'Channels created (after setRemoteDescription) should have id assigned');
-test((t) => {
+test(t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
@@ -625,7 +623,7 @@
// We've seen implementations behaving differently before and after the connection has been
// established.
-promise_test(async (t) => {
+promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
@@ -660,7 +658,7 @@
}, 'Reusing a data channel id that is in use (after setRemoteDescription) should throw ' +
'OperationError');
-promise_test(async (t) => {
+promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
@@ -685,7 +683,7 @@
'should throw OperationError');
// Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1441723
-promise_test(async (t) => {
+promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
diff --git a/webrtc/RTCPeerConnection-ondatachannel.html b/webrtc/RTCPeerConnection-ondatachannel.html
index 7110274..2fd33ca 100644
--- a/webrtc/RTCPeerConnection-ondatachannel.html
+++ b/webrtc/RTCPeerConnection-ondatachannel.html
@@ -355,7 +355,8 @@
pc2.ondatachannel = t.unreached_func('datachannel event should not be fired');
pc1.createDataChannel('test', {
- negotiated: true
+ negotiated: true,
+ id: 42
});
exchangeIceCandidates(pc1, pc2);