fune/testing/web-platform/tests/shape-detection/detection-HTMLCanvasElement.https.html
danakj effabd1b76 Bug 1682628 [wpt PR 26909] - Reland "Use skia.mojom.BitmapN32 in Detection mojoms", a=testonly
Automatic update from web-platform-tests
Reland "Use skia.mojom.BitmapN32 in Detection mojoms"

This is a reland of c7326b7f5dd47cddf6ff99d98fd1b7be1f54f922

Canvases may have different color formats than N32, and when we pull
the content of them into a cpu bitmap through SkImage::toLegacyBitmap()
we need to convert that to N32 format if we're going to send the bitmap
over IPC due to security restrictions of the BitmapN32 mojom type.

This does that conversion in the blink ShapeDetector and adds a test with
a float16 color format canvas which would cause the IPC sending to be
dropped (and the renderer to crash).

TBR=dcheng

Original change's description:
> Use skia.mojom.BitmapN32 in Detection mojoms
>
> These bitmaps are safer for transport from untrustworthy sources since
> all bitmaps should be in N32 format and the browser can make bad
> assumptions as a result.
>
> R=dcheng@chromium.org, reillyg@chromium.org
>
> Bug: 1144462
> Change-Id: I7d02cb187c62be37259f445a182f8c971aa03661
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580483
> Commit-Queue: danakj <danakj@chromium.org>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#835685}

Bug: 1144462
Change-Id: I23ef3df85049a7111830c5d272c02b69f9d7cd38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593827
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837241}

--

wpt-commits: ed3c1d0b0fbeacb78cab1103e71cbed3d7d389fd
wpt-pr: 26909
2020-12-21 14:59:48 +00:00

125 lines
5.1 KiB
HTML

<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/shapedetection-helpers.js"></script>
<script>
// These tests verify that a Detector's detect() works on an HTMLCanvasElement
// and on an OffscreenCanvas.
const canvasElementTests =
[
{
createDetector: () => { return new FaceDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
pixelFormat: "uint8",
mockTestName: "FaceDetectionTest",
detectionResultTest: FaceDetectorDetectionResultTest,
name: "Face - detect(HTMLCanvasElement)"
},
{
createDetector: () => { return new FaceDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
pixelFormat: "float16",
mockTestName: "FaceDetectionTest",
detectionResultTest: FaceDetectorDetectionResultTest,
name: "Face - detect(HTMLCanvasElementF16Format)"
},
{
createDetector: () => { return new FaceDetector(); },
createCanvas: () => { return new OffscreenCanvas(300, 150); },
pixelFormat: "uint8",
mockTestName: "FaceDetectionTest",
detectionResultTest: FaceDetectorDetectionResultTest,
name: "Face - detect(OffscreenCanvas)"
},
{
createDetector: () => { return new BarcodeDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
pixelFormat: "uint8",
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(HTMLCanvasElement)"
},
{
createDetector: () => { return new BarcodeDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
pixelFormat: "float16",
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(HTMLCanvasElementF16Format)"
},
{
createDetector: () => { return new BarcodeDetector(); },
createCanvas: () => { return new OffscreenCanvas(300, 150); },
pixelFormat: "uint8",
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(OffscreenCanvas)"
},
{
createDetector: () => { return new TextDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
pixelFormat: "uint8",
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(HTMLCanvasElement)"
},
{
createDetector: () => { return new TextDetector(); },
createCanvas: () => { return document.createElement("canvas"); },
pixelFormat: "float16",
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(HTMLCanvasElementF16Format)"
},
{
createDetector: () => { return new TextDetector(); },
createCanvas: () => { return new OffscreenCanvas(300, 150); },
pixelFormat: "uint8",
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(OffscreenCanvas)"
}
];
for (let canvasElementTest of canvasElementTests) {
detection_test(canvasElementTest.mockTestName, async (t, detectionTest) => {
const img = new Image();
const imgWatcher = new EventWatcher(t, img, ["load", "error"]);
img.src = "/images/green-16x16.png";
await imgWatcher.wait_for("load");
const canvas = canvasElementTest.createCanvas();
canvas.getContext(
"2d", { pixelFormat: canvasElementTest.pixelFormat }).drawImage(
img, 0, 0);
const detector = canvasElementTest.createDetector();
const detectionResult = await detector.detect(canvas);
canvasElementTest.detectionResultTest(detectionResult, detectionTest);
}, canvasElementTest.name);
}
function FaceDetectorDetectionResultTest(detectionResult, mockTest) {
const imageReceivedByMock =
mockTest.MockFaceDetectionProvider().getFrameData();
assert_equals(imageReceivedByMock.byteLength, 180000, "Image length");
const GREEN_PIXEL = 0xFF00FF00;
assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color");
assert_equals(detectionResult.length, 3, "Number of faces");
}
function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of barcodes");
assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
assert_equals(detectionResult[0].format, "qr_code", "barcode 1 format");
assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
}
function TextDetectorDetectionResultTest(detectionResult, mockTest) {
assert_equals(detectionResult.length, 2, "Number of textBlocks");
assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1");
assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2");
}
</script>