Chromium Code Reviews| 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..88f4ca29e885ae0d42fde2be2a9eaecdc413f6f0 |
| --- /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(); |
| + image.onload = makePromise; |
| + image.onerror = makePromise; |
| + function makePromise () { |
|
Reilly Grant (use Gerrit)
2016/10/24 20:07:23
Defining this function after it is used feels weir
|
| + faceDetector.detect(image) |
| + .then(faceDetectionResult => { |
| + reject("Promise for this test image should have been rejected."); |
| + }) |
| + .catch(error => { |
| + resolve(error); |
| + }); |
| + }; |
| + 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 the image*/); |
| + }); |
| +}, "FaceDetector should reject undecodable images with InvalidStateError."); |
| + |
| +</script> |