Bug 1504385 [wpt PR 13870] - Add support for resizeMode in [MediaStreamTrack|InputDeviceInfo].getCapabilities(), a=testonly
authorGuido Urdaneta <guidou@chromium.org>
Sat, 24 Nov 2018 10:29:25 +0000
changeset 507265 17fcb899cf54fbbd96b8c86cb6d8ca217eecc96f
parent 507264 78631157299d3a250443aac74b5d4a8880629422
child 507266 8a93c60fc17f39f8c4e8dbdbb0bcf3185c89b36b
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1504385, 13870, 854980, 1310714, 610108
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1504385 [wpt PR 13870] - Add support for resizeMode in [MediaStreamTrack|InputDeviceInfo].getCapabilities(), a=testonly Automatic update from web-platform-testsAdd support for resizeMode in [MediaStreamTrack|InputDeviceInfo].getCapabilities() Intent to Ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/V2srjdzRCXE Bug: 854980 Change-Id: Ie49e3d2f9b8afe1abc552172d78dd86088b6ce41 Reviewed-on: https://chromium-review.googlesource.com/c/1310714 Commit-Queue: Guido Urdaneta <guidou@chromium.org> Reviewed-by: Henrik Boström <hbos@chromium.org> Cr-Commit-Position: refs/heads/master@{#610108} -- wpt-commits: c00fd5dec24aac426acb570e9d253ec609b109bd wpt-pr: 13870
testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html
testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-getCapabilities.https.html
--- a/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html
+++ b/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html
@@ -11,70 +11,35 @@
 <p class="instructions">This test checks for the presence of the
 <code>navigator.mediaDevices.enumerateDevices()</code> method.</p>
 <div id='log'></div>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script>
 "use strict";
 //NOTE ALEX: for completion, a test for ondevicechange event is missing.
-promise_test(function() {
+promise_test(async () => {
   assert_true(undefined !== navigator.mediaDevices.enumerateDevices, "navigator.mediaDevices.enumerateDevices exists");
-  return navigator.mediaDevices.enumerateDevices().then(function(list) {
-    for (let mediainfo of list) {
-      assert_true(undefined !== mediainfo.deviceId, "mediaInfo's deviceId should exist.");
-      assert_true(undefined !== mediainfo.kind,     "mediaInfo's kind     should exist.");
-      assert_true(undefined !== mediainfo.label,    "mediaInfo's label    should exist.");
-      assert_true(undefined !== mediainfo.groupId,  "mediaInfo's groupId  should exist.");
-      // TODO the values of some of those fields should be empty string by default if no permission has been requested.
-      if ( mediainfo.kind == "audioinput" || mediainfo.kind == "videoinput") {
-        assert_true(mediainfo instanceof InputDeviceInfo);
-        var capabilities = mediainfo.getCapabilities();
-        assert_equals(typeof capabilities, "object", "capabilities must be an object.");
-        assert_equals(typeof capabilities.deviceId, "string", "deviceId must be a string.");
-        assert_equals(typeof capabilities.groupId, "string", "groupId must be a string.");
-        if (mediainfo.kind == "audioinput") {
-          assert_equals(typeof capabilities.echoCancellation, "object", "echoCancellation must be an object.");
-          assert_equals(typeof capabilities.autoGainControl, "object", "autoGainControl must be an object.");
-          assert_equals(typeof capabilities.noiseSuppression, "object", "noiseSuppression must be an object.");
-        }
-        if (mediainfo.kind == "videoinput") {
-          assert_equals(typeof capabilities.facingMode, "object", "facingMode must be an object.");
-          verifyVideoRangeProperties(capabilities);
-        }
-      } else if ( mediainfo.kind == "audiooutput" ) {
-        assert_true(mediainfo instanceof MediaDeviceInfo);
-      } else {
-        assert_unreached("mediainfo.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.")
-      }
+  const device_list =  await navigator.mediaDevices.enumerateDevices();
+  for (const mediainfo of device_list) {
+    assert_true(undefined !== mediainfo.deviceId, "mediaInfo's deviceId should exist.");
+    assert_true(undefined !== mediainfo.kind,     "mediaInfo's kind     should exist.");
+    assert_in_array(mediainfo.kind, ["videoinput", "audioinput", "audiooutput"]);
+    assert_true(undefined !== mediainfo.label,    "mediaInfo's label    should exist.");
+    assert_true(undefined !== mediainfo.groupId,  "mediaInfo's groupId  should exist.");
+  }
+}, "mediaDevices.enumerateDevices() is present and working");
+
+promise_test(async () => {
+  const device_list =  await navigator.mediaDevices.enumerateDevices();
+  for (const mediainfo of device_list) {
+    if (mediainfo.kind == "audioinput" || mediainfo.kind == "videoinput") {
+      assert_true(mediainfo instanceof InputDeviceInfo);
+    } else if ( mediainfo.kind == "audiooutput" ) {
+      assert_true(mediainfo instanceof MediaDeviceInfo);
+    } else {
+      assert_unreached("mediainfo.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.")
     }
-  });
-}, "mediaDevices.enumerateDevices() is present and working on navigator");
-
-function verifyVideoRangeProperties(capabilities) {
-  if (capabilities.hasOwnProperty('width')) {
-      assert_equals(Object.keys(capabilities.width).length, 2);
-      assert_true(capabilities.width.hasOwnProperty('min'));
-      assert_true(capabilities.width.hasOwnProperty('max'));
-      assert_less_than_equal(capabilities.width.min, capabilities.width.max);
   }
-  if (capabilities.hasOwnProperty('height')) {
-    assert_equals(Object.keys(capabilities.height).length, 2);
-    assert_true(capabilities.height.hasOwnProperty('min'));
-    assert_true(capabilities.height.hasOwnProperty('max'));
-    assert_less_than_equal(capabilities.height.min, capabilities.height.max);
-  }
-  if (capabilities.hasOwnProperty('aspectRatio')) {
-    assert_equals(Object.keys(capabilities.aspectRatio).length, 2);
-    assert_true(capabilities.aspectRatio.hasOwnProperty('min'));
-    assert_true(capabilities.aspectRatio.hasOwnProperty('max'));
-    assert_less_than_equal(capabilities.aspectRatio.min, capabilities.aspectRatio.max);
-  }
-  if (capabilities.hasOwnProperty('frameRate')) {
-    assert_equals(Object.keys(capabilities.frameRate).length, 2);
-    assert_true(capabilities.frameRate.hasOwnProperty('min'));
-    assert_true(capabilities.frameRate.hasOwnProperty('max'));
-    assert_less_than_equal(capabilities.frameRate.min, capabilities.frameRate.max);
-  }
-}
+}, "InputDeviceInfo is supported");
 </script>
 </body>
 </html>
--- a/testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-getCapabilities.https.html
+++ b/testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-getCapabilities.https.html
@@ -1,22 +1,150 @@
 <!doctype html>
-<title>MediaStreamTrack GetCapabilities</title>
-<p class="instructions">This test checks for the presence of audio and video properties in
-<code>MediaStreamTrack.getCapabilities()</code> method.</p>
+<title>MediaStreamTrack and InputDeviceInfo GetCapabilities</title>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script>
-  promise_test(() => {
-  return navigator.mediaDevices.getUserMedia({audio: true, video: true})
-    .then(stream => {
-      var audioCapabilities = stream.getAudioTracks()[0].getCapabilities();
-      var videoCapabilities = stream.getVideoTracks()[0].getCapabilities();
-      assert_true(undefined !== audioCapabilities.deviceId, "MediaTrackCapabilities's deviceId should exist for an audio track.");
-      assert_true(undefined !== audioCapabilities.groupId, "MediaTrackCapabilities's groupId should exist for an audio track.");
-      assert_true(undefined !== audioCapabilities.echoCancellation, "MediaTrackCapabilities's echoCancellation should exist for an audio track.");
-      assert_true(undefined !== audioCapabilities.autoGainControl, "MediaTrackCapabilities's autoGainControl should exist for an audio track.");
-      assert_true(undefined !== audioCapabilities.noiseSuppression, "MediaTrackCapabilities's noiseSuppression should exist for an audio track.");
-      assert_true(undefined !== videoCapabilities.deviceId, "MediaTrackCapabilities's deviceId should exist for a video track.");
-      assert_true(undefined !== videoCapabilities.groupId, "MediaTrackCapabilities's groupId should exist for a video track.");
-    });
+
+const audioProperties = [
+  {name: "volume", type: "number"},
+  {name: "sampleRate", type: "number"},
+  {name: "sampleSize", type: "number"},
+  {name: "echoCancellation", type: "boolean"},
+  {name: "autoGainControl", type: "boolean"},
+  {name: "noiseSuppression", type: "boolean"},
+  {name: "latency", type: "number"},
+  {name: "channelCount", type: "number"},
+  {name: "deviceId", type: "string"},
+  {name: "groupId", type: "string"}
+];
+
+const videoProperties = [
+  {name: "width", type: "number"},
+  {name: "height", type: "number"},
+  {name: "aspectRatio", type: "number"},
+  {name: "frameRate", type: "number"},
+  {name: "facingMode", type: "enum-any", validValues: ["user", "environment", "left", "right"]},
+  {name: "resizeMode", type: "enum-all", validValues: ["none", "crop-and-scale"]},
+  {name: "deviceId", type: "string"},
+  {name: "groupId", type: "string"},
+];
+
+function verifyBooleanCapability(capability) {
+  assert_less_than_equal(capability.length, 2);
+  capability.forEach(c => assert_equals(typeof c, "boolean"));
+}
+
+function verifyNumberCapability(capability) {
+    assert_equals(typeof capability, "object");
+    assert_equals(Object.keys(capability).length, 2);
+    assert_true(capability.hasOwnProperty('min'));
+    assert_true(capability.hasOwnProperty('max'));
+    assert_less_than_equal(capability.min, capability.max);
+}
+
+// Verify that any value provided by an enum capability is in the set of valid
+// values.
+function verifyEnumAnyCapability(capability, enumMembers) {
+  capability.forEach(c => {
+    assert_equals(typeof c, "string");
+    assert_in_array(c, enumMembers);
+  });
+}
+
+// Verify that all required values are supported by a capability.
+function verifyEnumAllCapability(capability, enumMembers, testNamePrefix) {
+  enumMembers.forEach(member => {
+    test(() => {
+      assert_in_array(member, capability);
+    }, testNamePrefix + " Value: " + member);
   });
+}
+
+function testCapabilities(capabilities, property, testNamePrefix) {
+  let testName = testNamePrefix + " " + property.name;
+  test(() => {
+    assert_true(capabilities.hasOwnProperty(property.name));
+  }, testName + " property present.");
+
+  const capability = capabilities[property.name];
+  testName += " properly supported.";
+  if (property.type == "string") {
+    test(() => {
+      assert_equals(typeof capability, "string");
+    }, testName);
+  }
+
+  if (property.type == "boolean") {
+    test(() => {
+      verifyBooleanCapability(capability);
+    }, testName);
+  }
+
+  if (property.type == "number") {
+    test(() => {
+      verifyNumberCapability(capability);
+    }, testName);
+  }
+
+  if (property.type.startsWith("enum")) {
+    test(() => {
+      verifyEnumAnyCapability(capability, property.validValues);
+    }, testName);
+
+    if (property.type == "enum-all") {
+      verifyEnumAllCapability(capability, property.validValues, testName);
+    }
+  }
+}
+
+{
+  audioProperties.forEach(property => {
+    promise_test(async t => {
+      const stream = await navigator.mediaDevices.getUserMedia({audio: true});
+      t.add_cleanup(() => stream.getAudioTracks()[0].stop());
+      const audioCapabilities = stream.getAudioTracks()[0].getCapabilities();
+      testCapabilities(audioCapabilities, property, "Audio track getCapabilities()");
+    }, "Setup audio MediaStreamTrack getCapabilities() test for " + property.name);
+  });
+
+  videoProperties.forEach(property => {
+    promise_test(async t => {
+      const stream = await navigator.mediaDevices.getUserMedia({video: true});
+      t.add_cleanup(() => stream.getVideoTracks()[0].stop());
+      const audioCapabilities = stream.getVideoTracks()[0].getCapabilities();
+      testCapabilities(audioCapabilities, property, "Video track getCapabilities()");
+    }, "Setup video MediaStreamTrack getCapabilities() test for " + property.name);
+  });
+}
+
+{
+  audioProperties.forEach(property => {
+    promise_test(async t => {
+      const devices = await navigator.mediaDevices.enumerateDevices();
+      for (const device of devices) {
+        // Test only one device.
+        if (device.kind == "audioinput") {
+          assert_inherits(device, "getCapabilities");
+          const capabilities = device.getCapabilities();
+          testCapabilities(capabilities, property, "Audio device getCapabilities()");
+          break;
+        }
+      }
+    }, "Setup audio InputDeviceInfo getCapabilities() test for " + property.name);
+  });
+
+  videoProperties.forEach(property => {
+    promise_test(async t => {
+      const devices = await navigator.mediaDevices.enumerateDevices();
+      for (const device of devices) {
+        // Test only one device.
+        if (device.kind == "videoinput") {
+          assert_inherits(device, "getCapabilities");
+          const capabilities = device.getCapabilities();
+          testCapabilities(capabilities, property, "Video device getCapabilities()");
+          break;
+        }
+      }
+    }, "Setup video InputDeviceInfo getCapabilities() test for " + property.name);
+  });
+}
 </script>