diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/shape-detection/detection-security-test.https.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/shape-detection/detection-security-test.https.html')
-rw-r--r-- | testing/web-platform/tests/shape-detection/detection-security-test.https.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shape-detection/detection-security-test.https.html b/testing/web-platform/tests/shape-detection/detection-security-test.https.html new file mode 100644 index 0000000000..4d87238dad --- /dev/null +++ b/testing/web-platform/tests/shape-detection/detection-security-test.https.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/shapedetection-helpers.js"></script> +<script> + +// Detectors should reject undecodable images with an InvalidStateError. +const badImageTests = + [ + { + createDetector: () => { return new FaceDetector(); }, + name: "Face - detect(broken image)" + }, + { + createDetector: () => { return new BarcodeDetector(); }, + name: "Barcode - detect(broken image)" + }, + { + createDetector: () => { return new TextDetector(); }, + name: "Text - detect(broken image)" + } + ]; + +for (let badImageTest of badImageTests) { + // This test verifies that a Detector will reject an undecodable image. + promise_test(async t => { + const img = new Image(); + const error = + await detectOnElementAndExpectError(badImageTest.createDetector, + img, "/images/broken.png"); + assert_equals(error.name, "InvalidStateError"); + }, badImageTest.name); +} + +// Detectors should reject undecodable videos with an InvalidStateError. +const badVideoTests = + [ + { + createDetector: () => { return new FaceDetector(); }, + name: "Face - detect(broken video)" + }, + { + createDetector: () => { return new BarcodeDetector(); }, + name: "Barcode - detect(broken video)" + }, + { + createDetector: () => { return new TextDetector(); }, + name: "Text - detect(broken video)" + } + ]; + +for (let badVideoTest of badVideoTests) { + // This test verifies that a Detector will reject a broken video. + promise_test(async t => { + const video = document.createElement('video'); + const error = + await detectOnElementAndExpectError(badVideoTest.createDetector, + video, "garbage.webm"); + assert_equals(error.name, "InvalidStateError"); + }, badVideoTest.name); +} + +// Returns a Promise that is resolve()d if detect() is rejected. Needs an input +// |element| (e.g. an HTMLImageElement or HTMLVideoElement) and a |url| to load. +function detectOnElementAndExpectError(createDetector, element, url) { + return new Promise((resolve, reject) => { + const tryDetection = async () => { + const detector = createDetector(); + try { + const detectionResult = await detector.detect(element); + reject("Promise should have been rejected."); + } catch (error) { + resolve(error); + } + }; + element.onload = tryDetection; + element.onerror = tryDetection; + element.src = url; + }); +}; + +</script> |