Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 3 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /shape-detection/detection-ImageBitmap.https.html - WPT Dashboard Interop Dashboard
<!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 ImageBitmap.
const imageBitmapTests =
[
{
createDetector: () => { return new FaceDetector(); },
mockTestName: "FaceDetectionTest",
detectionResultTest: FaceDetectorDetectionResultTest,
name: "Face - detect(ImageBitmap)"
},
{
createDetector: () => { return new BarcodeDetector(); },
mockTestName: "BarcodeDetectionTest",
detectionResultTest: BarcodeDetectorDetectionResultTest,
name: "Barcode - detect(ImageBitmap)"
},
{
createDetector: () => { return new TextDetector(); },
mockTestName: "TextDetectionTest",
detectionResultTest: TextDetectorDetectionResultTest,
name: "Text - detect(ImageBitmap)",
}
];
for (let imageBitmapTest of imageBitmapTests) {
detection_test(imageBitmapTest.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 imageBitmap = await createImageBitmap(img);
const detector = imageBitmapTest.createDetector();
const detectionResult = await detector.detect(imageBitmap);
imageBitmapTest.detectionResultTest(detectionResult, detectionTest);
}, imageBitmapTest.name);
}
function FaceDetectorDetectionResultTest(detectionResult, mockTest) {
const imageReceivedByMock = mockTest.MockFaceDetectionProvider().getFrameData();
assert_equals(imageReceivedByMock.byteLength, 1024, "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>