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

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: 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 imageUrl = "http://localhost:8080/security/resources/abe.png";
xianglu 2016/10/25 21:07:45 IMAGE_URL? Not sure if this is the right style gui
mcasas 2016/10/25 21:47:38 Done.
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(); 13 image.onload = function() {
11 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.onerror = () => {}; // Explicitly ignore expected error events.
xianglu 2016/10/25 21:07:45 It is possible that other security checks might fa
mcasas 2016/10/25 21:47:38 Done.
21 image.onerror = tryFaceDetection;
22 image.src = imageUrl; 24 image.src = imageUrl;
23 }); 25 });
24 } 26 }
25 27
26 // This test verifies that FaceDetector will reject a cross-origin-image. 28 function detectFaceOnImageBitmapAndExpectError(imageUrl) {
27 promise_test( 29 return new Promise(function(resolve, reject) {
28 function(t) { 30 var image = new Image();
29 // Since security origin is under file://, images using http protocol 31 image.onload = function() {
30 // is considered of a different origin. 32 createImageBitmap(image)
31 return detectFaceAndExpectError( 33 .then(imageBitmap => {
32 "http://localhost:8080/security/resources/abe.png") 34 var faceDetector = new FaceDetector();
33 .then(function(error) { 35 return faceDetector.detect(imageBitmap);
34 assert_equals(error.name, "SecurityError"); 36 })
35 assert_equals(error.message, 37 .then(faceDetectionResult => {
36 "Image source from a different origin."); 38 reject("Promise should have been rejected.");
39 })
40 .catch(error => {
41 resolve(error);
37 }); 42 });
38 }, 43 };
39 "FaceDetector should reject cross-origin-images with SecurityError."); 44 image.onerror = () => {}; // Explicitly ignore expected error events.
45 image.src = imageUrl;
46 });
47 }
48
49 // Verifies that FaceDetector rejects a cross-origin HTMLImageElement.
50 promise_test(function(t) {
51 return detectFaceOnImageElementAndExpectError(imageUrl)
52 .then(error => {
53 assert_equals(error.name, "SecurityError");
54 assert_equals(error.message, "Image source from a different origin.");
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(imageUrl)
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