From f0d34871028720e69ff5a669c096882b1c73ef01 Mon Sep 17 00:00:00 2001 From: Taylor Brandstetter Date: Sat, 29 Apr 2017 21:44:31 -0700 Subject: [PATCH 1/3] Adding tests for RTCDataChannel id attribute. When no ID argument is provided, and the DTLS role hasn't been determined, the id attribute should return `null`. After the DTLS role is determined by an answer being applied with "a=setup:active" (or "passive"), the null IDs should be replaced with either odd or even IDs, depending on the negotiated role. --- .../RTCPeerConnection-createDataChannel.html | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/webrtc/RTCPeerConnection-createDataChannel.html b/webrtc/RTCPeerConnection-createDataChannel.html index cb05e2ca068032c..423178ddbcbbc33 100644 --- a/webrtc/RTCPeerConnection-createDataChannel.html +++ b/webrtc/RTCPeerConnection-createDataChannel.html @@ -29,11 +29,70 @@ assert_equals(channel.maxRetransmits, null, 'maxRetransmits'); assert_equals(channel.protocol, '', 'protocol'); assert_equals(channel.negotiated, false, 'negotiated'); - // Initial id value is not defined. - assert_equals(typeof channel.id, 'number', 'id type'); + // 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 defaults'); +async_test(test => { + const pc = new RTCPeerConnection; + const channel = pc.createDataChannel(''); + pc.createOffer() + .then(function(offer) { + return pc.setLocalDescription(offer); + }) + .then(function() { + // Turn our own offer SDP into valid answer SDP by setting the DTLS role to + // "active". + const answer = new RTCSessionDescription({ + type: "answer", + sdp: pc.localDescription.sdp.replace("actpass", "active") + }); + return pc.setRemoteDescription(answer); + }) + .then(function() { + // Since the remote description had an "active" DTLS role, we're the server + // and should use odd data channel IDs, according to rtcweb-data-channel. + assert_equals(channel.id, 1, 'id'); + const another_channel = pc.createDataChannel('another'); + assert_equals(another_channel.id, 3, 'id'); + test.done(); + }) + .catch(test.step_func(function(e) { + assert_unreached('Error ' + e.name + ': ' + e.message); + })); +}, "DTLS client uses odd data channel IDs"); + +async_test(test => { + const pc = new RTCPeerConnection; + const channel = pc.createDataChannel(''); + pc.createOffer() + .then(function(offer) { + return pc.setLocalDescription(offer); + }) + .then(function() { + // Turn our own offer SDP into valid answer SDP by setting the DTLS role to + // "passive". + const answer = new RTCSessionDescription({ + type: "answer", + sdp: pc.localDescription.sdp.replace("actpass", "passive") + }); + return pc.setRemoteDescription(answer); + }) + .then(function() { + // Since the remote description had a "passive" DTLS role, we're the client + // and should use even data channel IDs, according to rtcweb-data-channel. + assert_equals(channel.id, 0, 'id'); + const another_channel = pc.createDataChannel('another'); + assert_equals(another_channel.id, 2, 'id'); + test.done(); + }) + .catch(test.step_func(function(e) { + assert_unreached('Error ' + e.name + ': ' + e.message); + })); +}, "DTLS server uses even data channel IDs"); + const labels = [ ['"foo"', 'foo', 'foo'], ['null', null, 'null'], From 1f5e055f475169ed70a75d23d6160da012b28e28 Mon Sep 17 00:00:00 2001 From: Taylor Brandstetter Date: Mon, 1 May 2017 14:15:20 -0700 Subject: [PATCH 2/3] Allow any distinct odd/even IDs; don't require "0, 2, 4, ..." --- webrtc/RTCPeerConnection-createDataChannel.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/webrtc/RTCPeerConnection-createDataChannel.html b/webrtc/RTCPeerConnection-createDataChannel.html index 423178ddbcbbc33..7edaa778f6dcf9d 100644 --- a/webrtc/RTCPeerConnection-createDataChannel.html +++ b/webrtc/RTCPeerConnection-createDataChannel.html @@ -54,9 +54,10 @@ .then(function() { // Since the remote description had an "active" DTLS role, we're the server // and should use odd data channel IDs, according to rtcweb-data-channel. - assert_equals(channel.id, 1, 'id'); + assert_equals(channel.id % 2, 1, 'id'); const another_channel = pc.createDataChannel('another'); - assert_equals(another_channel.id, 3, 'id'); + assert_equals(another_channel.id % 2, 1, 'id'); + assert_not_equals(channel.id, another_channel.id); test.done(); }) .catch(test.step_func(function(e) { @@ -83,9 +84,10 @@ .then(function() { // Since the remote description had a "passive" DTLS role, we're the client // and should use even data channel IDs, according to rtcweb-data-channel. - assert_equals(channel.id, 0, 'id'); + assert_equals(channel.id % 2, 0, 'id'); const another_channel = pc.createDataChannel('another'); - assert_equals(another_channel.id, 2, 'id'); + assert_equals(another_channel.id % 2, 0, 'id'); + assert_not_equals(channel.id, another_channel.id); test.done(); }) .catch(test.step_func(function(e) { From 97c3ec1e243dc91c487d4a5a7fa0df1ca062cb17 Mon Sep 17 00:00:00 2001 From: Taylor Brandstetter Date: Sun, 7 May 2017 15:23:23 -0700 Subject: [PATCH 3/3] Move data channel ID tests to new file, follow foolip's other advice. --- webrtc/RTCDataChannel-id.html | 60 +++++++++++++++++++ .../RTCPeerConnection-createDataChannel.html | 60 ------------------- 2 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 webrtc/RTCDataChannel-id.html diff --git a/webrtc/RTCDataChannel-id.html b/webrtc/RTCDataChannel-id.html new file mode 100644 index 000000000000000..7128da8bc04abe7 --- /dev/null +++ b/webrtc/RTCDataChannel-id.html @@ -0,0 +1,60 @@ + + +RTCDataChannel id attribute + + + diff --git a/webrtc/RTCPeerConnection-createDataChannel.html b/webrtc/RTCPeerConnection-createDataChannel.html index 7edaa778f6dcf9d..9a50b18c41e60a0 100644 --- a/webrtc/RTCPeerConnection-createDataChannel.html +++ b/webrtc/RTCPeerConnection-createDataChannel.html @@ -35,66 +35,6 @@ assert_equals(channel.priority, 'low', 'priority'); }, 'createDataChannel defaults'); -async_test(test => { - const pc = new RTCPeerConnection; - const channel = pc.createDataChannel(''); - pc.createOffer() - .then(function(offer) { - return pc.setLocalDescription(offer); - }) - .then(function() { - // Turn our own offer SDP into valid answer SDP by setting the DTLS role to - // "active". - const answer = new RTCSessionDescription({ - type: "answer", - sdp: pc.localDescription.sdp.replace("actpass", "active") - }); - return pc.setRemoteDescription(answer); - }) - .then(function() { - // Since the remote description had an "active" DTLS role, we're the server - // and should use odd data channel IDs, according to rtcweb-data-channel. - assert_equals(channel.id % 2, 1, 'id'); - const another_channel = pc.createDataChannel('another'); - assert_equals(another_channel.id % 2, 1, 'id'); - assert_not_equals(channel.id, another_channel.id); - test.done(); - }) - .catch(test.step_func(function(e) { - assert_unreached('Error ' + e.name + ': ' + e.message); - })); -}, "DTLS client uses odd data channel IDs"); - -async_test(test => { - const pc = new RTCPeerConnection; - const channel = pc.createDataChannel(''); - pc.createOffer() - .then(function(offer) { - return pc.setLocalDescription(offer); - }) - .then(function() { - // Turn our own offer SDP into valid answer SDP by setting the DTLS role to - // "passive". - const answer = new RTCSessionDescription({ - type: "answer", - sdp: pc.localDescription.sdp.replace("actpass", "passive") - }); - return pc.setRemoteDescription(answer); - }) - .then(function() { - // Since the remote description had a "passive" DTLS role, we're the client - // and should use even data channel IDs, according to rtcweb-data-channel. - assert_equals(channel.id % 2, 0, 'id'); - const another_channel = pc.createDataChannel('another'); - assert_equals(another_channel.id % 2, 0, 'id'); - assert_not_equals(channel.id, another_channel.id); - test.done(); - }) - .catch(test.step_func(function(e) { - assert_unreached('Error ' + e.name + ': ' + e.message); - })); -}, "DTLS server uses even data channel IDs"); - const labels = [ ['"foo"', 'foo', 'foo'], ['null', null, 'null'],