Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/shapedetection/shapedetection-cross-origin.html

Issue 2448193002: ShapeDetection: support CanvasImageSource as detect() source (Closed)
Patch Set: esprehn@ comments and specific LayoutTest for empty HTMLImageElement Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src=../../../../resources/testharness.js></script> 2 <script src=../../../../resources/testharness.js></script>
3 <script src=../../../../resources/testharnessreport.js></script> 3 <script src=../../../../resources/testharnessreport.js></script>
4 <script> 4 <script>
5 5
6 // http:// resources are considered cross-origin from the current file://.
7 const IMAGE_URL = "http://localhost:8080/security/resources/abe.png";
8
6 // TODO(xianglu): Move this helper function to a shared location for reuse. 9 // TODO(xianglu): Move this helper function to a shared location for reuse.
7 function detectFaceAndExpectError(imageUrl) { 10 function detectFaceOnImageElementAndExpectError(imageUrl) {
8 return new Promise(function(resolve, reject) { 11 return new Promise(function(resolve, reject) {
9 var image = new Image(); 12 var image = new Image();
10 var faceDetector = new FaceDetector();
11 var tryFaceDetection = function() { 13 var tryFaceDetection = function() {
14 var faceDetector = new FaceDetector();
12 faceDetector.detect(image) 15 faceDetector.detect(image)
13 .then(faceDetectionResult => { 16 .then(faceDetectionResult => {
14 reject("Promise for this test image should have been rejected."); 17 reject("Promise should have been rejected.");
15 }) 18 })
16 .catch(error => { 19 .catch(error => {
17 resolve(error); 20 resolve(error);
18 }); 21 });
19 }; 22 };
20 image.onload = tryFaceDetection; 23 image.onload = tryFaceDetection;
21 image.onerror = tryFaceDetection; 24 image.onerror = tryFaceDetection;
22 image.src = imageUrl; 25 image.src = imageUrl;
23 }); 26 });
24 } 27 }
25 28
26 // This test verifies that FaceDetector will reject a cross-origin-image. 29 function detectFaceOnImageBitmapAndExpectError(imageUrl) {
27 promise_test( 30 return new Promise(function(resolve, reject) {
28 function(t) { 31 var image = new Image();
29 // Since security origin is under file://, images using http protocol 32 image.onload = function() {
30 // is considered of a different origin. 33 createImageBitmap(image)
31 return detectFaceAndExpectError( 34 .then(imageBitmap => {
32 "http://localhost:8080/security/resources/abe.png") 35 var faceDetector = new FaceDetector();
33 .then(function(error) { 36 return faceDetector.detect(imageBitmap);
34 assert_equals(error.name, "SecurityError"); 37 })
35 assert_equals(error.message, 38 .then(faceDetectionResult => {
36 "Image source from a different origin."); 39 reject("Promise should have been rejected.");
40 })
41 .catch(error => {
42 resolve(error);
37 }); 43 });
38 }, 44 };
39 "FaceDetector should reject cross-origin-images with SecurityError."); 45 image.onerror = () => {}; // Explicitly ignore expected error events.
46 image.src = imageUrl;
47 });
48 }
49
50 // Verifies that FaceDetector rejects a cross-origin HTMLImageElement.
51 promise_test(function(t) {
52 return detectFaceOnImageElementAndExpectError(IMAGE_URL)
53 .then(error => {
54 assert_equals(error.name, "SecurityError");
55 });
56 },
57 "FaceDetector should reject cross-origin HTMLImageElements with a SecurityError. ");
58
59 // Verifies that FaceDetector rejects a cross-origin ImageBitmap.
60 promise_test(function(t) {
61 return detectFaceOnImageBitmapAndExpectError(IMAGE_URL)
62 .then(error => {
63 assert_equals(error.name, "SecurityError");
64 });
65 },
66 "FaceDetector should reject cross-origin ImageBitmaps with a SecurityError.");
67
40 </script> 68 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698