summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-transfer.https.html
blob: e110b4b3722e4f96abc63d1e87e2cf85e9af71a8 (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
<!doctype html>
<title>MediaStreamTrack transfer to Worker</title>
<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 id="workerCode" type="javascript/worker">
self.onmessage = (e) => {
  try {
    if(e.data instanceof MediaStreamTrack) {
      self.postMessage({result: 'Success'});
      return;
    } else {
      self.postMessage({
        result: 'Failure',
        error: `${e.data} is not a MediaStreamTrack`
      });
    }
  } catch (error) {
    self.postMessage({
      result: 'Failure',
      error
    });
  }
}
</script>
<script>
promise_test(async () => {
  const workerBlob = new Blob([document.querySelector('#workerCode').textContent],
                {type: "text/javascript"});
  const workerUrl = window.URL.createObjectURL(workerBlob);
  const worker = new Worker(workerUrl);
  window.URL.revokeObjectURL(workerUrl);
  await setMediaPermission("granted", ["camera"]);
  const stream = await navigator.mediaDevices.getDisplayMedia({video: true});
  const track = stream.getVideoTracks()[0];
  const result = new Promise((resolve, reject) => {
    worker.onmessage = (e) => {
      if (e.data.result === 'Failure') {
        reject('Failed: ' + e.data.error);
      } else {
        resolve();
      }
    };
  });
  worker.postMessage(track, [track]);
  return result;
});
</script>