summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js')
-rw-r--r--testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js b/testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js
new file mode 100644
index 0000000000..3981c6fdc8
--- /dev/null
+++ b/testing/web-platform/tests/shape-detection/detection-on-worker.https.worker.js
@@ -0,0 +1,54 @@
+importScripts("/resources/testharness.js");
+importScripts("/resources/test-only-api.js");
+importScripts("resources/shapedetection-helpers.js");
+
+'use strict';
+
+// These tests verify that a Detector's detect() works on an
+// ImageBitmap on workers.
+const imageBitmapTests =
+ [
+ {
+ createDetector: () => { return new FaceDetector(); },
+ mockTestName: "FaceDetectionTest",
+ resultSize: 3, // Number of faces
+ detectorType: "Face"
+ },
+ {
+ createDetector: () => { return new BarcodeDetector(); },
+ mockTestName: "BarcodeDetectionTest",
+ resultSize: 2, // Number of barcodes
+ detectorType: "Barcode"
+ },
+ {
+ createDetector: () => { return new TextDetector(); },
+ mockTestName: "TextDetectionTest",
+ resultSize: 2, // Number of text blocks
+ detectorType: "Text"
+ }
+ ];
+
+for (let imageBitmapTest of imageBitmapTests) {
+ // ImageBitmap is of transferable type and can be sent to and
+ // tested on worker.
+ detection_test(imageBitmapTest.mockTestName, async (t, detectionTest) => {
+ const img = createTestImage();
+ const theImageBitmap = await createImageBitmap(img);
+ const detector = imageBitmapTest.createDetector();
+ const detectionResult = await detector.detect(theImageBitmap);
+ assert_equals(detectionResult.length, imageBitmapTest.resultSize,
+ `Number of ${imageBitmapTest.detectorType}`);
+ }, `${imageBitmapTest.detectorType} Detector detect(ImageBitmap) on worker`);
+}
+
+function createTestImage() {
+ const image = new OffscreenCanvas(100, 50);
+ const imgctx = image.getContext('2d');
+ imgctx.fillStyle = "#F00";
+ imgctx.fillRect(0, 0, 2, 2);
+ imgctx.fillStyle = "#0F0";
+ imgctx.fillRect(0, 0, 1, 1);
+ return image;
+}
+
+done();