summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html')
-rw-r--r--testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html46
1 files changed, 46 insertions, 0 deletions
diff --git a/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html b/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html
new file mode 100644
index 0000000000..a9a6930aaf
--- /dev/null
+++ b/testing/web-platform/tests/mediacapture-image/ImageCapture-grabFrame.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<canvas id='canvas0' width=10 height=10></canvas>
+<canvas id='canvas1' width=10 height=10></canvas>
+</body>
+<script>
+
+// This test verifies that ImageCapture can grabFrame()s.
+
+var test = async_test(function() {
+ var canvas0 = document.getElementById('canvas0');
+ var context0 = canvas0.getContext("2d");
+ context0.fillStyle = "red";
+ context0.fillRect(0, 0, 10, 10);
+
+ var stream = canvas0.captureStream();
+
+ var capturer = new ImageCapture(stream.getVideoTracks()[0]);
+
+ capturer.grabFrame()
+ .then(bitmap => {
+ assert_equals(canvas0.width, bitmap.width);
+ assert_equals(canvas0.height, bitmap.height);
+
+ var context1 = document.getElementById('canvas1').getContext("2d");
+ context1.drawImage(bitmap, 0, 0);
+
+ var imageData0 = context0.getImageData(0, 0, 10, 10);
+ var imageData1 = context1.getImageData(0, 0, 10, 10);
+
+ assert_equals(imageData0.width, imageData1.width);
+ assert_equals(imageData0.height, imageData1.height);
+ assert_equals(imageData0.data.length, imageData1.data.length);
+ for (var i = 0; i < imageData0.data.length; i++)
+ assert_approx_equals(imageData0.data[i], imageData1.data[i], 5);
+
+ this.done();
+ })
+ .catch(error => {
+ assert_unreached('Error during grabFrame(): '+ error);
+ });
+}, 'exercises the ImageCapture API creation and grabFrame().');
+
+</script>