Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barcode Detection Mac: Accept barcode format hint in detector constructor. #15993

Merged
merged 1 commit into from Apr 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions shape-detection/detection-options.html
Expand Up @@ -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");

</script>