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

Unified Diff: third_party/WebKit/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-preservedrawingbuffer-false.html

Issue 2768683002: Fix unreliable MediaStream capture from WebGL canvases (Closed)
Patch Set: simplify test by removing WebRTC connection Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-preservedrawingbuffer-false.html
diff --git a/third_party/WebKit/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-preservedrawingbuffer-false.html b/third_party/WebKit/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-preservedrawingbuffer-false.html
new file mode 100644
index 0000000000000000000000000000000000000000..cd45effa72a314a52ce91c235952fe60b38f9646
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-webgl-preservedrawingbuffer-false.html
@@ -0,0 +1,55 @@
+ <!DOCTYPE html>
+ <script src =../../resources/testharness.js></script>
+ <script src =../../resources/testharnessreport.js></script>
+ <body>
+ <canvas id="output"></canvas>
+ </body>
+ <script>
+
+// When WebGL contexts are created with preserveDrawingBuffer set
+// to false, there is a risk that stream capture will occur after
+// the canvas has cleared its contents. This test verifies that
+// this is not the case.
+
+var canvas = document.getElementById('output');
+var framesToTest = 4;
+const ON_DATA_AVAILABLE_THRESHOLD = 10;
+
+function drawWebGL() {
+ var gl = canvas.getContext('webgl', { preserveDrawingBuffer: false });
+ gl.clearColor(0, 1, 0, 1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ if (framesToTest > 0)
+ requestAnimationFrame(drawWebGL);
+};
+
+async_test(function(test) {
+ var video = document.createElement('video');
+ var stream = canvas.captureStream();
+ video.srcObject = stream;
+ recorder = new MediaRecorder(stream);
+ var testCtx = document.createElement('canvas').getContext('2d');
+
+ recorder.ondataavailable = function(event) {
+ if (event.data.size > ON_DATA_AVAILABLE_THRESHOLD) {
+ test.step(function() {
+ testCtx.drawImage(video, 0, 0);
emircan 2017/03/22 18:26:26 Sorry I forgot about this earlier when we talked a
+ var data = testCtx.getImageData(0, 0, 1, 1).data;
+ // Equality is approximate because the video encoding is lossy.
+ assert_approx_equals(data[0], 0, 4, 'The red component.');
+ assert_approx_equals(data[1], 255, 4, 'The green component.');
+ assert_approx_equals(data[2], 0, 4, 'The blue component.');
+ assert_approx_equals(data[3], 255, 4, 'The alpha component.');
+ });
+ framesToTest = framesToTest - 1
+ if (framesToTest == 0) {
+ test.done();
+ }
+ }
+ }
+
+ recorder.start(0);
+ drawWebGL();
+}, 'Encode succeeds with captureStream() on an animated canvas with WebGL.');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698