AX: <svg> elements with labels and no accessible contents are exposed as empty AXGroups
[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=320px height=240px></canvas>
5         <video id="video" autoplay></video>
6         <canvas id="canvas2" width=320px height=240px></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 color = "green";
13
14 function printCanvas()
15 {
16     var context = canvas1.getContext("2d");
17     context.fillStyle = color;
18     context.fillRect(0, 0, canvas1.width, canvas1.height);
19 }
20
21 function printRectangleEvery50ms()
22 {
23     printCanvas();
24     setTimeout(printRectangleEvery50ms, 50);
25 }
26
27 function testCanvas(testName, canvas, isSame, count)
28 {
29     var array1 = canvas.getContext("2d").getImageData(20, 20, 60, 60).data;
30     if (count === undefined)
31         count = 0;
32     canvas2.getContext("2d").drawImage(video, 0 ,0);
33     array2 = canvas2.getContext("2d").getImageData(20, 20, 60, 60).data;
34     var isEqual = true;
35     var index = 0;
36     for (index = 0; index < array1.length; ++index) {
37         // Rough comparison since we are compressing data.
38         // This test still catches errors since we are going from green to blue to red.
39         if (Math.abs(array1[index] - array2[index]) > 100) {
40             isEqual = false;
41             continue;
42         }
43     }
44     if (isEqual === isSame)
45         return Promise.resolve();
46
47     if (count === 20)
48         return Promise.reject(testName + " failed, expected " + JSON.stringify(array1) + " but got " + JSON.stringify(array2));
49
50     return waitFor(100).then(() => {
51         return testCanvas(testName, canvas, isSame, ++count);
52     });
53 }
54
55 promise_test((test) => {
56     printRectangleEvery50ms();
57     return new Promise((resolve, reject) => {
58         createConnections((firstConnection) => {
59             var stream = canvas1.captureStream();
60             firstConnection.addTrack(stream.getVideoTracks()[0], stream);
61         }, (secondConnection) => {
62             secondConnection.ontrack = (trackEvent) => {
63                 assert_true(trackEvent.track instanceof MediaStreamTrack);
64                 assert_true(trackEvent.receiver instanceof RTCRtpReceiver);
65                 assert_true(Array.isArray(trackEvent.streams), "Array.isArray() should return true");
66                 assert_true(Object.isFrozen(trackEvent.streams), "Object.isFrozen() should return true");
67                 resolve(trackEvent.streams[0]);
68             };
69         });
70         setTimeout(() => reject("Test timed out"), 5000);
71     }).then((stream) => {
72         video.srcObject = stream;
73         return video.play();
74     });
75 }, "Setting up the connection");
76
77 promise_test((test) => {
78     return testCanvas("test 1", canvas1, true);
79 }, "Checking canvas is green");
80
81 promise_test((test) => {
82     color = "red";
83     printCanvas()
84     return testCanvas("test 2", canvas1, true);
85 }, "Checking canvas is red");
86
87
88 promise_test((test) => {
89     color = "green";
90     printCanvas();
91     return testCanvas("test 3", canvas1, true);
92 }, "Checking canvas is green again");
93
94 promise_test((test) => {
95     canvas1.width = 640;
96     canvas1.height = 480;
97     printCanvas();
98     return waitForVideoSize(video, 640, 480);
99 }, "Checking canvas size change");
100         </script>
101     </head>
102 </html>