summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_stats_relayProtocol.html
blob: 5146d423a6acc50b10b8da0cc2b3e15b62b40899 (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="nonTrickleIce.js"></script>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
  bug: "1435789",
  title: "WebRTC local-candidate relayProtocol stats attribute"
});

// This test uses the NAT simulator in order to get srflx candidates.
// It doesn't work in https, so we turn on getUserMedia in http, which requires
// a reload.
if (!("mediaDevices" in navigator)) {
  SpecialPowers.pushPrefEnv({set: [['media.devices.insecure.enabled', true]]},
                            () => location.reload());
} else {
  runNetworkTest(async (options = {}) => {
    await pushPrefs(
        ['media.peerconnection.nat_simulator.filtering_type', 'ENDPOINT_INDEPENDENT'],
        ['media.peerconnection.nat_simulator.mapping_type', 'ENDPOINT_INDEPENDENT'],
        // The above triggers warning about 5 ICE servers
        ['media.peerconnection.treat_warnings_as_errors', false],
        ['media.getusermedia.insecure.enabled', true]);
    const test = new PeerConnectionTest(options);
    makeOffererNonTrickle(test.chain);
    makeAnswererNonTrickle(test.chain);

    test.chain.removeAfter("PC_LOCAL_WAIT_FOR_MEDIA_FLOW");
    test.chain.append([PC_LOCAL_TEST_LOCAL_STATS_RELAYCANDIDATE]);

    test.setMediaConstraints([{ audio: true }], [{ audio: true }]);
    await test.run();
  }, { useIceServer: true });
}

const PC_LOCAL_TEST_LOCAL_STATS_RELAYCANDIDATE = test => {
  return test.pcLocal.getStats().then(stats => {
    let haveRelayProtocol = {};
    for (let [k, v] of stats) {
      if (v.type == "local-candidate") {
        haveRelayProtocol[v.candidateType + "-" + v.relayProtocol] = v.relayProtocol;
      }
    }
    is(haveRelayProtocol["host-undefined"], undefined, "relayProtocol not set for host candidates");
    is(haveRelayProtocol["srflx-undefined"], undefined, "relayProtocol not set for server reflexive candidates");
    ok(haveRelayProtocol["relay-udp"], "Has UDP relay candidate");
    ok(haveRelayProtocol["relay-tcp"], "Has TCP relay candidate");
    ok(haveRelayProtocol["relay-tls"], "Has TLS relay candidate");
    is(Object.keys(haveRelayProtocol).length, 5, "All candidate types are accounted for");
  });
}
</script>
</pre>
</body>
</html>