summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-MediaElement-disabled-video-is-black.https.html
blob: 3652362b848f8f12ae8c2e00c013583a5113a2dc (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
<!doctype html>
<html>
<head>
<title>A disabled video track is rendered as blackness</title>
<link rel="author" title="Dominique Hazael-Massieux" href="mailto:dom@w3.org"/>
<link rel="help" href="http://dev.w3.org/2011/webrtc/editor/getusermedia.html#introduction">
<link rel="help" href="http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreams-as-media-elements">
</head>
<body>
<p class="instructions">When prompted, accept to share your video stream.</p>
<h1 class="instructions">Description</h1>
<p class="instructions">This test checks that a disabled video track in a
MediaStream is rendered as blackness.</p>
<video id="vid"></video>

<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>
const vid = document.getElementById("vid");
const cv = document.createElement("canvas");
promise_test(async () => {
  await setMediaPermission("granted", ["camera"]);
  const stream = await navigator.mediaDevices.getUserMedia({video: true});
  if (stream.getVideoTracks()[0].enabled) {
    stream.getVideoTracks()[0].enabled = false;
  }

  let resolveLoadedPromise;
  const videoLoaded = new Promise(res => resolveLoadedPromise = res)
  var testOnceLoadeddata = function() {
        vid.removeEventListener("loadeddata", testOnceLoadeddata, false);
        cv.width = vid.offsetWidth;
        cv.height = vid.offsetHeight;
        var ctx = cv.getContext("2d");
        ctx.drawImage(vid,0,0);
        var imageData = ctx.getImageData(0, 0, cv.width, cv.height);
        for (var i = 0; i < imageData.data.length; i+=4) {
          assert_equals(imageData.data[i], 0, "No red component in pixel #" + i);
          assert_equals(imageData.data[i + 1], 0, "No green component in pixel #" + i);
          assert_equals(imageData.data[i + 2], 0, "No blue component in pixel #" + i);
          assert_equals(imageData.data[i + 3], 255, "No transparency in pixel #" + i);
        }
        resolveLoadedPromise();
  };

  vid.srcObject = stream;
  vid.play();
  vid.addEventListener("loadeddata", testOnceLoadeddata, false);
}, "Tests that a disabled video track in a MediaStream is rendered as blackness");
</script>
</body>
</html>