https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 7c18f59e74fc2b9ea2efe2227e05857f389fcde3 authored by Anne van Kesteren on 17 September 2018, 13:30:38 UTC
DOM: eventPhase during legacy-pre-activation behavior
Tip revision: 7c18f59
MediaStreamTrack-getSettings.https.html
<!doctype html>
<title>MediaStreamTrack GetSettings</title>
<p class="instructions">When prompted, accept to share your video stream.</p>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
  'use strict'

  // https://w3c.github.io/mediacapture-main/archives/20170605/getusermedia.html

  promise_test(t => {
    const constraints = {
      video: true,
      audio: false
    };

    return navigator.mediaDevices.getUserMedia(constraints)
    .then(mediaStream => {
      const settings1 = mediaStream.getVideoTracks()[0].getSettings();
      const videoConstraints = {
        deviceId: settings1.deviceId
      };

      return navigator.mediaDevices.getUserMedia({
        video: videoConstraints,
        audio: false
      }).then(mediaStream => {
        const settings2 = mediaStream.getVideoTracks()[0].getSettings();
        assert_equals(settings1.deviceId, settings2.deviceId);
      });
    });
  }, 'A device can be opened twice and have the same device ID');

  promise_test(t => {
    const constraints = {
      video: true,
      audio: false
    };

    return navigator.mediaDevices.getUserMedia(constraints)
    .then(mediaStream => {
      const settings1 = mediaStream.getVideoTracks()[0].getSettings();
      const videoConstraints = {
        deviceId: settings1.deviceId,
        width: {
          exact: settings1.width / 2
        }
      };

      return navigator.mediaDevices.getUserMedia({
        video: videoConstraints,
        audio: false
      }).then(mediaStream => {
        const settings2 = mediaStream.getVideoTracks()[0].getSettings();
        assert_equals(settings1.deviceId, settings2.deviceId);
        assert_equals(settings1.width / 2, settings2.width);
      });
    });
  }, 'A device can be opened twice with different resolutions');

  promise_test(t => {
    return navigator.mediaDevices.enumerateDevices().then(async devices => {
      for (var device of devices) {
        if (device.kind == "audiooutput")
          continue;
        var device_id_constraint = {deviceId: {exact: device.deviceId}};
        var constraints = device.kind == "audioinput"
          ? {audio: device_id_constraint}
          : {video: device_id_constraint};

        var stream = await navigator.mediaDevices.getUserMedia(constraints);
        assert_equals(stream.getTracks()[0].getSettings().groupId,
                      device.groupId);
        assert_true(device.groupId.length > 0);
      }
    });
  }, 'groupId is correctly reported by getSettings() for all devices');

  promise_test(t => {
    return navigator.mediaDevices.getUserMedia({audio: true}).then(stream => {
      let settings = stream.getAudioTracks()[0].getSettings();
      assert_equals(typeof(settings.deviceId), "string",
                    "deviceId should exist and it should be a string.");
      assert_equals(typeof(settings.groupId), "string",
                    "groupId should exist and it should be a string.");
      assert_equals(typeof(settings.volume), "number",
                    "volume should exist and it should be a number.");
      assert_true(settings.volume >= 0.0 && settings.volume <= 1.0,
                  "volume should be a number in the range [0.0, 1.0].");
      assert_equals(typeof(settings.sampleRate), "number",
                    "sampleRate should exist and it should be a number.");
      assert_true(settings.sampleRate > 0, "sampleRate should be positive.");
      assert_equals(typeof(settings.sampleSize), "number",
                    "sampleSize should exist and it should be a number.");
      assert_true(settings.sampleSize > 0, "sampleSize should be positive.");
      assert_equals(typeof(settings.echoCancellation), "boolean",
                    "echoCancellation should exist and it should be a boolean.");
      assert_equals(typeof(settings.autoGainControl), "boolean",
                    "autoGainControl should exist and it should be a boolean.");
      assert_equals(typeof(settings.noiseSuppression), "boolean",
                    "noiseSuppression should exist and it should be a boolean.");
      assert_equals(typeof(settings.latency), "number",
                    "latency should exist and it should be a number.");
      assert_true(settings.latency >= 0, "latency should not be negative.");
      assert_equals(typeof(settings.channelCount), "number",
                    "channelCount should exist and it should be a number.");
      assert_true(settings.channelCount > 0, "channelCount should be positive.");
    });
  }, 'audio properties are reported by getSettings()');
</script>
back to top