12ef993eda08b10cfe824eda49a1a9f55a33a803
[WebKit-https.git] / LayoutTests / fast / mediastream / captureStream / canvas2d.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>
10
11 var canvas1 = document.getElementById("canvas1");
12 var canvas2 = document.getElementById("canvas2");
13 var video = document.getElementById("video");
14
15 function checkCanvas(canvas, stream)
16 {
17     return new Promise((resolve, reject) => {
18         video.srcObject = stream;
19         video.onplay = () => {
20             canvas2.getContext("2d").drawImage(video, 0 ,0);
21             try {
22                 assert_array_equals(canvas.getContext("2d").getImageData(0 ,0, 100, 100), canvas2.getContext("2d").getImageData(0, 0, 100, 100));
23             } catch(e) {
24                 reject(e);
25                 return;
26             }
27             resolve();
28         }
29     });
30 }
31
32 function printLine()
33 {
34     var context = canvas1.getContext("2d");
35     context.strokeStyle="green";
36     context.beginPath();
37     context.moveTo(0,0);
38     context.lineTo(100, 100);
39     context.stroke();
40
41     setTimeout(printLine, 500);
42 }
43
44 promise_test((test) => {
45     var stream = canvas1.captureStream();
46
47     if (window.internals)
48         assert_true(internals.pageMediaState().toLowerCase().indexOf("capture") == -1, "media state should not contain any camera capture");
49     promise = checkCanvas(canvas1, stream);
50
51     printLine();
52
53
54     return promise;
55 }, "captureStream with 2d context drawing");
56
57 promise_test((test) => {
58     var stream = canvas1.captureStream().clone();
59     if (window.internals)
60         assert_true(internals.pageMediaState().toLowerCase().indexOf("capture") == -1, "media state should not contain any camera capture");
61     promise = checkCanvas(canvas1, stream);
62
63     printLine();
64
65
66     return promise;
67 }, "captureStream cloning");
68         </script>
69     </head>
70 </html>