RTCConfiguration-bundlePolicy.html (9013B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCConfiguration bundlePolicy</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="RTCPeerConnection-helper.js"></script> 7 <script src="./third_party/sdp/sdp.js"></script> 8 <script> 9 'use strict'; 10 11 // Test is based on the following editor draft: 12 // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html 13 14 /* 15 4.3.2. Interface Definition 16 [Constructor(optional RTCConfiguration configuration)] 17 interface RTCPeerConnection : EventTarget { 18 ... 19 RTCConfiguration getConfiguration(); 20 void setConfiguration(RTCConfiguration configuration); 21 }; 22 23 4.2.1. RTCConfiguration Dictionary 24 dictionary RTCConfiguration { 25 RTCBundlePolicy bundlePolicy = "balanced"; 26 ... 27 }; 28 29 4.2.6. RTCBundlePolicy Enum 30 enum RTCBundlePolicy { 31 "balanced", 32 "max-compat", 33 "max-bundle" 34 }; 35 */ 36 37 test(() => { 38 const pc = new RTCPeerConnection(); 39 assert_equals(pc.getConfiguration().bundlePolicy, 'balanced'); 40 }, 'Default bundlePolicy should be balanced'); 41 42 test(() => { 43 const pc = new RTCPeerConnection({ bundlePolicy: undefined }); 44 assert_equals(pc.getConfiguration().bundlePolicy, 'balanced'); 45 }, `new RTCPeerConnection({ bundlePolicy: undefined }) should have bundlePolicy balanced`); 46 47 test(() => { 48 const pc = new RTCPeerConnection({ bundlePolicy: 'balanced' }); 49 assert_equals(pc.getConfiguration().bundlePolicy, 'balanced'); 50 }, `new RTCPeerConnection({ bundlePolicy: 'balanced' }) should succeed`); 51 52 test(() => { 53 const pc = new RTCPeerConnection({ bundlePolicy: 'max-compat' }); 54 assert_equals(pc.getConfiguration().bundlePolicy, 'max-compat'); 55 }, `new RTCPeerConnection({ bundlePolicy: 'max-compat' }) should succeed`); 56 57 test(() => { 58 const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' }); 59 assert_equals(pc.getConfiguration().bundlePolicy, 'max-bundle'); 60 }, `new RTCPeerConnection({ bundlePolicy: 'max-bundle' }) should succeed`); 61 62 test(() => { 63 const pc = new RTCPeerConnection(); 64 pc.setConfiguration({}); 65 }, 'setConfiguration({}) with initial default bundlePolicy balanced should succeed'); 66 67 test(() => { 68 const pc = new RTCPeerConnection({ bundlePolicy: 'balanced' }); 69 pc.setConfiguration({}); 70 }, 'setConfiguration({}) with initial bundlePolicy balanced should succeed'); 71 72 test(() => { 73 const pc = new RTCPeerConnection(); 74 pc.setConfiguration({ bundlePolicy: 'balanced' }); 75 }, 'setConfiguration({ bundlePolicy: balanced }) with initial default bundlePolicy balanced should succeed'); 76 77 test(() => { 78 const pc = new RTCPeerConnection({ bundlePolicy: 'balanced' }); 79 pc.setConfiguration({ bundlePolicy: 'balanced' }); 80 }, `setConfiguration({ bundlePolicy: 'balanced' }) with initial bundlePolicy balanced should succeed`); 81 82 test(() => { 83 const pc = new RTCPeerConnection({ bundlePolicy: 'max-compat' }); 84 pc.setConfiguration({ bundlePolicy: 'max-compat' }); 85 }, `setConfiguration({ bundlePolicy: 'max-compat' }) with initial bundlePolicy max-compat should succeed`); 86 87 test(() => { 88 const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' }); 89 pc.setConfiguration({ bundlePolicy: 'max-bundle' }); 90 }, `setConfiguration({ bundlePolicy: 'max-bundle' }) with initial bundlePolicy max-bundle should succeed`); 91 92 test(() => { 93 assert_throws_js(TypeError, () => 94 new RTCPeerConnection({ bundlePolicy: null })); 95 }, `new RTCPeerConnection({ bundlePolicy: null }) should throw TypeError`); 96 97 test(() => { 98 assert_throws_js(TypeError, () => 99 new RTCPeerConnection({ bundlePolicy: 'invalid' })); 100 }, `new RTCPeerConnection({ bundlePolicy: 'invalid' }) should throw TypeError`); 101 102 /* 103 4.3.2. Interface Definition 104 To set a configuration 105 5. If configuration.bundlePolicy is set and its value differs from the 106 connection's bundle policy, throw an InvalidModificationError. 107 */ 108 test(() => { 109 const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' }); 110 assert_idl_attribute(pc, 'setConfiguration'); 111 112 assert_throws_dom('InvalidModificationError', () => 113 pc.setConfiguration({ bundlePolicy: 'max-compat' })); 114 }, `setConfiguration({ bundlePolicy: 'max-compat' }) with initial bundlePolicy max-bundle should throw InvalidModificationError`); 115 116 test(() => { 117 const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' }); 118 assert_idl_attribute(pc, 'setConfiguration'); 119 120 // the default value for bundlePolicy is balanced 121 assert_throws_dom('InvalidModificationError', () => 122 pc.setConfiguration({})); 123 }, `setConfiguration({}) with initial bundlePolicy max-bundle should throw InvalidModificationError`); 124 125 /* 126 Coverage Report 127 Tested 2 128 Total 2 129 */ 130 promise_test(async t => { 131 // balanced: Gather ICE candidates for each media type in use (audio, video, and data). 132 const pc = new RTCPeerConnection({bundlePolicy: 'balanced'}); 133 t.add_cleanup(() => pc.close()); 134 pc.addTransceiver('audio'); 135 pc.addTransceiver('audio'); // This should not gather candidates. 136 pc.addTransceiver('video'); 137 pc.createDataChannel('channel'); 138 139 await pc.setLocalDescription(); 140 await waitForIceGatheringState(pc, ['complete']); 141 const sections = SDPUtils.splitSections(pc.localDescription.sdp); 142 sections.shift(); 143 assert_equals(sections.length, 4); 144 const candidatesA1 = SDPUtils.matchPrefix(sections[0], 'a=candidate:'); 145 assert_greater_than(candidatesA1.length, 0, 'First audio m-line should have candidates'); 146 const candidatesA2 = SDPUtils.matchPrefix(sections[1], 'a=candidate:'); 147 assert_equals(candidatesA2.length, 0, 'Second audio m-line should have no candidates'); 148 const candidatesV = SDPUtils.matchPrefix(sections[2], 'a=candidate:'); 149 assert_greater_than(candidatesV.length, 0, 'First video m-line should have candidates'); 150 const candidatesD = SDPUtils.matchPrefix(sections[3], 'a=candidate:'); 151 assert_greater_than(candidatesD.length, 0, 'First data m-line should have candidates'); 152 }, '"balanced" bundle policy should gather ICE candidates for each media type in use'); 153 154 promise_test(async t => { 155 // max-compat: Gather ICE candidates for each track. 156 const pc = new RTCPeerConnection({bundlePolicy: 'max-compat'}); 157 t.add_cleanup(() => pc.close()); 158 pc.addTransceiver('audio'); 159 pc.addTransceiver('audio'); // This should gather candidates. 160 pc.addTransceiver('video'); 161 pc.createDataChannel('channel'); 162 163 await pc.setLocalDescription(); 164 await waitForIceGatheringState(pc, ['complete']); 165 const sections = SDPUtils.splitSections(pc.localDescription.sdp); 166 sections.shift(); 167 assert_equals(sections.length, 4); 168 const candidatesA1 = SDPUtils.matchPrefix(sections[0], 'a=candidate:'); 169 assert_greater_than(candidatesA1.length, 0, 'First audio m-line should have candidates'); 170 const candidatesA2 = SDPUtils.matchPrefix(sections[1], 'a=candidate:'); 171 assert_greater_than(candidatesA2.length, 0, 'Second audio m-line should have candidates'); 172 const candidatesV = SDPUtils.matchPrefix(sections[2], 'a=candidate:'); 173 assert_greater_than(candidatesV.length, 0, 'First video m-lne should have candidates'); 174 const candidatesD = SDPUtils.matchPrefix(sections[3], 'a=candidate:'); 175 assert_greater_than(candidatesD.length, 0, 'First data m-line should have candiates'); 176 }, '"max-compat" bundle policy should gather ICE candidates for each track'); 177 178 promise_test(async t => { 179 // max-bundle: Gather ICE candidates for only one track. 180 const pc = new RTCPeerConnection({bundlePolicy: 'max-bundle'}); 181 t.add_cleanup(() => pc.close()); 182 pc.addTransceiver('audio'); // Only first m-line gathers candidates. 183 pc.addTransceiver('audio'); 184 pc.addTransceiver('video'); 185 pc.createDataChannel('channel'); 186 187 await pc.setLocalDescription(); 188 await waitForIceGatheringState(pc, ['complete']); 189 const sections = SDPUtils.splitSections(pc.localDescription.sdp); 190 sections.shift(); 191 assert_equals(sections.length, 4); 192 const candidatesA1 = SDPUtils.matchPrefix(sections[0], 'a=candidate:'); 193 assert_greater_than(candidatesA1.length, 0, 'First audio m-line should have candidates'); 194 const candidatesA2 = SDPUtils.matchPrefix(sections[1], 'a=candidate:'); 195 assert_equals(candidatesA2.length, 0, 'Second audio m-line shoud have no candidates'); 196 const candidatesV = SDPUtils.matchPrefix(sections[2], 'a=candidate:'); 197 assert_equals(candidatesV.length, 0, 'Firt video m-line should have no candidates'); 198 const candidatesD = SDPUtils.matchPrefix(sections[3], 'a=candidate:'); 199 assert_equals(candidatesD.length, 0, 'First data m-line should have no candidates'); 200 }, '"max-bundle" bundle policy should gather ICE candidates for one track'); 201 </script>