detection-options.https.html (1976B)
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 <body> 6 <img id="img" src="/images/green-16x16.png"/> 7 </body> 8 <script> 9 10 detection_test("FaceDetectionTest", async (t, detectionTest) => { 11 const img = document.getElementById("img"); 12 const mock = detectionTest.MockFaceDetectionProvider(); 13 14 const detectorWithDefault = new FaceDetector(); 15 let faceDetectionResult = await detectorWithDefault.detect(img); 16 assert_equals(mock.getMaxDetectedFaces(), 10, "default maxDetectedFaces"); 17 assert_equals(mock.getFastMode(), false, "default maxDetectedFaces"); 18 19 const detectorWithOptions = 20 new FaceDetector({maxDetectedFaces: 7, fastMode: true}); 21 faceDetectionResult = await detectorWithOptions.detect(img); 22 assert_equals(mock.getMaxDetectedFaces(), 7, "maxDetectedFaces"); 23 assert_equals(mock.getFastMode(), true, "maxDetectedFaces"); 24 }, "Test that FaceDetectionOptions are correctly propagated"); 25 26 detection_test("BarcodeDetectionTest", async (t, detectionTest) => { 27 const img = document.getElementById("img"); 28 const mock = detectionTest.MockBarcodeDetectionProvider(); 29 30 const detectorWithNoOptions = new BarcodeDetector(); 31 let barcodeDetectionResult = await detectorWithNoOptions.detect(img); 32 assert_array_equals(mock.getFormats(), [], "formats"); 33 34 const detectorWithOptions = new BarcodeDetector({ 35 formats: ["code_128", "qr_code"]}); 36 barcodeDetectionResult = await detectorWithOptions.detect(img); 37 assert_array_equals( 38 mock.getFormats(), 39 [BarcodeFormat.CODE_128, BarcodeFormat.QR_CODE], 40 "formats"); 41 42 const invalidFormats = [ 43 [], 44 ["unknown"], 45 ["foo", "bar"] 46 ]; 47 48 invalidFormats.forEach(invalidFormat => { 49 assert_throws_js(TypeError, () => new BarcodeDetector({formats: invalidFormat})); 50 }); 51 52 }, "Test that BarcodeDetectorOptions are correctly propagated"); 53 54 </script>