From b87f8fafd492f92a75e9e49d421d78d3cd4b7e97 Mon Sep 17 00:00:00 2001 From: Jao-ke Chin-Lee Date: Tue, 2 Apr 2019 15:04:24 -0700 Subject: [PATCH] Barcode Detection Mac: Accept barcode format hint in detector constructor. A user may specify barcode formats from the spec to which to restrict detection, which are converted internally to all known related variants. For Mac, this is done by setting the "symbologies" property of a Vision API request. Change-Id: Ia12d250f9a753187c47c85b0fbc0765840e865ab Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1530190 Commit-Queue: Jao-ke Chin-Lee Reviewed-by: Reilly Grant Reviewed-by: Daniel Cheng Auto-Submit: Jao-ke Chin-Lee Cr-Commit-Position: refs/heads/master@{#646978} --- shape-detection/detection-options.html | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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"); +