summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_setParameters_oldSetParameters.html
blob: 2b55ec46e6b36ff194bedeee68372a1e758716e4 (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
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
  bug: "1230184",
  title: "Set parameters on sender",
  visible: true
});

function parameterstest(pc) {
  ok(pc.getSenders().length, "have senders");
  var sender = pc.getSenders()[0];

  var testParameters = (params, errorName, errorMsg) => {
    info("Trying to set " + JSON.stringify(params));

    var validateParameters = (a, b) => {
      var validateEncoding = (a, b) => {
        is(a.rid, b.rid, "same rid");
        is(a.maxBitrate, b.maxBitrate, "same maxBitrate");
        is(a.maxFramerate, b.maxFramerate, "same maxFramerate");
        is(a.scaleResolutionDownBy, b.scaleResolutionDownBy,
           "same scaleResolutionDownBy");
      };
      is(a.encodings.length, (b.encodings || []).length, "same encodings");
      a.encodings.forEach((en, i) => validateEncoding(en, b.encodings[i]));
    };

    var before = JSON.stringify(sender.getParameters());
    isnot(JSON.stringify(params), before, "starting condition");

    var p = sender.setParameters(params)
    .then(() => {
      isnot(JSON.stringify(sender.getParameters()), before, "parameters changed");
      validateParameters(sender.getParameters(), params);
      is(null, errorName || null, "is success expected");
    }, e => {
      is(e.name, errorName, "correct error name");
      is(e.message, errorMsg, "correct error message");
    });
    is(JSON.stringify(sender.getParameters()), before, "parameters not set yet");
    return p;
  };

  return [
    [{ encodings: [ { rid: "foo", maxBitrate: 40000, scaleResolutionDownBy: 2 },
                    { rid: "bar", maxBitrate: 10000, scaleResolutionDownBy: 4 }]
    }],
    [{ encodings: [{ maxBitrate: 10000, scaleResolutionDownBy: 4 }]}],
    [{ encodings: [{ maxFramerate: 0.0, scaleResolutionDownBy: 1 }]}],
    [{ encodings: [{ maxFramerate: 30.5, scaleResolutionDownBy: 1 }]}],
    [{ encodings: [{ maxFramerate: -1, scaleResolutionDownBy: 1 }]}, "RangeError", "maxFramerate must be non-negative"],
    [{ encodings: [{ maxBitrate: 40000 },
                   { rid: "bar", maxBitrate: 10000 }] }, "TypeError", "Missing rid"],
    [{ encodings: [{ rid: "foo", maxBitrate: 40000 },
                   { rid: "bar", maxBitrate: 10000 },
                   { rid: "bar", maxBitrate: 20000 }] }, "TypeError", "Duplicate rid"],
    [{}, "TypeError", `RTCRtpSender.setParameters: Missing required 'encodings' member of RTCRtpSendParameters.`]
  ].reduce((p, args) => p.then(() => testParameters.apply(this, args)),
           Promise.resolve());
}

runNetworkTest(() => {
  const test = new PeerConnectionTest();
  test.setMediaConstraints([{video: true}], [{video: true}]);
  test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");

  // Test sender parameters.
  test.chain.append([
    function PC_LOCAL_SET_PARAMETERS(test) {
      return parameterstest(test.pcLocal._pc);
    }
  ]);

  return test.run();
});

</script>
</pre>
</body>
</html>