RTCPeerConnectionIceEvent-constructor.html (3789B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <!-- 4 4.8.2 RTCPeerConnectionIceEvent 5 6 The icecandidate event of the RTCPeerConnection uses the RTCPeerConnectionIceEvent interface. 7 8 --> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script> 12 /* 13 RTCPeerConnectionIceEvent 14 15 [Constructor(DOMString type, optional RTCPeerConnectionIceEventInit eventInitDict)] 16 17 interface RTCPeerConnectionIceEvent : Event { 18 readonly attribute RTCIceCandidate? candidate; 19 readonly attribute DOMString? url; 20 }; 21 */ 22 test(() => { 23 assert_throws_js(TypeError, () => { 24 new RTCPeerConnectionIceEvent(); 25 }); 26 }, "RTCPeerConnectionIceEvent with no arguments throws TypeError"); 27 28 test(() => { 29 const event = new RTCPeerConnectionIceEvent("type"); 30 /* 31 candidate of type RTCIceCandidate, readonly, nullable 32 url of type DOMString, readonly, nullable 33 */ 34 assert_equals(event.candidate, null); 35 assert_equals(event.url, null); 36 37 /* 38 Firing an RTCPeerConnectionIceEvent event named e with an RTCIceCandidate 39 candidate means that an event with the name e, which does not bubble 40 (except where otherwise stated) and is not cancelable 41 (except where otherwise stated), 42 */ 43 assert_false(event.bubbles); 44 assert_false(event.cancelable); 45 46 }, "RTCPeerConnectionIceEvent with no eventInitDict (default)"); 47 48 test(() => { 49 const event = new RTCPeerConnectionIceEvent("type", {}); 50 51 /* 52 candidate of type RTCIceCandidate, readonly, nullable 53 url of type DOMString, readonly, nullable 54 */ 55 assert_equals(event.candidate, null); 56 assert_equals(event.url, null); 57 58 /* 59 Firing an RTCPeerConnectionIceEvent event named e with an RTCIceCandidate 60 candidate means that an event with the name e, which does not bubble 61 (except where otherwise stated) and is not cancelable 62 (except where otherwise stated), 63 */ 64 assert_false(event.bubbles); 65 assert_false(event.cancelable); 66 67 }, "RTCPeerConnectionIceEvent with empty object as eventInitDict (default)"); 68 69 test(() => { 70 const event = new RTCPeerConnectionIceEvent("type", { 71 candidate: null 72 }); 73 assert_equals(event.candidate, null); 74 }, "RTCPeerConnectionIceEvent.candidate is null when constructed with { candidate: null }"); 75 76 test(() => { 77 const event = new RTCPeerConnectionIceEvent("type", { 78 candidate: undefined 79 }); 80 assert_equals(event.candidate, null); 81 }, "RTCPeerConnectionIceEvent.candidate is null when constructed with { candidate: undefined }"); 82 83 84 /* 85 86 4.8.1 RTCIceCandidate Interface 87 88 The RTCIceCandidate() constructor takes a dictionary argument, candidateInitDict, 89 whose content is used to initialize the new RTCIceCandidate object. When run, if 90 both the sdpMid and sdpMLineIndex dictionary members are null, throw a TypeError. 91 */ 92 const candidate = ""; 93 const sdpMid = "sdpMid"; 94 const sdpMLineIndex = 1; 95 const usernameFragment = ""; 96 const url = "foo.bar"; 97 98 test(() => { 99 const iceCandidate = new RTCIceCandidate({ candidate, sdpMid, sdpMLineIndex, usernameFragment }); 100 const event = new RTCPeerConnectionIceEvent("type", { 101 candidate: iceCandidate, 102 url, 103 }); 104 105 assert_equals(event.candidate, iceCandidate); 106 assert_false(event.bubbles); 107 assert_false(event.cancelable); 108 }, "RTCPeerConnectionIceEvent with RTCIceCandidate"); 109 110 test(() => { 111 const plain = { candidate, sdpMid, sdpMLineIndex, usernameFragment }; 112 assert_throws_js(TypeError, () => new RTCPeerConnectionIceEvent("type", { candidate: plain })); 113 }, "RTCPeerConnectionIceEvent with non RTCIceCandidate object throws"); 114 115 test(() => { 116 const event = new RTCPeerConnectionIceEvent("type", { 117 candidate: null, 118 bubbles: true, 119 cancelable: true, 120 }); 121 122 assert_true(event.bubbles); 123 assert_true(event.cancelable); 124 }, "RTCPeerConnectionIceEvent bubbles and cancelable"); 125 126 </script>