chromium/third_party/blink/web_tests/fast/mediacapturefromelement/CanvasCaptureMediaStream-applyConstraints.html

<!doctype html>
<title>CanvasCapture applyConstraints</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>

promise_test(async t => {
  let canvas = document.createElement('canvas');
  canvas.width = canvas.height = 64;

  let stream = canvas.captureStream();
  let track = stream.getVideoTracks()[0];
  t.add_cleanup(() => track.stop());

  let settings = track.getSettings();
  assert_equals(settings.width, canvas.width);
  assert_equals(settings.height, canvas.height);
  assert_equals(settings.resizeMode, 'none');

  await track.applyConstraints({width: 63, height: 63});
  settings = track.getSettings();
  assert_equals(settings.width, 63);
  assert_equals(settings.height, 63);
  assert_equals(settings.resizeMode, 'crop-and-scale');

  await track.applyConstraints({resizeMode: {exact: 'none'}});
  settings = track.getSettings();
  assert_equals(settings.width, canvas.width);
  assert_equals(settings.height, canvas.height);
  assert_equals(settings.resizeMode, 'none');

  try {
    await track.applyConstraints(
      {width: {exact: 63}, resizeMode: {exact: 'none'}});
    t.step(()=>assert_unreached('applyConstraints should not have succeeded'));
  } catch(e) {
    assert_equals(e.name, 'OverconstrainedError');
    assert_equals(e.constraint, 'width');
  }

}, "Canvas capture resizeMode");
</script>
</body>
</html>