diff --git a/shape-detection/detection-options.html b/shape-detection/detection-options.html index 31475575e3f42e..704faf729294d7 100644 --- a/shape-detection/detection-options.html +++ b/shape-detection/detection-options.html @@ -23,4 +23,44 @@ assert_equals(mock.getFastMode(), true, "maxDetectedFaces"); }, "Test that FaceDetectionOptions are correctly propagated"); +detection_test("BarcodeDetectionTest", async (t, detectionTest) => { + const img = document.getElementById("img"); + const mock = detectionTest.MockBarcodeDetectionProvider(); + + const detectorWithNoOptions = new BarcodeDetector(); + let barcodeDetectionResult = await detectorWithNoOptions.detect(img); + assert_array_equals(mock.getFormats(), [], "formats"); + + const detectorWithOptions = new BarcodeDetector({ + formats: ["code_128", "qr_code"]}); + barcodeDetectionResult = await detectorWithOptions.detect(img); + assert_array_equals( + mock.getFormats(), + [shapeDetection.mojom.BarcodeFormat.CODE_128, + shapeDetection.mojom.BarcodeFormat.QR_CODE], + "formats"); + + try { + new BarcodeDetector({formats: []}); + assert_unreached("providing hint option that is empty should fail"); + } catch (error) { + assert_equals(error.name, "TypeError"); + } + + try { + new BarcodeDetector({formats: ["unknown"]}); + assert_unreached("providing \"unknown\" as a hint option should fail"); + } catch (error) { + assert_equals(error.name, "TypeError"); + } + + try { + new BarcodeDetector({formats: ["foo", "bar"]}); + assert_unreached( + "providing hint option with unrecognized formats should fail"); + } catch (error) { + assert_equals(error.name, "TypeError"); + } +}, "Test that BarcodeDetectorOptions are correctly propagated"); +