[iOS] Switching cameras in a WebRTC call makes black frames being sent
[WebKit-https.git] / LayoutTests / webrtc / video-remote-mute.html
1 <!doctype html>
2 <html>
3     <head>
4         <meta charset="utf-8">
5         <title>Testing basic video exchange from offerer to receiver</title>
6         <script src="../resources/testharness.js"></script>
7         <script src="../resources/testharnessreport.js"></script>
8     </head>
9     <body>
10         <video id="video" autoplay=""></video>
11         <canvas id="canvas" width="640" height="480"></canvas>
12         <script src ="routines.js"></script>
13         <script>
14 video = document.getElementById("video");
15 canvas = document.getElementById("canvas");
16
17 function isVideoBlack()
18 {
19     canvas.width = video.videoWidth;
20     canvas.height = video.videoHeight;
21     canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
22
23     imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
24     data = imageData.data;
25     for (var cptr = 0; cptr < canvas.width * canvas.height; ++cptr) {
26         if (data[4 * cptr] || data[4 * cptr + 1] || data[4 * cptr + 2])
27             return false;
28     }
29     return true;
30 }
31
32 var track;
33 promise_test((test) => {
34     if (window.testRunner)
35         testRunner.setUserMediaPermission(true);
36
37     return navigator.mediaDevices.getUserMedia({ video: true}).then((localStream) => {
38         return new Promise((resolve, reject) => {
39             createConnections((firstConnection) => {
40                 firstConnection.addTrack(localStream.getVideoTracks()[0], localStream);
41             }, (secondConnection) => {
42                 secondConnection.ontrack = (trackEvent) => { resolve(trackEvent.streams[0]); };
43             });
44             setTimeout(() => reject("Test timed out"), 5000);
45         });
46     }).then((remoteStream) => {
47         video.srcObject = remoteStream;
48         track = remoteStream.getVideoTracks()[0];
49         return video.play();
50     }).then(() => {
51          assert_false(isVideoBlack());
52     }).then(() => {
53         track.enabled = false;
54         return waitFor(500);
55     }).then(() => {
56         assert_true(isVideoBlack());
57         track.enabled = true;
58         return waitFor(500);
59     }).then(() => {
60         assert_false(isVideoBlack());
61     });
62 }, "Incoming muted/unmuted video track");
63         </script>
64     </body>
65 </html>