From 5523f4f2804ce657a67b5186705edcf49845bcac Mon Sep 17 00:00:00 2001 From: Wanming Lin Date: Mon, 22 Jul 2019 11:07:32 +0000 Subject: [PATCH] Bug 1566105 [wpt PR 17636] - Reland: [shapedetection] Add some shapedetection tests, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests Reland: [shapedetection] Add some shapedetection tests The original CL has been reverted because the test external/wpt/shape-detection/detection-HTMLVideoElement-invalid-state.html is flaky. In the previous CL, the way to create a HTMLVideoElement with 'HAVE_METADATA' state is wrong, because simply loading a video file its readyState should be >= HAVE_METADATA during loadedmetadata event. Which is the reason of the flaky. This reland CL leverages MediaSource API to precisely trigger a transition to HAVE_METADATA state by invoking `appendBuffer()` with an initialization segment. See relevant spec: https://w3c.github.io/media-source/#sourcebuffer-init-segment-received Original change's description: > [shapedetection] Add some shapedetection tests > > Cover following two checkpoints: > - If the ImageBitmapSource is an HTMLVideoElement object whose readyState attribute > is either HAVE_NOTHING or HAVE_METADATA then reject the Promise with a new > DOMException whose name is InvalidStateError. > - If the ImageBitmapSource argument is an HTMLCanvasElement whose bitmap’s origin-clean > flag is false, then reject the Promise with a new DOMException whose name is SecurityError. > > spec: https://wicg.github.io/shape-detection-api/#image-sources-for-detection > Change-Id: I0522d0340d3cb0291df6be65dfc1ab99037b30f7 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1666766 > Reviewed-by: Reilly Grant > Commit-Queue: Wanming Lin > Cr-Commit-Position: refs/heads/master@{#671578} Bug: 979170 Change-Id: I963c3b6bce86791f5bedde7849c2e439b28c5481 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1688460 Reviewed-by: Reilly Grant Commit-Queue: Wanming Lin Cr-Commit-Position: refs/heads/master@{#675956} -- wpt-commits: cba61ec81f44eab31fa68d2ae9f87aef1144c190 wpt-pr: 17636 --- ...ection-HTMLVideoElement-invalid-state.html | 70 +++++++++++++++++++ .../shapedetection-cross-origin.sub.html | 31 +++++--- 2 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 testing/web-platform/tests/shape-detection/detection-HTMLVideoElement-invalid-state.html diff --git a/testing/web-platform/tests/shape-detection/detection-HTMLVideoElement-invalid-state.html b/testing/web-platform/tests/shape-detection/detection-HTMLVideoElement-invalid-state.html new file mode 100644 index 000000000000..dcf9e3af8552 --- /dev/null +++ b/testing/web-platform/tests/shape-detection/detection-HTMLVideoElement-invalid-state.html @@ -0,0 +1,70 @@ + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/shape-detection/shapedetection-cross-origin.sub.html b/testing/web-platform/tests/shape-detection/shapedetection-cross-origin.sub.html index c9d86430356d..f45369266973 100644 --- a/testing/web-platform/tests/shape-detection/shapedetection-cross-origin.sub.html +++ b/testing/web-platform/tests/shape-detection/shapedetection-cross-origin.sub.html @@ -30,9 +30,9 @@ for (let crossOriginTest of crossOriginTests) { img.src = IMAGE_URL; await imgWatcher.wait_for("load"); const detector = crossOriginTest.createDetector(); - promise_rejects(t, "SecurityError", detector.detect(img)); - }, crossOriginTest.detectorType - + " should reject cross-origin HTMLImageElements with a SecurityError."); + await promise_rejects(t, "SecurityError", detector.detect(img)); + }, `${crossOriginTest.detectorType} should reject cross-origin \ +HTMLImageElements with a SecurityError.`); // Verifies that Detector rejects a cross-origin ImageBitmap. promise_test(async t => { @@ -42,9 +42,9 @@ for (let crossOriginTest of crossOriginTests) { await imgWatcher.wait_for("load"); const imgBitmap = await createImageBitmap(img); const detector = crossOriginTest.createDetector(); - promise_rejects(t, "SecurityError", detector.detect(imgBitmap)); - }, crossOriginTest.detectorType - + " should reject cross-origin ImageBitmaps with a SecurityError."); + await promise_rejects(t, "SecurityError", detector.detect(imgBitmap)); + }, `${crossOriginTest.detectorType} should reject cross-origin \ +ImageBitmaps with a SecurityError.`); // Verifies that Detector rejects a cross-origin HTMLVideoElement. promise_test(async t => { @@ -53,9 +53,22 @@ for (let crossOriginTest of crossOriginTests) { video.src = VIDEO_URL; await videoWatcher.wait_for("loadeddata"); const detector = crossOriginTest.createDetector(); - promise_rejects(t, "SecurityError", detector.detect(video)); - }, crossOriginTest.detectorType - + " should reject cross-origin HTMLVideoElements with a SecurityError."); + await promise_rejects(t, "SecurityError", detector.detect(video)); + }, `${crossOriginTest.detectorType} should reject cross-origin \ +HTMLVideoElements with a SecurityError.`); + + // Verifies that Detector rejects a cross-origin HTMLCanvasElement. + promise_test(async t => { + const img = new Image(); + const imgWatcher = new EventWatcher(t, img, ["load", "error"]); + img.src = IMAGE_URL; + await imgWatcher.wait_for("load"); + const canvas = document.createElement("canvas"); + canvas.getContext("2d").drawImage(img, 0, 0); + const detector = crossOriginTest.createDetector(); + await promise_rejects(t, "SecurityError", detector.detect(canvas)); + }, `${crossOriginTest.detectorType} should reject cross-origin \ +HTMLCanvasElement with a SecurityError.`); }