| Index: third_party/WebKit/LayoutTests/fast/shapedetection/shapedetection-security-test.html
|
| diff --git a/third_party/WebKit/LayoutTests/fast/shapedetection/shapedetection-security-test.html b/third_party/WebKit/LayoutTests/fast/shapedetection/shapedetection-security-test.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..56def7be6c874f4e4374539ff0a9b73bf52fb375
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/fast/shapedetection/shapedetection-security-test.html
|
| @@ -0,0 +1,47 @@
|
| +<!DOCTYPE html>
|
| +<script src=../../resources/testharness.js></script>
|
| +<script src=../../resources/testharnessreport.js></script>
|
| +<script>
|
| +
|
| +// TODO(xianglu): Consider adding tests for image with only one dimension
|
| +// equal to zero.
|
| +
|
| +// Returns a Promise that is resolve()d if detect() fails.
|
| +function detectFaceAndExpectError(imageUrl) {
|
| + return new Promise(function(resolve, reject) {
|
| + var image = new Image();
|
| + var faceDetector = new FaceDetector();
|
| + var tryFaceDetection = function() {
|
| + faceDetector.detect(image)
|
| + .then(faceDetectionResult => {
|
| + reject("Promise for this test image should have been rejected.");
|
| + })
|
| + .catch(error => {
|
| + resolve(error);
|
| + });
|
| + };
|
| + image.onload = tryFaceDetection;
|
| + image.onerror = tryFaceDetection;
|
| + image.src = imageUrl;
|
| + });
|
| +}
|
| +
|
| +// This test verifies that FaceDetector will reject an empty image.
|
| +promise_test(function(t) {
|
| + return detectFaceAndExpectError("")
|
| + .then(function(error) {
|
| + assert_equals(error.name, "InvalidStateError");
|
| + assert_equals(error.message, "HTMLImageElement is empty.");
|
| + });
|
| +}, "FaceDetector should reject empty images with InvalidStateError.");
|
| +
|
| +// This test verifies that FaceDetector will reject an undecodable image.
|
| +promise_test(function(t) {
|
| + return detectFaceAndExpectError("../../imported/wpt/images/broken.png")
|
| + .then(function(error) {
|
| + assert_equals(error.name, "InvalidStateError");
|
| + assert_regexp_match(error.message, /Unable to decompress*/);
|
| + });
|
| +}, "FaceDetector should reject undecodable images with InvalidStateError.");
|
| +
|
| +</script>
|
|
|