| 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; |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame^] | 14 | test.add_cleanup(() => pc.close()); |
| Taylor Brandstetter | ce56f0e | 2017-05-09 13:53:14 | [diff] [blame] | 15 | const channel = pc.createDataChannel(''); |
| 16 | return pc.createOffer() |
| 17 | .then(offer => pc.setLocalDescription(offer)) |
| 18 | .then(() => { |
| 19 | // Turn our own offer SDP into valid answer SDP by setting the DTLS role to |
| 20 | // "active". |
| 21 | const answer = { |
| 22 | type: "answer", |
| 23 | sdp: pc.localDescription.sdp.replace("actpass", "active") |
| 24 | }; |
| 25 | return pc.setRemoteDescription(answer); |
| 26 | }) |
| 27 | .then(() => { |
| 28 | // Since the remote description had an "active" DTLS role, we're the server |
| 29 | // and should use odd data channel IDs, according to rtcweb-data-channel. |
| 30 | assert_equals(channel.id % 2, 1, 'id'); |
| 31 | const another_channel = pc.createDataChannel('another'); |
| 32 | assert_equals(another_channel.id % 2, 1, 'id'); |
| 33 | assert_not_equals(channel.id, another_channel.id); |
| 34 | }) |
| 35 | }, "DTLS client uses odd data channel IDs"); |
| 36 | |
| 37 | promise_test(test => { |
| 38 | const pc = new RTCPeerConnection; |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame^] | 39 | test.add_cleanup(() => pc.close()); |
| Taylor Brandstetter | ce56f0e | 2017-05-09 13:53:14 | [diff] [blame] | 40 | const channel = pc.createDataChannel(''); |
| 41 | return pc.createOffer() |
| 42 | .then(offer => pc.setLocalDescription(offer)) |
| 43 | .then(() => { |
| 44 | // Turn our own offer SDP into valid answer SDP by setting the DTLS role to |
| 45 | // "passive". |
| 46 | const answer = { |
| 47 | type: "answer", |
| 48 | sdp: pc.localDescription.sdp.replace("actpass", "passive") |
| 49 | }; |
| 50 | return pc.setRemoteDescription(answer); |
| 51 | }) |
| 52 | .then(() => { |
| 53 | // Since the remote description had a "passive" DTLS role, we're the client |
| 54 | // and should use even data channel IDs, according to rtcweb-data-channel. |
| 55 | assert_equals(channel.id % 2, 0, 'id'); |
| 56 | const another_channel = pc.createDataChannel('another'); |
| 57 | assert_equals(another_channel.id % 2, 0, 'id'); |
| 58 | assert_not_equals(channel.id, another_channel.id); |
| 59 | }) |
| 60 | }, "DTLS server uses even data channel IDs"); |
| 61 | |
| 62 | </script> |