Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/WebKit/LayoutTests/media/video-capture-canvas.html

Issue 2112003002: Convert video-canvas* and video-capture* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use timeupdate event Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE HTML"> 1 <!DOCTYPE html>
2 <html> 2 <title>Verify drawing video frames to canvas using media stream.</title>
3 <head> 3 <script src="../resources/testharness.js"></script>
4 <script src=media-file.js></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 5 <video></video>
6 (Please avoid writing new tests using video-test.js) --> 6 <canvas width="1" height="1"></canvas>
7 <script src=video-test.js></script> 7 <script>
8 <script src=video-played.js></script> 8 async_test(function(t) {
9 <script src="../resources/js-test.js"></script> 9 var video = document.querySelector("video");
10 var canvas = document.querySelector("canvas");
11 navigator.webkitGetUserMedia({ video: true }, function(stream) {
12 // start preview.
13 video.src = URL.createObjectURL(stream);
14 }, getStreamFailed);
10 15
11 <script type="text/javascript"> 16 function getStreamFailed(error) {
12 17 t.unreached_func();
13 if (window.internals)
14 window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
15
16 function gotStream(stream)
17 {
18 consoleWrite("got a stream");
19 previewURL = URL.createObjectURL(stream);
20 video.src = previewURL;
21 consoleWrite("start preview");
22 }
23
24 function gotStreamFailed(error)
25 {
26 consoleWrite("Failed to get access to local media. Error code was " + error. code);
27 }
28
29 function canplaythrough()
30 {
31 width = canvas.width;
32 height = canvas.height;
33 ctx = canvas.getContext("2d");
34 ctx.fillStyle = 'black';
35 ctx.fillRect(0, 0, width, height);
36
37 consoleWrite("paint to canvas");
38 ctx.drawImage(video, 0, 0, width, height);
39 shouldBeTrue("!!ctx.getImageData(0, 0, width, height)");
40
41 frame = ctx.getImageData(0, 0, width, height);
42 r = frame.data[0];
43 g = frame.data[1];
44 b = frame.data[2];
45 testExpected("r+g+b", 0, "!=");
46 endTest();
47 }
48
49 function playPreview()
50 {
51 findMediaElement();
52 canvas = document.getElementsByTagName('canvas')[0];
53 try {
54 consoleWrite("request access to local media");
55 navigator.webkitGetUserMedia({video:true}, gotStream, gotStreamFailed);
56 } catch (e) {
57 consoleWrite("getUserMedia error " + "(" + e.name + " / " + e.message + ")");
58 } 18 }
59 19
60 waitForEvent('canplaythrough', canplaythrough); 20 video.oncanplaythrough = t.step_func_done(function() {
61 } 21 var width = canvas.width;
22 var height = canvas.height;
23 var ctx = canvas.getContext("2d");
24 ctx.fillStyle = "black";
25 ctx.fillRect(0, 0, width, height);
62 26
63 </script> 27 // paint to canvas.
64 </head> 28 ctx.drawImage(video, 0, 0, width, height);
65 29 var frame = ctx.getImageData(0, 0, width, height);
66 <body onload="playPreview()"> 30 assert_not_equals(frame, null);
67 <video width="320" height="240" autoplay="autoplay"></video> 31 assert_not_equals(frame.data[0] + frame.data[1] + frame.data[2], 0);
68 <canvas width="1" height="1" ></canvas> 32 });
69 </body> 33 });
70 </html> 34 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698