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

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: 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 }, gotStream, getStreamFailed);
10 12
11 <script type="text/javascript"> 13 function gotStream(stream) {
fs 2016/06/30 18:43:42 Use an anonymous function?
Srirama 2016/06/30 19:16:22 Done.
12 14 // start preview.
13 if (window.internals) 15 video.src = URL.createObjectURL(stream);
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 } 16 }
59 17
60 waitForEvent('canplaythrough', canplaythrough); 18 function getStreamFailed(error) {
fs 2016/06/30 18:43:42 Use t.unreached_func() instead of this?
Srirama 2016/06/30 19:16:21 Done.
61 } 19 assert_unreached();
20 }
62 21
63 </script> 22 video.oncanplaythrough = t.step_func_done(function() {
64 </head> 23 var width = canvas.width;
24 var height = canvas.height;
25 var ctx = canvas.getContext("2d");
26 ctx.fillStyle = "black";
27 ctx.fillRect(0, 0, width, height);
65 28
66 <body onload="playPreview()"> 29 // paint to canvas.
67 <video width="320" height="240" autoplay="autoplay"></video> 30 ctx.drawImage(video, 0, 0, width, height);
68 <canvas width="1" height="1" ></canvas> 31 var frame = ctx.getImageData(0, 0, width, height);
69 </body> 32 assert_not_equals(frame, null);
70 </html> 33 assert_not_equals(frame.data[0] + frame.data[1] + frame.data[2], 0);
34 });
35 });
36 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698