OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <title>drawing <video> to <canvas></title> | |
4 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | |
5 (Please avoid writing new tests using video-test.js) --> | |
6 <script src=../http/tests/media/video-test.js></script> | |
7 | |
8 <script> | |
9 var ctx; | |
10 var results = { | |
11 current: 0, | |
12 values: [ | |
13 { time:0, r:255, g:255, b:0 }, | |
14 { time:2, r:8, g:0, b:226 }, | |
15 { time:4, r:0, g:24, b:197 }, | |
16 { time:6, r:0, g:46, b:166 }, | |
17 { time:8, r:0, g:66, b:136 }, | |
18 { time:10, r:0, g:85, b:112 }, | |
19 ] | |
20 }; | |
21 | |
22 var width; | |
23 var height; | |
24 | |
25 function testPixel() | |
26 { | |
27 var expected = results.values[results.current]; | |
28 if (expected.time) | |
29 ctx.drawImage(video, 0, 0, width, height); | |
30 | |
31 var frame = ctx.getImageData(0, 0, width, height); | |
32 r = frame.data[4 * 2 * width + 16 + 0]; | |
33 g = frame.data[4 * 2 * width + 16 + 1]; | |
34 b = frame.data[4 * 2 * width + 16 + 2]; | |
35 | |
36 testExpected("r", expected.r); | |
37 testExpected("g", expected.g); | |
38 testExpected("b", expected.b); | |
39 | |
40 if (++results.current >= results.values.length) | |
41 endTest(); | |
42 else | |
43 setTimeout(testFrame, 0); | |
44 } | |
45 | |
46 function testFrame() | |
47 { | |
48 video.pause(); | |
49 consoleWrite(""); | |
50 var expected = results.values[results.current]; | |
51 if (expected.time) | |
52 run("video.currentTime = " + expected.time); | |
53 setTimeout(testPixel, 100); | |
54 } | |
55 | |
56 function loadedmetadata() | |
57 { | |
58 width = video.videoWidth / 2; | |
59 height = video.videoHeight / 2; | |
60 | |
61 ctx = canvas.getContext("2d"); | |
62 ctx.fillStyle = 'yellow'; | |
63 ctx.fillRect(0, 0, width, height); | |
64 testFrame(); | |
65 } | |
66 | |
67 function start() | |
68 { | |
69 findMediaElement(); | |
70 canvas = document.getElementsByTagName('canvas')[0]; | |
71 waitForEvent('loadedmetadata', loadedmetadata); | |
72 run("video.src = 'content/counting.mp4'"); | |
73 } | |
74 </script> | |
75 </head> | |
76 | |
77 <body onload="start()" > | |
78 | |
79 <div> | |
80 <video controls></video> | |
81 <canvas width="160" height="120" ></canvas> | |
82 </div> | |
83 | |
84 <p>Test <video> as a source for <canvas>.</p> | |
85 | |
86 </body> | |
87 </html> | |
OLD | NEW |