summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-streams/idlharness.https.window.js
blob: d8b7bc8d7a2a471ebaef2214706e0c26cba707bd (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
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
// META: timeout=long

'use strict';

// https://w3c.github.io/mediacapture-main/

idl_test(
  ['mediacapture-streams'],
  ['webidl', 'dom', 'html', 'permissions'],
  async idl_array => {
    const inputDevices = [];
    const outputDevices = [];
    try {
      const list = await navigator.mediaDevices.enumerateDevices();
      for (const device of list) {
        if (device.kind in self) {
          continue;
        }
        assert_in_array(device.kind, ['audioinput', 'videoinput', 'audiooutput']);
        self[device.kind] = device;
        if (device.kind.endsWith('input')) {
          inputDevices.push(device.kind);
        } else {
          outputDevices.push(device.kind);
        }
      }
    } catch (e) {}

    try {
      self.stream = await navigator.mediaDevices.getUserMedia({audio: true});
      self.track = stream.getTracks()[0];
      self.trackEvent = new MediaStreamTrackEvent("type", {
        track: track,
      });
    } catch (e) {}

    idl_array.add_objects({
      InputDeviceInfo: inputDevices,
      MediaStream: ['stream', 'new MediaStream()'],
      Navigator: ['navigator'],
      MediaDevices: ['navigator.mediaDevices'],
      MediaDeviceInfo: outputDevices,
      MediaStreamTrack: ['track'],
      MediaStreamTrackEvent: ['trackEvent'],
      OverconstrainedError: ['new OverconstrainedError("constraint")'],
    });
  }
);