Improve debugging ability of some webrtc tests
[WebKit-https.git] / LayoutTests / webrtc / captureCanvas-webrtc.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3     <head>
4         <canvas id="canvas1" width=100px height=100px></canvas>
5         <video id="video" autoplay width=100px height=100px></video>
6         <canvas id="canvas2" width=100px height=100px></canvas>
7         <script src="../resources/testharness.js"></script>
8         <script src="../resources/testharnessreport.js"></script>
9         <script src ="routines.js"></script>
10         <script>
11
12 var canvas1 = document.getElementById("canvas1");
13 var canvas2 = document.getElementById("canvas2");
14 var video = document.getElementById("video");
15
16 var color = "green";
17 function printRectangle()
18 {
19     var context = canvas1.getContext("2d");
20     context.fillStyle = color;
21     context.fillRect(0, 0, 100, 100);
22     setTimeout(printRectangle, 50);
23 }
24
25 promise_test((test) => {
26     printRectangle();
27     return new Promise((resolve, reject) => {
28         createConnections((firstConnection) => {
29             var stream = canvas1.captureStream();
30             firstConnection.addTrack(stream.getVideoTracks()[0], stream);
31         }, (secondConnection) => {
32             secondConnection.ontrack = (trackEvent) => {
33                 assert_true(trackEvent.track instanceof MediaStreamTrack);
34                 assert_true(trackEvent.receiver instanceof RTCRtpReceiver);
35                 assert_true(Array.isArray(trackEvent.streams), "Array.isArray() should return true");
36                 assert_true(Object.isFrozen(trackEvent.streams), "Object.isFrozen() should return true");
37                 resolve(trackEvent.streams[0]);
38             };
39         });
40         setTimeout(() => reject("Test timed out"), 5000);
41     }).then((stream) => {
42         video.srcObject = stream;
43         return video.play();
44     });
45 }, "Setting up the connection");
46
47 promise_test((test) => {
48     return waitFor(100).then(() => {
49         canvas2.getContext("2d").drawImage(video, 0 ,0);
50         assert_array_equals(canvas2.getContext("2d").getImageData(20 ,20, 60, 60), canvas1.getContext("2d").getImageData(20, 20, 60, 60));
51     });
52 }, "Checking canvas is green");
53
54 promise_test((test) => {
55     color = "red";
56     return waitFor(300).then(() => {
57         canvas2.getContext("2d").drawImage(video, 0 ,0);
58         assert_array_equals(canvas2.getContext("2d").getImageData(20 ,20, 60, 60), canvas1.getContext("2d").getImageData(20, 20, 60, 60));
59     });
60 }, "Checking canvas is red");
61
62
63 promise_test((test) => {
64     color = "green";
65     return waitFor(300).then(() => {
66         canvas2.getContext("2d").drawImage(video, 0 ,0);
67         assert_array_equals(canvas2.getContext("2d").getImageData(20 ,20, 60, 60), canvas1.getContext("2d").getImageData(20, 20, 60, 60));
68     });
69 }, "Checking canvas is green again");
70         </script>
71     </head>
72 </html>