fune/testing/web-platform/tests/shape-detection/detection-security-test.https.html
Wanming Lin 015541adbc Bug 1627268 [wpt PR 22690] - Reland: [shapedetection] Upstream TextDetection tests to WPT, a=testonly
Automatic update from web-platform-tests
Reland: [shapedetection] Upstream TextDetection tests to WPT

The original CL has been reverted because the test
external/wpt/shape-detection/idlharness.https.any.shareworker.html
is flaky on Mac. This reland CL disables this test on Mac.

Original change's description:
> [shapedetection] Upstream TextDetection tests to WPT
>
> This CL upstreams the reset of shapedetection tests(mainly
> TextDetection tests) to WPT.
>
> - Moves tests under
>   third_party/blink/web_tests/shapedetection/,
>   third_party/blink/web_tests/fast/shapedetection/,
>   third_party/blink/web_tests/http/tests/shapedetection/,
>   to third_party/blink/web_tests/external/wpt/shape-detection.
> - Moves third_party/blink/web_tests/shapedetection/resources/mock-textdetection.js
>   to third_party/blink/web_tests/external/wpt/resources/chromium/.
> - Removes third_party/blink/web_tests/fast/shapedetection/shapedetection-creation.html
>   as which should be covered in idlharness tests.
> - Introduces simulateClosedPipe() to MockBarcodeDetectionProvider to simulate
>   'no implementation available' case for
>   third_party/blink/web_tests/external/wpt/shape-detection/detection-getSupportedFormats.https.html
> - Improves third_party/blink/web_tests/external/wpt/shape-detection/detection-options.https.html
>   by using assert_throws_js BTW.
>
> Bug: 932382
> Change-Id: I2f795e4fa4f23b33c49b7924cdbcbccde5ac6ed4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131154
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Commit-Queue: Wanming Lin <wanming.lin@intel.com>
> Cr-Commit-Position: refs/heads/master@{#756131}

Bug: 932382, 1067533
Change-Id: I85b5dcc841185e2edd20a76ed3aec8add7f08954
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134924
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Cr-Commit-Position: refs/heads/master@{#756647}

--

wpt-commits: dfc0080d132ac25c4cf824a25735203b3a2b6853
wpt-pr: 22690
2020-04-13 14:08:06 +00:00

82 lines
2.6 KiB
HTML

<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/shapedetection-helpers.js"></script>
<script>
// Detectors should reject undecodable images with an InvalidStateError.
const badImageTests =
[
{
createDetector: () => { return new FaceDetector(); },
name: "Face - detect(broken image)"
},
{
createDetector: () => { return new BarcodeDetector(); },
name: "Barcode - detect(broken image)"
},
{
createDetector: () => { return new TextDetector(); },
name: "Text - detect(broken image)"
}
];
for (let badImageTest of badImageTests) {
// This test verifies that a Detector will reject an undecodable image.
promise_test(async t => {
const img = new Image();
const error =
await detectOnElementAndExpectError(badImageTest.createDetector,
img, "/images/broken.png");
assert_equals(error.name, "InvalidStateError");
}, badImageTest.name);
}
// Detectors should reject undecodable videos with an InvalidStateError.
const badVideoTests =
[
{
createDetector: () => { return new FaceDetector(); },
name: "Face - detect(broken video)"
},
{
createDetector: () => { return new BarcodeDetector(); },
name: "Barcode - detect(broken video)"
},
{
createDetector: () => { return new TextDetector(); },
name: "Text - detect(broken video)"
}
];
for (let badVideoTest of badVideoTests) {
// This test verifies that a Detector will reject a broken video.
promise_test(async t => {
const video = document.createElement('video');
const error =
await detectOnElementAndExpectError(badVideoTest.createDetector,
video, "garbage.webm");
assert_equals(error.name, "InvalidStateError");
}, badVideoTest.name);
}
// 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 detectOnElementAndExpectError(createDetector, element, url) {
return new Promise((resolve, reject) => {
const tryDetection = async () => {
const detector = createDetector();
try {
const detectionResult = await detector.detect(element);
reject("Promise should have been rejected.");
} catch (error) {
resolve(error);
}
};
element.onload = tryDetection;
element.onerror = tryDetection;
element.src = url;
});
};
</script>