https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 165b38a337777a07db471dacd5c9dc35ee07a5d3 authored by Ovidio Henriquez on 30 March 2018, 22:26:25 UTC
Reland "bluetooth: FakeBluetoothChooser impl."
Tip revision: 165b38a
MediaDevices-IDL-enumerateDevices.html
<!doctype html>
<html>
<head>
<title>enumerateDevices: test that enumerateDevices is present</title>
<link rel="author" title="Dr Alex Gouaillard" href="mailto:agouaillard@gmail.com"/>
<link rel="help" href="http://w3c.github.io/mediacapture-main/getusermedia.html#methods-2">
<link rel="help" href="http://w3c.github.io/mediacapture-main/getusermedia.html#device-info">
<link rel="help" href="http://w3c.github.io/mediacapture-main/getusermedia.html#idl-def-MediaDeviceKind">
<meta name='assert' content='Check that the enumerateDevices() method is present.'/>
</head>
<body>
<h1 class="instructions">Description</h1>
<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 src=/resources/WebIDLParser.js></script>
<script src=/resources/idlharness.js></script>
<script>
  "use strict";

  function doIdlTest(idlText) {
    const MDI_idl = new IdlArray();

    MDI_idl.add_untested_idls("interface Event {};");
    MDI_idl.add_untested_idls("interface EventTarget {};");
    MDI_idl.add_untested_idls("interface Navigator {};");
    MDI_idl.add_idls(idlText);

    assert_true(undefined !== navigator.mediaDevices.enumerateDevices,
      "navigator.mediaDevices.enumerateDevices exists");

    return navigator.mediaDevices.enumerateDevices()
    .then(function(list) {
      if( list.length > 0 ) {
        var kind = list[0].kind;
        if (kind == "audioinput" ||
            kind == "videoinput") {
          MDI_idl.add_objects({InputDeviceInfo: [list[0]]});
        } else if (kind == "audiooutput" ) {
          MDI_idl.add_objects({MediaDeviceInfo: [list[0]]});
        }
      }

      for(const media of list) {
        if (media.kind == "audioinput" ||
            media.kind == "videoinput") {
          // TODO -- Check InputDeviceInfo IDL, getCapabilities()
        } else if (media.kind == "audiooutput" ) {
          // TODO -- pass
        } else {
          assert_unreached("media.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.")
        }
      }

      MDI_idl.test();
    });
  }

  promise_test(() => {
    return fetch('/interfaces/mediacapture-main.idl')
      .then(response => response.text())
      .then(doIdlTest);

  }, "Test MediaDevices.enumerateDevices call and result. Types only.");
</script>
</body>
</html>
back to top