| <!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([dom, idlText]) { |
| const MDI_idl = new IdlArray(); |
| |
| MDI_idl.add_untested_idls(dom, { only: ['Event', 'EventInit'] }); |
| 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 Promise.all( |
| [ |
| '/interfaces/dom.idl', |
| '/interfaces/mediacapture-main.idl', |
| ].map(url => fetch(url).then(r => r.text()))) |
| .then(doIdlTest); |
| |
| }, "Test MediaDevices.enumerateDevices call and result. Types only."); |
| </script> |
| </body> |
| </html> |