Commit 4b4c32b4 authored by Mark Pearson's avatar Mark Pearson Committed by Commit Bot

Revert "Reland: [shapedetection] Add some shapedetection tests"

This reverts commit 19f78e3e.

Reason for revert:

consistently fails (via timeout) on the Mac10.11 Tests bot
https://ci.chromium.org/p/chromium/builders/ci/Mac10.11%20Tests
even since it first landed on this run:
https://ci.chromium.org/p/chromium/builders/ci/Mac10.11%20Tests/40038

BUG=979170

Original change's description:
> 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}

TBR=reillyg@chromium.org,mcasas@chromium.org,wanming.lin@intel.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 979170
Change-Id: Ia07d24517436bf2e45086251cef82441bb966192
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1700387Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Commit-Queue: Mark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677084}
parent 1520e8e6
<!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>
\ No newline at end of file
...@@ -30,9 +30,9 @@ for (let crossOriginTest of crossOriginTests) { ...@@ -30,9 +30,9 @@ for (let crossOriginTest of crossOriginTests) {
img.src = IMAGE_URL; img.src = IMAGE_URL;
await imgWatcher.wait_for("load"); await imgWatcher.wait_for("load");
const detector = crossOriginTest.createDetector(); const detector = crossOriginTest.createDetector();
await promise_rejects(t, "SecurityError", detector.detect(img)); promise_rejects(t, "SecurityError", detector.detect(img));
}, `${crossOriginTest.detectorType} should reject cross-origin \ }, crossOriginTest.detectorType
HTMLImageElements with a SecurityError.`); + " should reject cross-origin HTMLImageElements with a SecurityError.");
// Verifies that Detector rejects a cross-origin ImageBitmap. // Verifies that Detector rejects a cross-origin ImageBitmap.
promise_test(async t => { promise_test(async t => {
...@@ -42,9 +42,9 @@ HTMLImageElements with a SecurityError.`); ...@@ -42,9 +42,9 @@ HTMLImageElements with a SecurityError.`);
await imgWatcher.wait_for("load"); await imgWatcher.wait_for("load");
const imgBitmap = await createImageBitmap(img); const imgBitmap = await createImageBitmap(img);
const detector = crossOriginTest.createDetector(); const detector = crossOriginTest.createDetector();
await promise_rejects(t, "SecurityError", detector.detect(imgBitmap)); promise_rejects(t, "SecurityError", detector.detect(imgBitmap));
}, `${crossOriginTest.detectorType} should reject cross-origin \ }, crossOriginTest.detectorType
ImageBitmaps with a SecurityError.`); + " should reject cross-origin ImageBitmaps with a SecurityError.");
// Verifies that Detector rejects a cross-origin HTMLVideoElement. // Verifies that Detector rejects a cross-origin HTMLVideoElement.
promise_test(async t => { promise_test(async t => {
...@@ -53,22 +53,9 @@ ImageBitmaps with a SecurityError.`); ...@@ -53,22 +53,9 @@ ImageBitmaps with a SecurityError.`);
video.src = VIDEO_URL; video.src = VIDEO_URL;
await videoWatcher.wait_for("loadeddata"); await videoWatcher.wait_for("loadeddata");
const detector = crossOriginTest.createDetector(); const detector = crossOriginTest.createDetector();
await promise_rejects(t, "SecurityError", detector.detect(video)); promise_rejects(t, "SecurityError", detector.detect(video));
}, `${crossOriginTest.detectorType} should reject cross-origin \ }, crossOriginTest.detectorType
HTMLVideoElements with a SecurityError.`); + " 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.`);
} }
......
<!DOCTYPE html>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script>
// 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 = new TextDetector();
await promise_rejects(t, 'InvalidStateError', detector.detect(video));
}, "Text - detect(HTMLVideoElement) - HAVE_NOTHING");
// Detector's detect() rejects on a HAVE_METADATA HTMLVideoElement.
promise_test(async t => {
const url = "/media/resources/media-source/webm/"
+ "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 = new TextDetector();
await promise_rejects(t, 'InvalidStateError', detector.detect(video));
}, "Text - detect(HTMLVideoElement) - HAVE_METADATA");
</script>
...@@ -7,51 +7,74 @@ ...@@ -7,51 +7,74 @@
const IMAGE_URL = "http://localhost:8080/security/resources/abe.png"; const IMAGE_URL = "http://localhost:8080/security/resources/abe.png";
const VIDEO_URL = "http://localhost:8080/external/wpt/media/white.webm"; const VIDEO_URL = "http://localhost:8080/external/wpt/media/white.webm";
// Returns a Promise that is resolve()d if detect() is rejected. Needs an input
// |element| (e.g. an HTMLImageElement or HTMLVideoElement) and a |url| to load.
function detectTextOnElementAndExpectError(element, url) {
return new Promise(function(resolve, reject) {
var tryTextDetection = function() {
var textDetector = new TextDetector();
textDetector.detect(element)
.then(textDetectionResult => {
reject("Promise should have been rejected.");
})
.catch(error => {
resolve(error);
});
};
element.onload = tryTextDetection;
element.onerror = tryTextDetection;
element.src = url;
});
}
function detectTextOnImageBitmapAndExpectError(imageUrl) {
return new Promise(function(resolve, reject) {
var image = new Image();
image.onload = function() {
createImageBitmap(image)
.then(imageBitmap => {
var textDetector = new TextDetector();
return textDetector.detect(imageBitmap);
})
.then(textDetectionResult => {
reject("Promise should have been rejected.");
})
.catch(error => {
resolve(error);
});
};
image.onerror = () => {}; // Explicitly ignore expected error events.
image.src = imageUrl;
});
}
// Verifies that TextDetector rejects a cross-origin HTMLImageElement. // Verifies that TextDetector rejects a cross-origin HTMLImageElement.
promise_test(async t => { promise_test(function(t) {
const img = new Image(); var image = new Image();
const imgWatcher = new EventWatcher(t, img, ["load", "error"]); return detectTextOnElementAndExpectError(image, IMAGE_URL)
img.src = IMAGE_URL; .then(error => {
await imgWatcher.wait_for("load"); assert_equals(error.name, "SecurityError");
const detector = new TextDetector(); });
await promise_rejects(t, "SecurityError", detector.detect(img));
}, },
"TextDetector should reject cross-origin HTMLImageElements with a SecurityError."); "TextDetector should reject cross-origin HTMLImageElements with a SecurityError.");
// Verifies that TextDetector rejects a cross-origin ImageBitmap. // Verifies that TextDetector rejects a cross-origin ImageBitmap.
promise_test(async t => { promise_test(function(t) {
const img = new Image(); return detectTextOnImageBitmapAndExpectError(IMAGE_URL)
const imgWatcher = new EventWatcher(t, img, ["load", "error"]); .then(error => {
img.src = IMAGE_URL; assert_equals(error.name, "SecurityError");
await imgWatcher.wait_for("load"); });
const imgBitmap = await createImageBitmap(img);
const detector = new TextDetector();
await promise_rejects(t, "SecurityError", detector.detect(imgBitmap));
}, },
"TextDetector should reject cross-origin ImageBitmaps with a SecurityError."); "TextDetector should reject cross-origin ImageBitmaps with a SecurityError.");
// Verifies that TextDetector rejects a cross-origin HTMLVideoElement. // Verifies that TextDetector rejects a cross-origin HTMLVideoElement.
promise_test(async t => { promise_test(function(t) {
const video = document.createElement('video'); var video = document.createElement('video');
const videoWatcher = new EventWatcher(t, video, ["load", "error"]); return detectTextOnElementAndExpectError(video, VIDEO_URL)
video.src = VIDEO_URL; .then(error => {
await videoWatcher.wait_for("error"); assert_equals(error.name, "SecurityError");
const detector = new TextDetector(); });
await promise_rejects(t, "SecurityError", detector.detect(video));
}, },
"TextDetector should reject cross-origin HTMLVideoElements with a SecurityError."); "TextDetector should reject cross-origin HTMLVideoElements with a SecurityError.");
// Verifies that TextDetector 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 = new TextDetector();
await promise_rejects(t, "SecurityError", detector.detect(canvas));
},
"TextDetector should reject cross-origin HTMLCanvasElements with a SecurityError.");
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment