Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!doctype html> | |
| 2 <meta charset=utf-8> | |
| 3 <title>RTCPeerConnection createDataChannel method</title> | |
| 4 <script src=/resources/testharness.js></script> | |
| 5 <script src=/resources/testharnessreport.js></script> | |
| 6 <script> | |
| 7 'use strict'; | |
| 8 | |
| 9 test(() => { | |
| 10 const pc = new RTCPeerConnection; | |
| 11 assert_equals(pc.createDataChannel.length, 1); | |
| 12 assert_throws(new TypeError, () => pc.createDataChannel()); | |
| 13 }, 'createDataChannel required arguments'); | |
| 14 | |
| 15 test(() => { | |
| 16 const pc = new RTCPeerConnection; | |
| 17 pc.close(); | |
| 18 assert_equals(pc.signalingState, 'closed', 'signaling state'); | |
| 19 assert_throws('InvalidStateError', () => pc.createDataChannel('')); | |
| 20 }, 'createDataChannel with closed connection'); | |
| 21 | |
| 22 test(() => { | |
| 23 const pc = new RTCPeerConnection; | |
| 24 const channel = pc.createDataChannel(''); | |
| 25 assert_true(channel instanceof RTCDataChannel, 'is RTCDataChannel'); | |
| 26 assert_equals(channel.label, '', 'label'); | |
| 27 assert_equals(channel.ordered, true, 'ordered'); | |
| 28 assert_equals(channel.maxPacketLifeTime, null, 'maxPacketLifeTime'); | |
| 29 assert_equals(channel.maxRetransmits, null, 'maxRetransmits'); | |
| 30 assert_equals(channel.protocol, '', 'protocol'); | |
| 31 assert_equals(channel.negotiated, false, 'negotiated'); | |
| 32 // Initial id value is not defined. | |
|
hbos_chromium
2017/04/19 09:15:33
The id was not specified and as such was generated
foolip
2017/04/20 11:52:03
I filed https://github.com/w3c/webrtc-pc/issues/11
| |
| 33 assert_equals(typeof channel.id, 'number', 'id type'); | |
| 34 assert_equals(channel.priority, 'low', 'priority'); | |
| 35 }, 'createDataChannel defaults'); | |
| 36 | |
| 37 const labels = [ | |
| 38 ['"foo"', 'foo', 'foo'], | |
| 39 ['null', null, 'null'], | |
| 40 ['undefined', undefined, 'undefined'], | |
| 41 ['lone surrogate', '\uD800', '\uFFFD'], | |
| 42 ]; | |
| 43 for (const [description, label, expected] of labels) { | |
| 44 test(() => { | |
| 45 const pc = new RTCPeerConnection; | |
| 46 const channel = pc.createDataChannel(label); | |
| 47 assert_equals(channel.label, expected); | |
| 48 }, 'createDataChannel with label ' + description); | |
| 49 } | |
| 50 | |
| 51 test(() => { | |
| 52 const pc = new RTCPeerConnection; | |
| 53 const channel = pc.createDataChannel('', { ordered: false }); | |
| 54 assert_equals(channel.ordered, false); | |
| 55 }, 'createDataChannel with ordered false'); | |
| 56 | |
| 57 // true as the default value of a boolean is confusing because null is converted | |
| 58 // to false while undefined is converted to true. | |
|
hbos_chromium
2017/04/19 09:15:33
(Oh man, I misread this comment not realizing you
foolip
2017/04/20 11:52:03
Sorry to almost have ruined your sanity :)
| |
| 59 test(() => { | |
| 60 const pc = new RTCPeerConnection; | |
| 61 const channel1 = pc.createDataChannel('', { ordered: null }); | |
| 62 assert_equals(channel1.ordered, false); | |
| 63 const channel2 = pc.createDataChannel('', { ordered: undefined }); | |
| 64 assert_equals(channel2.ordered, true); | |
| 65 }, 'createDataChannel with ordered null/undefined'); | |
| 66 | |
| 67 test(() => { | |
| 68 const pc = new RTCPeerConnection; | |
| 69 const channel = pc.createDataChannel('', { maxPacketLifeTime: 0 }); | |
| 70 assert_equals(channel.maxPacketLifeTime, 0); | |
| 71 }, 'createDataChannel with maxPacketLifeTime 0'); | |
| 72 | |
| 73 test(() => { | |
| 74 const pc = new RTCPeerConnection; | |
| 75 const channel = pc.createDataChannel('', { maxRetransmits: 0 }); | |
| 76 assert_equals(channel.maxRetransmits, 0); | |
| 77 }, 'createDataChannel with maxRetransmits 0'); | |
| 78 | |
| 79 test(() => { | |
| 80 const pc = new RTCPeerConnection; | |
| 81 assert_throws('SyntaxError', () => pc.createDataChannel('', { | |
| 82 maxPacketLifeTime: 0, | |
| 83 maxRetransmits: 0 | |
| 84 })); | |
| 85 }, 'createDataChannel with both maxPacketLifeTime and maxRetransmits'); | |
| 86 | |
| 87 const protocols = [ | |
| 88 ['"foo"', 'foo', 'foo'], | |
| 89 ['null', null, 'null'], | |
| 90 ['undefined', undefined, ''], | |
| 91 ['lone surrogate', '\uD800', '\uFFFD'], | |
| 92 ]; | |
| 93 for (const [description, protocol, expected] of protocols) { | |
| 94 test(() => { | |
| 95 const pc = new RTCPeerConnection; | |
| 96 const channel = pc.createDataChannel('', { protocol: protocol }); | |
| 97 assert_equals(channel.protocol, expected); | |
| 98 }, 'createDataChannel with protocol ' + description); | |
| 99 } | |
| 100 | |
| 101 test(() => { | |
| 102 const pc = new RTCPeerConnection; | |
| 103 const channel = pc.createDataChannel('', { negotiated: true }); | |
| 104 assert_equals(channel.negotiated, true); | |
| 105 }, 'createDataChannel with negotiated true'); | |
| 106 | |
| 107 test(() => { | |
| 108 const pc = new RTCPeerConnection; | |
| 109 const channel = pc.createDataChannel('', { id: 65534 }); | |
| 110 assert_equals(channel.id, 65534); | |
| 111 }, 'createDataChannel with id 65534'); | |
| 112 | |
| 113 test(() => { | |
| 114 const pc = new RTCPeerConnection; | |
| 115 assert_throws(new TypeError, () => pc.createDataChannel('', { id: 65535 })); | |
|
hbos_chromium
2017/04/19 09:15:33
Can you add a comment saying 65534 is the maximum
foolip
2017/04/20 11:52:03
Ah, will do.
foolip
2017/04/24 07:40:03
Wrote a comment and tested more numbers, now landi
| |
| 116 }, 'createDataChannel with id 65535'); | |
| 117 | |
| 118 test(() => { | |
| 119 const pc = new RTCPeerConnection; | |
| 120 const channel = pc.createDataChannel('', { priority: "high" }); | |
| 121 assert_equals(channel.priority, "high"); | |
| 122 }, 'createDataChannel with priority "high"'); | |
| 123 </script> | |
| OLD | NEW |