blob: ffcaad04ee293b6eea49d440cad6902e760303d0 [file] [log] [blame]
<!DOCTYPE html>
<script src=../resources/testharness.js></script>
<script src=../resources/testharnessreport.js></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/shape_detection/public/interfaces/barcodedetection.mojom.js"></script>
<script src="file:///gen/services/shape_detection/public/interfaces/facedetection.mojom.js"></script>
<script src="file:///gen/services/shape_detection/public/interfaces/facedetection_provider.mojom.js"></script>
<script src="file:///gen/services/shape_detection/public/interfaces/textdetection.mojom.js"></script>
<script src="resources/mock-barcodedetection.js"></script>
<script src="resources/mock-facedetection.js"></script>
<script src="resources/mock-textdetection.js"></script>
<script>
// 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(function(resolve, reject) {
var tryDetection = async function() {
var detector = createDetector();
try {
var detectionResult = await detector.detect(element);
reject("Promise should have been rejected.");
} catch (error) {
resolve(error);
}
};
element.onload = tryDetection;
element.onerror = tryDetection;
element.src = url;
});
};
// This test verifies that a Detector will reject an undecodable image.
var createTestForBadImage = function(createDetector) {
promise_test(function(t) {
var image = new Image();
return detectOnElementAndExpectError(createDetector, image,
"../external/wpt/images/broken.png")
.then(function(error) {
assert_equals(error.name, "InvalidStateError");
});
});
};
// Detectors should reject undecodable images with an InvalidStateError.
generate_tests(createTestForBadImage, [
[ "Face - detect(broken image)", () => { return new FaceDetector(); } ],
[ "Barcode - detect(broken image)", () => { return new BarcodeDetector(); } ],
[ "Text - detect(broken image)", () => { return new TextDetector(); } ]
]);
// This test verifies that a Detector will reject a broken video.
var createTestForBadVideo = function(createDetector) {
promise_test(function(t) {
var video = document.createElement('video');
return detectOnElementAndExpectError(createDetector, video,
"content/garbage.webm")
.then(function(error) {
assert_equals(error.name, "InvalidStateError");
});
});
};
// Detectors should reject undecodable videos with an InvalidStateError.
generate_tests(createTestForBadVideo, [
[ "Face - detect(broken video)", () => { return new FaceDetector(); } ],
[ "Barcode - detect(broken video)", () => { return new BarcodeDetector(); } ],
[ "Text - detect(broken video)", () => { return new TextDetector(); } ]
]);
</script>