summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html
blob: 4971f4fc48280c42388d24085e35dde07e0d9b10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!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="https://w3c.github.io/mediacapture-main/#enumerating-devices">
<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/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src=permission-helper.js></script>
<script>
"use strict";

//NOTE ALEX: for completion, a test for ondevicechange event is missing.

promise_test(async () => {
  assert_not_equals(navigator.mediaDevices.enumerateDevices, undefined, "navigator.mediaDevices.enumerateDevices exists");
  const deviceList =  await navigator.mediaDevices.enumerateDevices();
  for (const mediaInfo of deviceList) {
    assert_not_equals(mediaInfo.kind, undefined, "mediaInfo's kind should exist.");
    assert_equals(mediaInfo.deviceId, "", "mediaInfo's deviceId should exist and be empty if getUserMedia was never called successfully.");
    assert_equals(mediaInfo.label, "", "mediaInfo's label should exist and be empty if getUserMedia was never called successfully.");
    assert_equals(mediaInfo.groupId, "", "mediaInfo's groupId  should exist and be empty if getUserMedia was never called successfully.");
    assert_in_array(mediaInfo.kind, ["videoinput", "audioinput", "audiooutput"]);
  }
  assert_less_than_equal(deviceList.filter((item) => { return item.kind == "audioinput"; }).length, 1, "there should be zero or one audio input device ");
  assert_less_than_equal(deviceList.filter((item) => { return item.kind == "videoinput"; }).length, 1, "there should be zero or one video input device ");

}, "mediaDevices.enumerateDevices() is present and working - before capture");

promise_test(async () => {
  await setMediaPermission("granted", ["microphone"]);
  await navigator.mediaDevices.getUserMedia({ audio : true });
  const deviceList =  await navigator.mediaDevices.enumerateDevices();
  for (const mediaInfo of deviceList) {
    assert_not_equals(mediaInfo.kind, undefined, "mediaInfo's kind should exist.");
    assert_not_equals(mediaInfo.deviceId, "", "mediaInfo's deviceId should exist and not be empty.");
    assert_in_array(mediaInfo.kind, ["videoinput", "audioinput", "audiooutput"]);
  }
}, "mediaDevices.enumerateDevices() is present and working - after capture");

promise_test(async () => {
  const deviceList =  await navigator.mediaDevices.enumerateDevices();
  for (const mediaInfo of deviceList) {
    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'.")
    }
  }
}, "InputDeviceInfo is supported");
</script>
</body>
</html>