tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_peerConnection_bug825703.html (4997B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5 </head>
      6 <body>
      7 <pre id="test">
      8 <script type="application/javascript">
      9  createHTML({
     10    bug: "825703",
     11    title: "RTCConfiguration valid/invalid permutations"
     12  });
     13 
     14 // ^^^ Don't insert data above this line without adjusting line number below!
     15 var lineNumberAndFunction = {
     16 // <--- 16 is the line this must be.
     17  line: 17, func: () => new RTCPeerConnection().onaddstream = () => {}
     18 };
     19 
     20 var makePC = (config, expected_error) => {
     21  var exception;
     22  try {
     23    new RTCPeerConnection(config).close();
     24  } catch (e) {
     25    exception = e;
     26  }
     27  is((exception? exception.name : "success"), expected_error || "success",
     28     "RTCPeerConnection(" + JSON.stringify(config) + ") " + exception?.message);
     29 };
     30 
     31 // The order of properties in objects is not guaranteed in JavaScript, so this
     32 // transform produces json-comparable dictionaries. The resulting copy is only
     33 // meant to be used in comparisons (e.g. array-ness is not preserved).
     34 
     35 var toComparable = o =>
     36    (typeof o != 'object' || !o)? o : Object.keys(o).sort().reduce((co, key) => {
     37  co[key] = toComparable(o[key]);
     38  return co;
     39 }, {});
     40 
     41 // This is a test of the iceServers parsing code + readable errors
     42 runNetworkTest(async () => {
     43  let exception = null;
     44 
     45  try {
     46    new RTCPeerConnection().close();
     47  } catch (e) {
     48    exception = e;
     49  }
     50  ok(!exception, "RTCPeerConnection() succeeds");
     51  exception = null;
     52 
     53  // Some overlap still with WPT RTCConfiguration-iceServers.html
     54 
     55  makePC({ iceServers: [
     56    { urls:"stun:127.0.0.1" },
     57    { urls:"stun:localhost", foo:"" },
     58    { urls: ["stun:127.0.0.1", "stun:localhost"] },
     59  ]});
     60  makePC({ iceServers: [
     61    { urls:"turn:[::1]:3478", username:"p", credential:"p" },
     62    { urls:"turn:[::1]:3478", username:"", credential:"" },
     63    { urls:"turns:[::1]:3478", username:"", credential:"" },
     64  ]});
     65  makePC({ iceServers: [
     66    { urls:"turn:localhost:3478?transport=udp", username:"p", credential:"p" },
     67    { urls: ["turn:[::1]:3478", "turn:localhost"], username:"p", credential:"p" },
     68    { urls:"turns:localhost:3478?transport=udp", username:"p", credential:"p" },
     69  ]});
     70  makePC({ iceServers: [{ urls:"http:0.0.0.0" }] }, "SyntaxError");
     71 
     72  try {
     73    new RTCPeerConnection({ iceServers: [{ urls:"http:0.0.0.0" }] }).close();
     74  } catch (e) {
     75    ok(e.message.indexOf("http") > 0,
     76       "RTCPeerConnection() constructor has readable exceptions");
     77  }
     78 
     79  const push = prefs => SpecialPowers.pushPrefEnv(prefs);
     80 
     81  // Remaining tests trigger warnings
     82  await push({ set: [['media.peerconnection.treat_warnings_as_errors', false]] });
     83 
     84  makePC({ iceServers: [
     85    { urls:"stuns:localhost", foo:"" },
     86    { url:"stun:localhost", foo:"" },
     87    { url:"turn:localhost", username:"p", credential:"p" }
     88  ]});
     89 
     90  // Test getConfiguration
     91  const config = {
     92    bundlePolicy: "max-bundle",
     93    iceTransportPolicy: "relay",
     94    peerIdentity: null,
     95    certificates: [],
     96    iceServers: [
     97      { urls: ["stun:127.0.0.1", "stun:localhost"], credentialType:"password" },
     98      { urls: ["turn:[::1]:3478"], username:"p", credential:"p", credentialType:"password" },
     99    ],
    100  };
    101  // Make sure sdpSemantics is not exposed in getConfiguration
    102  const configWithExtraProps = Object.assign({},
    103                                             config,
    104                                             {sdpSemantics: "plan-b"});
    105  ok("sdpSemantics" in configWithExtraProps, "sdpSemantics control");
    106 
    107  const pc = new RTCPeerConnection(configWithExtraProps);
    108  is(JSON.stringify(toComparable(pc.getConfiguration())),
    109     JSON.stringify(toComparable(config)), "getConfiguration");
    110  pc.close();
    111 
    112  // This set of tests are setting the about:config User preferences for default
    113  // ice servers and checking the outputs when RTCPeerConnection() is
    114  // invoked. See Bug 1167922 for more information.
    115  await push({ set: [['media.peerconnection.default_iceservers', ""]] });
    116  makePC();
    117  await push({ set: [['media.peerconnection.default_iceservers', "k"]] });
    118  makePC();
    119  await push({ set: [['media.peerconnection.default_iceservers',
    120                      "[{\"urls\": [\"stun:stun.services.mozilla.com\"]}]"]]});
    121  makePC();
    122  // This set of tests check that warnings work. See Bug 1254839 for more.
    123  const warning = await new Promise(resolve => {
    124    SpecialPowers.registerConsoleListener(msg => {
    125      if (msg.message.includes("onaddstream")) {
    126        SpecialPowers.postConsoleSentinel();
    127        resolve(msg.message);
    128      }
    129    });
    130    lineNumberAndFunction.func();
    131  });
    132  is(warning.split('"')[1],
    133     "WebRTC: onaddstream is deprecated! Use peerConnection.ontrack instead.",
    134     "warning logged");
    135  const remainder = warning.split('"').slice(2).join('"');
    136  info(remainder);
    137  ok(remainder.includes('file: "' + window.location + '"'),
    138     "warning has this file");
    139  ok(remainder.includes('line: ' + lineNumberAndFunction.line),
    140     "warning has correct line number");
    141 });
    142 </script>
    143 </pre>
    144 </body>
    145 </html>