summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc-extensions/RTCRtpParameters-maxFramerate.html
blob: 3e348f0d147bdb6cd0583d4f5596feb30f86cb52 (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
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpParameters encodings</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webrtc/dictionary-helper.js"></script>
<script src="/webrtc/RTCRtpParameters-helper.js"></script>
<script>
'use strict';

test(t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  assert_throws_js(RangeError, () => pc.addTransceiver('video', {
    sendEncodings: [{
      maxFramerate: -10
    }]
  }));
}, `addTransceiver() with sendEncoding.maxFramerate field set to less than 0 should reject with RangeError`);

test(t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  let {sender} = pc.addTransceiver('audio', {
    sendEncodings: [{
      maxFramerate: -10
    }]
  });
  let encodings = sender.getParameters().encodings;
  assert_equals(encodings.length, 1);
  assert_not_own_property(encodings[0], "maxFramerate");

  sender = pc.addTransceiver('audio', {
    sendEncodings: [{
      maxFramerate: 10
    }]
  }).sender;
  encodings = sender.getParameters().encodings;
  assert_equals(encodings.length, 1);
  assert_not_own_property(encodings[0], "maxFramerate");
}, `addTransceiver('audio') with sendEncoding.maxFramerate should succeed, but remove the maxFramerate, even if it is invalid`);

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const {sender} = pc.addTransceiver('audio');
  let params = sender.getParameters();
  assert_equals(params.encodings.length, 1);
  params.encodings[0].maxFramerate = 20;
  await sender.setParameters(params);
  const {encodings} = sender.getParameters();
  assert_equals(encodings.length, 1);
  assert_not_own_property(encodings[0], "maxFramerate");
}, `setParameters with maxFramerate on an audio sender should succeed, but remove the maxFramerate`);

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const {sender} = pc.addTransceiver('audio');
  let params = sender.getParameters();
  assert_equals(params.encodings.length, 1);
  params.encodings[0].maxFramerate = -1;
  await sender.setParameters(params);
  const {encodings} = sender.getParameters();
  assert_equals(encodings.length, 1);
  assert_not_own_property(encodings[0], "maxFramerate");
}, `setParameters with an invalid maxFramerate on an audio sender should succeed, but remove the maxFramerate`);

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const { sender } = pc.addTransceiver('video');
  await doOfferAnswerExchange(t, pc);

  const param = sender.getParameters();
  const encoding = param.encodings[0];
  assert_not_own_property(encoding, "maxFramerate");

  encoding.maxFramerate = -10;
  return promise_rejects_js(t, RangeError,
    sender.setParameters(param));
}, `setParameters() with encoding.maxFramerate field set to less than 0 should reject with RangeError`);

// It would be great if we could test to see whether maxFramerate is actually
// honored.
test_modified_encoding('video', 'maxFramerate', 24, 16,
  'setParameters() with maxFramerate 24->16 should succeed');

test_modified_encoding('video', 'maxFramerate', undefined, 16,
  'setParameters() with maxFramerate undefined->16 should succeed');

test_modified_encoding('video', 'maxFramerate', 24, undefined,
  'setParameters() with maxFramerate 24->undefined should succeed');

test_modified_encoding('video', 'maxFramerate', 0, 16,
  'setParameters() with maxFramerate 0->16 should succeed');

test_modified_encoding('video', 'maxFramerate', 24, 0,
  'setParameters() with maxFramerate 24->0 should succeed');

</script>