detection-ImageBitmap.https.html (2687B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/shapedetection-helpers.js"></script> 5 <script> 6 7 // These tests verify that a Detector's detect() works on an ImageBitmap. 8 const imageBitmapTests = 9 [ 10 { 11 createDetector: () => { return new FaceDetector(); }, 12 mockTestName: "FaceDetectionTest", 13 detectionResultTest: FaceDetectorDetectionResultTest, 14 name: "Face - detect(ImageBitmap)" 15 }, 16 { 17 createDetector: () => { return new BarcodeDetector(); }, 18 mockTestName: "BarcodeDetectionTest", 19 detectionResultTest: BarcodeDetectorDetectionResultTest, 20 name: "Barcode - detect(ImageBitmap)" 21 }, 22 { 23 createDetector: () => { return new TextDetector(); }, 24 mockTestName: "TextDetectionTest", 25 detectionResultTest: TextDetectorDetectionResultTest, 26 name: "Text - detect(ImageBitmap)", 27 } 28 ]; 29 30 for (let imageBitmapTest of imageBitmapTests) { 31 detection_test(imageBitmapTest.mockTestName, async (t, detectionTest) => { 32 const img = new Image(); 33 const imgWatcher = new EventWatcher(t, img, ["load", "error"]); 34 img.src = "/images/green-16x16.png"; 35 await imgWatcher.wait_for("load"); 36 const imageBitmap = await createImageBitmap(img); 37 38 const detector = imageBitmapTest.createDetector(); 39 const detectionResult = await detector.detect(imageBitmap); 40 imageBitmapTest.detectionResultTest(detectionResult, detectionTest); 41 }, imageBitmapTest.name); 42 } 43 44 function FaceDetectorDetectionResultTest(detectionResult, mockTest) { 45 const imageReceivedByMock = mockTest.MockFaceDetectionProvider().getFrameData(); 46 assert_equals(imageReceivedByMock.byteLength, 1024, "Image length"); 47 const GREEN_PIXEL = 0xFF00FF00; 48 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color"); 49 assert_equals(detectionResult.length, 3, "Number of faces"); 50 } 51 52 function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) { 53 assert_equals(detectionResult.length, 2, "Number of barcodes"); 54 assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); 55 assert_equals(detectionResult[0].format, "qr_code", "barcode 1 format"); 56 assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); 57 assert_equals(detectionResult[1].format, "code_128", "barcode 2 format"); 58 } 59 60 function TextDetectorDetectionResultTest(detectionResult, mockTest) { 61 assert_equals(detectionResult.length, 2, "Number of textBlocks"); 62 assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1"); 63 assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2"); 64 } 65 66 </script>