summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shape-detection/detected-postMessage.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/shape-detection/detected-postMessage.https.html
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/shape-detection/detected-postMessage.https.html')
-rw-r--r--testing/web-platform/tests/shape-detection/detected-postMessage.https.html90
1 files changed, 90 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shape-detection/detected-postMessage.https.html b/testing/web-platform/tests/shape-detection/detected-postMessage.https.html
new file mode 100644
index 0000000000..8066984b26
--- /dev/null
+++ b/testing/web-platform/tests/shape-detection/detected-postMessage.https.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/shapedetection-helpers.js"></script>
+<script>
+
+// These tests verify that Detected{Face, Barcode, Text} can be passed to
+// postMessage().
+const postMessageTests =
+ [
+ {
+ createDetector: () => { return new FaceDetector(); },
+ mockTestName: "FaceDetectionTest",
+ detectionResultTest: FaceDetectorDetectionResultTest,
+ name: "Face - DetectedFace can be passed to postMessage()"
+ },
+ {
+ createDetector: () => { return new BarcodeDetector(); },
+ mockTestName: "BarcodeDetectionTest",
+ detectionResultTest: BarcodeDetectorDetectionResultTest,
+ name: "Barcode - DetectedBarcode can be passed to postMessage()"
+ },
+ {
+ createDetector: () => { return new TextDetector(); },
+ mockTestName: "TextDetectionTest",
+ detectionResultTest: TextDetectorDetectionResultTest,
+ name: "Text - DetectedText can be passed to postMessage()",
+ },
+ ];
+
+for (let postMessageTest of postMessageTests) {
+ detection_test(postMessageTest.mockTestName, async t => {
+ const img = new Image();
+ const imgWatcher = new EventWatcher(t, img, ["load", "error"]);
+ img.src = "/images/green-16x16.png";
+ await imgWatcher.wait_for("load");
+
+ const canvas = document.createElement("canvas");
+ canvas.getContext("2d").drawImage(img, 0, 0);
+
+ const detector = postMessageTest.createDetector();
+ const detectionResult = await detector.detect(canvas.getContext("2d")
+ .getImageData(0, 0, canvas.width, canvas.height));
+
+ const msgWatcher = new EventWatcher(t, window, ['message']);
+ window.postMessage(detectionResult);
+ const evt = await msgWatcher.wait_for('message');
+ postMessageTest.detectionResultTest(evt.data)
+ }, postMessageTest.name);
+}
+
+function FaceDetectorDetectionResultTest(detectionResult) {
+ assert_equals(detectionResult.length, 3, "Number of faces");
+ assert_equals(detectionResult[0].landmarks.length, 2, "Number of landmarks");
+ assert_object_equals(detectionResult[0].landmarks[0],
+ {type : 'eye', locations : [{x : 4.0, y : 5.0}]},
+ "landmark #1");
+ assert_equals(detectionResult[0].landmarks[1].locations.length, 8,
+ "Number of locations along eye");
+ assert_object_equals(detectionResult[1].landmarks[0],
+ {type : 'nose', locations : [{x : 100.0, y : 50.0}]},
+ "landmark #2");
+ assert_equals(detectionResult[1].landmarks[1].locations.length, 9,
+ "Number of locations along nose");
+}
+
+function BarcodeDetectorDetectionResultTest(detectionResult) {
+ assert_equals(detectionResult.length, 2, "Number of barcodes");
+ assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
+ assert_equals(detectionResult[0].format, "qr_code", "barcode 1 format");
+ assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
+ assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
+}
+
+function TextDetectorDetectionResultTest(detectionResult) {
+ assert_equals(detectionResult.length, 2, "Number of textBlocks");
+ assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
+ assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
+ for (let i = 0; i < detectionResult.length; i++) {
+ assert_equals(detectionResult[i].boundingBox.x, detectionResult[i].cornerPoints[0].x);
+ assert_equals(detectionResult[i].boundingBox.y, detectionResult[i].cornerPoints[0].y);
+ assert_equals(detectionResult[i].boundingBox.width,
+ detectionResult[i].cornerPoints[2].x - detectionResult[i].cornerPoints[3].x);
+ assert_equals(detectionResult[i].boundingBox.height,
+ detectionResult[i].cornerPoints[2].y - detectionResult[i].cornerPoints[1].y);
+ }
+
+}
+
+</script>