OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src=../../resources/testharness.js></script> |
| 3 <script src=../../resources/testharnessreport.js></script> |
| 4 <script> |
| 5 |
| 6 // TODO(xianglu): Consider adding tests for image with only one dimension |
| 7 // equal to zero. |
| 8 |
| 9 // Returns a Promise that is resolve()d if detect() fails. |
| 10 function detectFaceAndExpectError(imageUrl) { |
| 11 return new Promise(function(resolve, reject) { |
| 12 var image = new Image(); |
| 13 var faceDetector = new FaceDetector(); |
| 14 var tryFaceDetection = function() { |
| 15 faceDetector.detect(image) |
| 16 .then(faceDetectionResult => { |
| 17 reject("Promise for this test image should have been rejected."); |
| 18 }) |
| 19 .catch(error => { |
| 20 resolve(error); |
| 21 }); |
| 22 }; |
| 23 image.onload = tryFaceDetection; |
| 24 image.onerror = tryFaceDetection; |
| 25 image.src = imageUrl; |
| 26 }); |
| 27 } |
| 28 |
| 29 // This test verifies that FaceDetector will reject an empty image. |
| 30 promise_test(function(t) { |
| 31 return detectFaceAndExpectError("") |
| 32 .then(function(error) { |
| 33 assert_equals(error.name, "InvalidStateError"); |
| 34 assert_equals(error.message, "HTMLImageElement is empty."); |
| 35 }); |
| 36 }, "FaceDetector should reject empty images with InvalidStateError."); |
| 37 |
| 38 // This test verifies that FaceDetector will reject an undecodable image. |
| 39 promise_test(function(t) { |
| 40 return detectFaceAndExpectError("../../imported/wpt/images/broken.png") |
| 41 .then(function(error) { |
| 42 assert_equals(error.name, "InvalidStateError"); |
| 43 assert_regexp_match(error.message, /Unable to decompress*/); |
| 44 }); |
| 45 }, "FaceDetector should reject undecodable images with InvalidStateError."); |
| 46 |
| 47 </script> |
OLD | NEW |