| Taylor Brandstetter | ce56f0e | 2017-05-09 13:53:14 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>RTCDataChannel id attribute</title> |
| 4 | <script src=/resources/testharness.js></script> |
| 5 | <script src=/resources/testharnessreport.js></script> |
| 6 | <script> |
| 7 | 'use strict'; |
| 8 | |
| 9 | // This and the test below verify that after a description is set that |
| 10 | // negotiates the DTLS role used by SCTP, data channels with unset IDs |
| 11 | // have IDs set according to the rules in rtcweb-data-channel. |
| 12 | promise_test(test => { |
| 13 | const pc = new RTCPeerConnection; |
| 14 | const channel = pc.createDataChannel(''); |
| 15 | return pc.createOffer() |
| 16 | .then(offer => pc.setLocalDescription(offer)) |
| 17 | .then(() => { |
| 18 | // Turn our own offer SDP into valid answer SDP by setting the DTLS role to |
| 19 | // "active". |
| 20 | const answer = { |
| 21 | type: "answer", |
| 22 | sdp: pc.localDescription.sdp.replace("actpass", "active") |
| 23 | }; |
| 24 | return pc.setRemoteDescription(answer); |
| 25 | }) |
| 26 | .then(() => { |
| 27 | // Since the remote description had an "active" DTLS role, we're the server |
| 28 | // and should use odd data channel IDs, according to rtcweb-data-channel. |
| 29 | assert_equals(channel.id % 2, 1, 'id'); |
| 30 | const another_channel = pc.createDataChannel('another'); |
| 31 | assert_equals(another_channel.id % 2, 1, 'id'); |
| 32 | assert_not_equals(channel.id, another_channel.id); |
| 33 | }) |
| 34 | }, "DTLS client uses odd data channel IDs"); |
| 35 | |
| 36 | promise_test(test => { |
| 37 | const pc = new RTCPeerConnection; |
| 38 | const channel = pc.createDataChannel(''); |
| 39 | return pc.createOffer() |
| 40 | .then(offer => pc.setLocalDescription(offer)) |
| 41 | .then(() => { |
| 42 | // Turn our own offer SDP into valid answer SDP by setting the DTLS role to |
| 43 | // "passive". |
| 44 | const answer = { |
| 45 | type: "answer", |
| 46 | sdp: pc.localDescription.sdp.replace("actpass", "passive") |
| 47 | }; |
| 48 | return pc.setRemoteDescription(answer); |
| 49 | }) |
| 50 | .then(() => { |
| 51 | // Since the remote description had a "passive" DTLS role, we're the client |
| 52 | // and should use even data channel IDs, according to rtcweb-data-channel. |
| 53 | assert_equals(channel.id % 2, 0, 'id'); |
| 54 | const another_channel = pc.createDataChannel('another'); |
| 55 | assert_equals(another_channel.id % 2, 0, 'id'); |
| 56 | assert_not_equals(channel.id, another_channel.id); |
| 57 | }) |
| 58 | }, "DTLS server uses even data channel IDs"); |
| 59 | |
| 60 | </script> |