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..56c29727ece88d7b79ab313ecca756c6aee44e62 |
--- /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 will resolve to a rejection from detect method. |
mcasas
2016/10/21 23:43:16
This reads a bit confusing, suggest instead:
// Re
xianglu
2016/10/22 02:19:09
Done.
|
+function makeTestPromiseWithImageUrl(url) { |
+ return new Promise(function(resolve, reject) { |
+ var image = new Image(); |
+ var faceDetector = new FaceDetector(); |
+ image.onload = makePromise; |
+ image.onerror = makePromise; |
+ function makePromise () { |
+ faceDetector.detect(image) |
+ .then(faceDetectionResult => { |
+ reject("Promise for this test image should have been rejected."); |
+ }) |
+ .catch(error => { |
+ resolve(error); |
+ }); |
+ }; |
+ image.src = url; |
+ }); |
+} |
+ |
+// This test verifies that FaceDetector will reject an empty image. |
+promise_test(function(t) { |
+ return makeTestPromiseWithImageUrl("") |
+ .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 makeTestPromiseWithImageUrl("../../imported/wpt/images/broken.png") |
+ .then(function(error) { |
+ assert_equals(error.name, "InvalidStateError"); |
+ assert_regexp_match(error.message, /Image is broken*/); |
+ }); |
+}, "FaceDetector should reject undecodable images with InvalidStateError."); |
+ |
+</script> |