Bug 1566105 [wpt PR 17636] - Reland: [shapedetection] Add some shapedetection tests, a=testonly

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 <reillyg@chromium.org>
> Commit-Queue: Wanming Lin <wanming.lin@intel.com>
> 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 <reillyg@chromium.org>
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Cr-Commit-Position: refs/heads/master@{#675956}

--

wpt-commits: cba61ec81f44eab31fa68d2ae9f87aef1144c190
wpt-pr: 17636
This commit is contained in:
Wanming Lin 2019-07-22 11:07:32 +00:00 коммит произвёл James Graham
Родитель 397864ff1d
Коммит 5523f4f280
2 изменённых файлов: 92 добавлений и 9 удалений

Просмотреть файл

@ -0,0 +1,70 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const videoElementTests =
[
{
createDetector: () => { return new FaceDetector(); },
name: "Face - detect(HTMLVideoElement)",
},
{
createDetector: () => { return new BarcodeDetector(); },
name: "Barcode - detect(HTMLVideoElement)",
}
];
for (let videoElementTest of videoElementTests) {
// Detector's detect() rejects on a HAVE_NOTHING HTMLVideoElement.
promise_test(async t => {
const video = document.createElement("video");
video.src = "";
const videoWatcher = new EventWatcher(t, video, ["play", "error"]);
video.load();
await videoWatcher.wait_for("error");
assert_equals(video.readyState, video.HAVE_NOTHING);
const detector = videoElementTest.createDetector();
await promise_rejects(t, 'InvalidStateError', detector.detect(video));
}, `${videoElementTest.name} - HAVE_NOTHING`);
// Detector's detect() rejects on a HAVE_METADATA HTMLVideoElement.
promise_test(async t => {
const url = '/media/test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm';
const type = 'video/webm; codecs="vp8, vorbis"';
const video = document.createElement("video");
document.body.appendChild(video);
t.add_cleanup(() => { document.body.removeChild(video); });
// Attach MediaSource to the video element.
const mediaSource = new MediaSource();
const mediaSourceURL = URL.createObjectURL(mediaSource);
const mediaSourceWatcher =
new EventWatcher(t, mediaSource, ["sourceopen", "error"]);
video.src = mediaSourceURL;
await mediaSourceWatcher.wait_for("sourceopen");
const sourceBuffer = mediaSource.addSourceBuffer(type);
// Load media data from the video file to create an initialization segment.
const response = await fetch(url);
const mediaData = await response.arrayBuffer();
const initSegment = new Uint8Array(mediaData, 0, 4052);
// Append the initialization segment to trigger a transition
// to HAVE_METADATA.
const videoWatcher =
new EventWatcher(t, video, ["loadedmetadata", "error"]);
sourceBuffer.appendBuffer(initSegment);
await videoWatcher.wait_for("loadedmetadata");
assert_equals(video.readyState, video.HAVE_METADATA);
const detector = videoElementTest.createDetector();
await promise_rejects(t, 'InvalidStateError', detector.detect(video));
}, `${videoElementTest.name} - HAVE_METADATA`);
}
</script>

Просмотреть файл

@ -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.`);
}