DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
<!doctype html>
<title>RTCIceCandidate constructor</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
  'use strict';

  const candidateString = 'candidate:1905690388 1 udp 2113937151 192.168.0.1 58041 typ host generation 0 ufrag thC8 network-cost 50';
  const candidateString2 = 'candidate:435653019 2 tcp 1845501695 192.168.0.196 4444 typ srflx raddr www.example.com rport 22222 tcptype active';
  const arbitraryString = '<arbitrary string[0] content>;';

  test(t => {
    // The argument for RTCIceCandidateInit is optional (w3c/webrtc-pc #1153 #1166),
    // but the constructor throws because both sdpMid and sdpMLineIndex are null by default.
    // Note that current browsers pass this test but may throw TypeError for
    // different reason, i.e. they don't accept empty argument.
    // Further tests below are used to differentiate the errors.
    assert_throws_js(TypeError, () => new RTCIceCandidate());
  }, 'new RTCIceCandidate()');

  test(t => {
    // All fields in RTCIceCandidateInit are optional,
    // but the constructor throws because both sdpMid and sdpMLineIndex are null by default.
    // Note that current browsers pass this test but may throw TypeError for
    // different reason, i.e. they don't allow undefined candidate string.
    // Further tests below are used to differentiate the errors.
    assert_throws_js(TypeError, () => new RTCIceCandidate({}));
  }, 'new RTCIceCandidate({})');

  test(t => {
    // Checks that manually filling the default values for RTCIceCandidateInit
    // still throws because both sdpMid and sdpMLineIndex are null
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: '',
        sdpMid: null,
        sdpMLineIndex: null,
        usernameFragment: undefined
      }));
  }, 'new RTCIceCandidate({ ... }) with manually filled default values');

  test(t => {
    // Checks that explicitly setting both sdpMid and sdpMLineIndex null should throw
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        sdpMid: null,
        sdpMLineIndex: null
      }));
  }, 'new RTCIceCandidate({ sdpMid: null, sdpMLineIndex: null })');

  test(t => {
    // Throws because both sdpMid and sdpMLineIndex are null by default
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: ''
      }));
  }, `new RTCIceCandidate({ candidate: '' })`);

  test(t => {
    // Throws because the candidate field is not nullable
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: null
      }));
  }, `new RTCIceCandidate({ candidate: null })`);

  test(t => {
    // Throws because both sdpMid and sdpMLineIndex are null by default
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: candidateString
      }));
  }, 'new RTCIceCandidate({ ... }) with valid candidate string only');

  test(t => {
    const candidate = new RTCIceCandidate({ sdpMid: 'audio' });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ sdpMid: 'audio' })`);

  test(t => {
    const candidate = new RTCIceCandidate({ sdpMLineIndex: 0 });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, null, 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ sdpMLineIndex: 0 })');

  test(t => {
    const candidate = new RTCIceCandidate({
      sdpMid: 'audio',
      sdpMLineIndex: 0
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ sdpMid: 'audio', sdpMLineIndex: 0 })`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: '',
      sdpMid: 'audio'
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ candidate: '', sdpMid: 'audio' }`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: '',
      sdpMLineIndex: 0
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, null, 'sdpMid', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ candidate: '', sdpMLineIndex: 0 }`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: candidateString,
      sdpMid: 'audio'
    });

    assert_equals(candidate.candidate, candidateString, 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with valid candidate string and sdpMid');

  test(t =>{
    // candidate string is not validated in RTCIceCandidate
    const candidate = new RTCIceCandidate({
      candidate: arbitraryString,
      sdpMid: 'audio'
    });

    assert_equals(candidate.candidate, arbitraryString, 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with invalid candidate string and sdpMid');

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: candidateString,
      sdpMid: 'video',
      sdpMLineIndex: 1,
      usernameFragment: 'test'
    });

    assert_equals(candidate.candidate, candidateString, 'candidate');
    assert_equals(candidate.sdpMid, 'video', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 1, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, 'test', 'usernameFragment');

    // The following fields should match those in the candidate field
    assert_equals(candidate.foundation, '1905690388', 'foundation');
    assert_equals(candidate.component, 'rtp', 'component');
    assert_equals(candidate.priority, 2113937151, 'priority');
    assert_equals(candidate.address, '192.168.0.1', 'address');
    assert_equals(candidate.protocol, 'udp', 'protocol');
    assert_equals(candidate.port, 58041, 'port');
    assert_equals(candidate.type, 'host', 'type');
    assert_equals(candidate.tcpType, '', 'tcpType');
    assert_equals(candidate.relatedAddress, null, 'relatedAddress');
    assert_equals(candidate.relatedPort, null, 'relatedPort');
  }, 'new RTCIceCandidate({ ... }) with nondefault values for all fields');

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: candidateString2,
      sdpMid: 'video',
      sdpMLineIndex: 1,
      usernameFragment: 'user1'
    });

    assert_equals(candidate.candidate, candidateString2, 'candidate');
    assert_equals(candidate.sdpMid, 'video', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 1, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, 'user1', 'usernameFragment');

    // The following fields should match those in the candidate field
    assert_equals(candidate.foundation, '435653019', 'foundation');
    assert_equals(candidate.component, 'rtcp', 'component');
    assert_equals(candidate.priority, 1845501695, 'priority');
    assert_equals(candidate.address, '192.168.0.196', 'address');
    assert_equals(candidate.protocol, 'tcp', 'protocol');
    assert_equals(candidate.port, 4444, 'port');
    assert_equals(candidate.type, 'srflx', 'type');
    assert_equals(candidate.tcpType, 'active', 'tcpType');
    assert_equals(candidate.relatedAddress, 'www.example.com', 'relatedAddress');
    assert_equals(candidate.relatedPort, 22222, 'relatedPort');
  }, 'new RTCIceCandidate({ ... }) with nondefault values for all fields, tcp candidate');

  test(t => {
    // sdpMid is not validated in RTCIceCandidate
    const candidate = new RTCIceCandidate({
      sdpMid: arbitraryString
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, arbitraryString, 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with invalid sdpMid');


  test(t => {
    // Some arbitrary large out of bound line index that practically
    // do not reference any m= line in SDP.
    // However sdpMLineIndex is not validated in RTCIceCandidate
    // and it has no knowledge of the SDP it is associated with.
    const candidate = new RTCIceCandidate({
      sdpMLineIndex: 65535
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, null, 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 65535, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with invalid sdpMLineIndex');

</script>