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): Move this helper function to a shared location for reuse. |
| 7 function detectFaceAndExpectError(imageUrl) { |
| 8 return new Promise(function(resolve, reject) { |
| 9 var image = new Image(); |
| 10 var faceDetector = new FaceDetector(); |
| 11 var tryFaceDetection = function() { |
| 12 faceDetector.detect(image) |
| 13 .then(faceDetectionResult => { |
| 14 reject("Promise for this test image should have been rejected."); |
| 15 }) |
| 16 .catch(error => { |
| 17 resolve(error); |
| 18 }); |
| 19 }; |
| 20 image.onload = tryFaceDetection; |
| 21 image.onerror = tryFaceDetection; |
| 22 image.src = imageUrl; |
| 23 }); |
| 24 } |
| 25 |
| 26 // This test verifies that FaceDetector will reject a cross-origin-image. |
| 27 promise_test( |
| 28 function(t) { |
| 29 // Since security origin is under file://, images using http protocol |
| 30 // is considered of a different origin. |
| 31 return detectFaceAndExpectError( |
| 32 "http://localhost:8080/security/resources/abe.png") |
| 33 .then(function(error) { |
| 34 assert_equals(error.name, "SecurityError"); |
| 35 assert_equals(error.message, |
| 36 "Image source from a different origin."); |
| 37 }); |
| 38 }, |
| 39 "FaceDetector should reject cross-origin-images with SecurityError."); |
| 40 </script> |
OLD | NEW |