Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Test "video" as a source for "canvas".</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="media-file.js"></script> | |
| 6 <video></video> | |
| 7 <canvas width="160" height="120"></canvas> | |
| 8 <script> | |
| 9 async_test(function(t) { | |
| 10 var ctx; | |
| 11 var width; | |
| 12 var height; | |
| 13 var results = { | |
| 14 current: 0, | |
| 15 values: [ | |
| 16 { time: 0, r: 255, g: 255, b: 0 }, | |
| 17 { time: 2, r: 0, g: 9, b: 237 }, | |
| 18 { time: 4, r: 0, g: 32, b: 209 }, | |
| 19 { time: 6, r: 0, g: 54, b: 182 }, | |
| 20 { time: 8, r: 0, g: 77, b: 154 }, | |
| 21 { time: 10, r: 0, g: 97, b: 126 } | |
| 22 ] | |
| 23 }; | |
| 24 | |
| 25 var video = document.querySelector("video"); | |
| 26 | |
| 27 video.onloadedmetadata = t.step_func(function() { | |
| 28 width = video.videoWidth / 2; | |
| 29 height = video.videoHeight / 2; | |
| 30 | |
| 31 ctx = document.querySelector("canvas").getContext("2d"); | |
| 32 ctx.fillStyle = "yellow"; | |
| 33 ctx.fillRect(0, 0, width, height); | |
| 34 testFrame(); | |
| 35 }); | |
| 36 | |
| 37 function testFrame() { | |
| 38 var expected = results.values[results.current]; | |
| 39 if (expected.time) | |
| 40 video.currentTime = expected.time; | |
| 41 | |
| 42 setTimeout(function() { | |
|
fs
2016/07/02 18:33:45
Could we use 'seeked' for this? (May need special-
fs
2016/07/02 18:39:44
Possibly combined with rAF or setTimeout(..., 0).
Srirama
2016/07/03 04:31:34
Done.
| |
| 43 var expected = results.values[results.current]; | |
| 44 if (expected.time) | |
| 45 ctx.drawImage(video, 0, 0, width, height); | |
| 46 | |
| 47 var frame = ctx.getImageData(0, 0, width, height); | |
| 48 r = frame.data[4 * 2 * width + 16 + 0]; | |
| 49 g = frame.data[4 * 2 * width + 16 + 1]; | |
| 50 b = frame.data[4 * 2 * width + 16 + 2]; | |
|
fs
2016/07/02 18:33:45
var r = ...;
et.c
Srirama
2016/07/03 04:31:34
Done.
| |
| 51 | |
| 52 assert_equals(r, expected.r); | |
| 53 assert_equals(g, expected.g); | |
| 54 assert_equals(b, expected.b); | |
| 55 | |
| 56 if (++results.current == results.values.length) | |
| 57 t.done(); | |
| 58 else | |
| 59 setTimeout(testFrame, 0); | |
| 60 }, 100); | |
| 61 } | |
| 62 | |
| 63 video.src = findMediaFile("video", "content/counting"); | |
| 64 }); | |
| 65 </script> | |
| OLD | NEW |