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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/shapedetection/shapedetection-cross-origin.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/shapedetection/shapedetection-cross-origin.html b/third_party/WebKit/LayoutTests/http/tests/shapedetection/shapedetection-cross-origin.html
index 9f330c9bb9b20a76d272fbc45a13488b8746621a..94561f12e248deb80482d4a693bf8cda21a54768 100644
--- a/third_party/WebKit/LayoutTests/http/tests/shapedetection/shapedetection-cross-origin.html
+++ b/third_party/WebKit/LayoutTests/http/tests/shapedetection/shapedetection-cross-origin.html
@@ -3,38 +3,66 @@
<script src=../../../../resources/testharnessreport.js></script>
<script>
+// http:// resources are considered cross-origin from the current file://.
+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.
+
// TODO(xianglu): Move this helper function to a shared location for reuse.
-function detectFaceAndExpectError(imageUrl) {
+function detectFaceOnImageElementAndExpectError(imageUrl) {
return new Promise(function(resolve, reject) {
var image = new Image();
- var faceDetector = new FaceDetector();
- var tryFaceDetection = function() {
+ image.onload = function() {
+ var faceDetector = new FaceDetector();
faceDetector.detect(image)
.then(faceDetectionResult => {
- reject("Promise for this test image should have been rejected.");
+ reject("Promise should have been rejected.");
})
.catch(error => {
resolve(error);
});
};
- image.onload = tryFaceDetection;
- image.onerror = tryFaceDetection;
+ 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.
image.src = imageUrl;
});
}
-// This test verifies that FaceDetector will reject a cross-origin-image.
-promise_test(
- function(t) {
- // Since security origin is under file://, images using http protocol
- // is considered of a different origin.
- return detectFaceAndExpectError(
- "http://localhost:8080/security/resources/abe.png")
- .then(function(error) {
- assert_equals(error.name, "SecurityError");
- assert_equals(error.message,
- "Image source from a different origin.");
+function detectFaceOnImageBitmapAndExpectError(imageUrl) {
+ return new Promise(function(resolve, reject) {
+ var image = new Image();
+ image.onload = function() {
+ createImageBitmap(image)
+ .then(imageBitmap => {
+ var faceDetector = new FaceDetector();
+ return faceDetector.detect(imageBitmap);
+ })
+ .then(faceDetectionResult => {
+ reject("Promise should have been rejected.");
+ })
+ .catch(error => {
+ resolve(error);
});
- },
- "FaceDetector should reject cross-origin-images with SecurityError.");
+ };
+ image.onerror = () => {}; // Explicitly ignore expected error events.
+ image.src = imageUrl;
+ });
+}
+
+// Verifies that FaceDetector rejects a cross-origin HTMLImageElement.
+promise_test(function(t) {
+ return detectFaceOnImageElementAndExpectError(imageUrl)
+ .then(error => {
+ assert_equals(error.name, "SecurityError");
+ assert_equals(error.message, "Image source from a different origin.");
+ });
+},
+"FaceDetector should reject cross-origin HTMLImageElements with a SecurityError.");
+
+// Verifies that FaceDetector rejects a cross-origin ImageBitmap.
+promise_test(function(t) {
+ return detectFaceOnImageBitmapAndExpectError(imageUrl)
+ .then(error => {
+ assert_equals(error.name, "SecurityError");
+ });
+},
+"FaceDetector should reject cross-origin ImageBitmaps with a SecurityError.");
+
</script>

Powered by Google App Engine
This is Rietveld 408576698