summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/test_peerConnection_addIceCandidate.html
blob: 93cbdd0832c02215be8a39cba22ad413571db542 (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
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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1087551",
    title: "addIceCandidate behavior (local and remote) including invalid data"
  });

  var test;
  runNetworkTest(function () {
    test = new PeerConnectionTest();
    test.setMediaConstraints([{audio: true}], [{audio: true}]);
    test.chain.removeAfter("PC_LOCAL_GET_ANSWER");

    test.chain.insertAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION", [
      function PC_LOCAL_ADD_CANDIDATE_EARLY(test) {
        var candidate = new RTCIceCandidate(
          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
           sdpMLineIndex: 0});
        return test.pcLocal._pc.addIceCandidate(candidate).then(
          generateErrorCallback("addIceCandidate should have failed."),
          err => {
            is(err.name, "InvalidStateError", "Error is InvalidStateError");
          });
        }
    ]);
    test.chain.insertAfter("PC_REMOTE_SET_LOCAL_DESCRIPTION", [
      function PC_REMOTE_ADD_CANDIDATE_INVALID_INDEX(test) {
        var invalid_index = new RTCIceCandidate(
          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
           sdpMLineIndex: 2});
        return test.pcRemote._pc.addIceCandidate(invalid_index)
        .then(
          generateErrorCallback("addIceCandidate should have failed."),
          err => {
            is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
          }
        );
      },
      function PC_REMOTE_ADD_BOGUS_CANDIDATE(test) {
        var bogus = new RTCIceCandidate(
          {candidate:"Pony Lords, jump!",
           sdpMLineIndex: 0});
        return test.pcRemote._pc.addIceCandidate(bogus)
        .then(
          generateErrorCallback("addIceCandidate should have failed."),
          err => {
            is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
          }
        );
      },
      function PC_REMOTE_ADD_CANDIDATE_MISSING_INDEX(test) {
        // Note: it is probably not a good idea to automatically fill a missing
        //       MLineIndex with a default value of zero, see bug 1157034
        var broken = new RTCIceCandidate(
          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host"});
        return test.pcRemote._pc.addIceCandidate(broken)
        .then(
          // FIXME this needs to be updated once bug 1157034 is fixed
          todo(false, "Missing index in got automatically set to a valid value bz://1157034")
        );
      },
      function PC_REMOTE_ADD_VALID_CANDIDATE(test) {
        var candidate = new RTCIceCandidate(
          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
           sdpMLineIndex: 0});
        return test.pcRemote._pc.addIceCandidate(candidate)
        .then(ok(true, "Successfully added valid ICE candidate"));
      },
      // bug 1095793
      function PC_REMOTE_ADD_MISMATCHED_MID_AND_LEVEL_CANDIDATE(test) {
        var bogus = new mozRTCIceCandidate(
          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
           sdpMLineIndex: 0,
           sdpMid: "sdparta_1"});
        return test.pcRemote._pc.addIceCandidate(bogus)
        .then(
          generateErrorCallback("addIceCandidate should have failed."),
          err => {
            is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
          }
        );
      },
      function PC_REMOTE_ADD_MATCHING_MID_AND_LEVEL_CANDIDATE(test) {
        var candidate = new mozRTCIceCandidate(
          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
           sdpMLineIndex: 0,
           sdpMid: "sdparta_0"});
        return test.pcRemote._pc.addIceCandidate(candidate)
        .then(ok(true, "Successfully added valid ICE candidate with matching mid and level"));
      }
    ]);
    test.run();
  });
</script>
</pre>
</body>
</html>