Debian Codegraph @

testing/web-platform/mozilla/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html

raw
1 <!doctype html>
2 <html>
3 <head>
4 <title>enumerateDevices: test that enumerateDevices is present (legacy Firefox)</title>
5 <meta name='assert' content='Check that the enumerateDevices() method is present (legacy Firefox).'/>
6 </head>
7 <body>
8 <h1 class="instructions">Description</h1>
9 <p class="instructions">This is a modified copy of
10 testing/web-platform/tests/mediacapture-streams/MediaDevices-enumerateDevices.https.html
11 testing legacy Firefox version of the <code>navigator.mediaDevices.enumerateDevices()</code> method.</p>
12 <div id='log'></div>
13 <script src=/resources/testharness.js></script>
14 <script src=/resources/testharnessreport.js></script>
15 <script src=/resources/testdriver.js></script>
16 <script src=/resources/testdriver-vendor.js></script>
17 <script src=permission-helper.js></script>
18 <script>
19 "use strict";
20
21 promise_test(async () => {
22 assert_not_equals(navigator.mediaDevices.enumerateDevices, undefined, "navigator.mediaDevices.enumerateDevices exists");
23 const devices = await navigator.mediaDevices.enumerateDevices();
24 for (const {kind, deviceId, label, groupId} of devices) {
25 assert_in_array(kind, ["videoinput", "audioinput", "audiooutput"]);
26 assert_greater_than(deviceId.length, 0, "deviceId should be present even if getUserMedia was never called successfully (legacy).");
27 assert_equals(label, "", "label should be empty string if getUserMedia was never called successfully.");
28 assert_greater_than(groupId.length, 0, "groupId should be present even if getUserMedia was never called successfully (legacy).");
29 }
30 assert_less_than_equal(devices.filter(({kind}) => kind == "audioinput").length,
31 1, "there should be zero or one audio input device.");
32 assert_less_than_equal(devices.filter(({kind}) => kind == "videoinput").length,
33 1, "there should be zero or one video input device.");
34 assert_equals(devices.filter(({kind}) => kind == "audiooutput").length,
35 0, "there should be no audio output devices.");
36 assert_less_than_equal(devices.length, 2,
37 "there should be no more than two devices.");
38 if (devices.length > 1) {
39 assert_equals(devices[0].kind, "audioinput", "audioinput is first");
40 assert_equals(devices[1].kind, "videoinput", "videoinput is second");
41 }
42 }, "mediaDevices.enumerateDevices() is present and working - before capture");
43
44 promise_test(async t => {
45 await setMediaPermission("granted");
46 const stream = await navigator.mediaDevices.getUserMedia({ video: true });
47 stream.getTracks()[0].stop();
48
49 const devices = await navigator.mediaDevices.enumerateDevices();
50 const kinds = ["audioinput", "videoinput"];
51 for (const {kind, deviceId} of devices) {
52 assert_in_array(kind, kinds, "camera doesn't expose audiooutput");
53 assert_equals(typeof deviceId, "string", "deviceId is a string.");
54 switch (kind) {
55 case "videoinput":
56 assert_greater_than(deviceId.length, 0, "video deviceId should not be empty.");
57 break;
58 case "audioinput":
59 assert_greater_than(deviceId.length, 0, "audio deviceId should not be empty (legacy).");
60 break;
61 }
62 }
63 }, "mediaDevices.enumerateDevices() is working - after video capture");
64
65 // This test is designed to come after its video counterpart directly above
66 promise_test(async t => {
67 const devices1 = await navigator.mediaDevices.enumerateDevices();
68 const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
69 stream.getTracks()[0].stop();
70 const devices = await navigator.mediaDevices.enumerateDevices();
71 assert_equals(devices.filter(({kind}) => kind == "videoinput").length,
72 devices1.filter(({kind}) => kind == "videoinput").length,
73 "same number of (previously exposed) videoinput devices");
74 assert_greater_than_equal(devices.filter(d => d.kind == "audioinput").length,
75 devices1.filter(d => d.kind == "audioinput").length,
76 "same number or more audioinput devices");
77 const order = ["audioinput", "videoinput", "audiooutput"];
78 for (const {kind, deviceId} of devices) {
79 assert_in_array(kind, order, "expected kind");
80 assert_equals(typeof deviceId, "string", "deviceId is a string.");
81 switch (kind) {
82 case "videoinput":
83 assert_greater_than(deviceId.length, 0, "video deviceId should not be empty.");
84 break;
85 case "audioinput":
86 assert_greater_than(deviceId.length, 0, "audio deviceId should not be empty.");
87 break;
88 }
89 }
90 const kinds = devices.map(({kind}) => kind);
91 const correct = [...kinds].sort((a, b) => order.indexOf(a) - order.indexOf(b));
92 assert_equals(JSON.stringify(kinds), JSON.stringify(correct), "correct order");
93 }, "mediaDevices.enumerateDevices() is working - after video then audio capture");
94
95 promise_test(async () => {
96 const devices = await navigator.mediaDevices.enumerateDevices();
97 for (const mediaInfo of devices) {
98 if (mediaInfo.kind == "audioinput" || mediaInfo.kind == "videoinput") {
99 assert_true("InputDeviceInfo" in window, "InputDeviceInfo exists");
100 assert_true(mediaInfo instanceof InputDeviceInfo);
101 } else if (mediaInfo.kind == "audiooutput") {
102 assert_true(mediaInfo instanceof MediaDeviceInfo);
103 } else {
104 assert_unreached("mediaInfo.kind should be one of 'audioinput', 'videoinput', or 'audiooutput'.")
105 }
106 }
107 }, "InputDeviceInfo is supported");
108 </script>
109 </body>
110 </html>