Skip to content

Commit

Permalink
[shapedetection] Add some shapedetection tests
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Honry authored and chromium-wpt-export-bot committed Jun 24, 2019
1 parent 3cb5a99 commit ec977de
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
50 changes: 50 additions & 0 deletions shape-detection/detection-HTMLVideoElement-invalid-state.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!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 video = document.createElement("video");
video.src = "/media/white.webm";
video.loop = true;
video.autoplay = true;
const videoWatcher = new EventWatcher(t, video, ["loadedmetadata", "error"]);
video.load();
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>
31 changes: 22 additions & 9 deletions shape-detection/shapedetection-cross-origin.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
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 => {
Expand All @@ -42,9 +42,9 @@
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 => {
Expand All @@ -53,9 +53,22 @@
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.`);

}

Expand Down

0 comments on commit ec977de

Please sign in to comment.