mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 06:08:24 +02:00
Automatic update from web-platform-tests Upstream shapedetection tests to WPT Moved shapedetection tests under third_party/blink/web_tests/shapedetection/, third_party/blink/web_tests/fast/shapedetection/, third_party/blink/web_tests/http/tests/shapedetection/, to third_party/blink/web_tests/external/wpt/shape-detection/, excludes the Text detection part as which is still a sister informative specification of Shape Detection. Copyed third_party/blink/web_tests/shapedetection/resources/big-buffer-helpers.js to wpt/shape-detection/resources/shapedetection-helpers.js and extended it by adding a wrapper promise test, detection_test. Moved third_party/blink/web_tests/shapedetection/resources/mock-barcodedetection.js and third_party/blink/web_tests/shapedetection/resources/mock-facedetection.js to wpt/resources/chromium/ Used the testharness from wpt/ and rewrited tests to remove use of generate_tests as which is discouraged in wpt. Rewrite detection-on-worker.html as detection-on-worker.worker.js by using wpt preferred worker test framework. Rename detection-support.html as detection-getSupportedFormats.html as *-support.html is treated as support file rather than test file in wpt. No new tests have been added. BUG=932382 Change-Id: I321e7b9f986f407b83325bb4c6bdc366c9769264 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1510754 Commit-Queue: Wanming Lin <wanming.lin@intel.com> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/master@{#641504} -- wpt-commits: 7183ea12000b9edaac650b1211c35aa6e0abba88 wpt-pr: 15761
65 lines
2.7 KiB
HTML
65 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="resources/shapedetection-helpers.js"></script>
|
|
<body>
|
|
<img id="img" src="/images/green-16x16.png"/>
|
|
</body>
|
|
<script>
|
|
|
|
// These tests verify that a Detector's detect() works on an HTMLImageElement.
|
|
const imageElementTests =
|
|
[
|
|
{
|
|
createDetector: () => { return new FaceDetector(); },
|
|
mockTestName: "FaceDetectionTest",
|
|
detectionResultTest: FaceDetectorDetectionResultTest,
|
|
name: "Face - detect(HTMLImageElement)"
|
|
},
|
|
{
|
|
createDetector: () => { return new BarcodeDetector(); },
|
|
mockTestName: "BarcodeDetectionTest",
|
|
detectionResultTest: BarcodeDetectorDetectionResultTest,
|
|
name: "Barcode - detect(HTMLImageElement)",
|
|
}
|
|
];
|
|
|
|
for (let imageElementTest of imageElementTests) {
|
|
detection_test(imageElementTest.mockTestName, async (t, detectionTest) => {
|
|
const img = document.getElementById("img");
|
|
|
|
const detector = imageElementTest.createDetector();
|
|
const detectionResult = await detector.detect(img);
|
|
imageElementTest.detectionResultTest(detectionResult, detectionTest);
|
|
}, imageElementTest.name);
|
|
}
|
|
|
|
function FaceDetectorDetectionResultTest(detectionResult, mockTest) {
|
|
const imageReceivedByMock =
|
|
mockTest.MockFaceDetectionProvider().getFrameData();
|
|
assert_equals(imageReceivedByMock.byteLength, 1024, "Image length");
|
|
const GREEN_PIXEL = 0xFF00FF00;
|
|
assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color");
|
|
assert_equals(detectionResult.length, 3, "Number of faces");
|
|
assert_equals(detectionResult[0].landmarks.length, 2, "Number of landmarks");
|
|
assert_object_equals(detectionResult[0].landmarks[0],
|
|
{type : 'eye', locations : [{x : 4.0, y : 5.0}]},
|
|
"landmark #1");
|
|
assert_equals(detectionResult[0].landmarks[1].locations.length, 8,
|
|
"Number of locations along eye");
|
|
assert_object_equals(detectionResult[1].landmarks[0],
|
|
{type : 'nose', locations : [{x : 100.0, y : 50.0}]},
|
|
"landmark #2");
|
|
assert_equals(detectionResult[1].landmarks[1].locations.length, 9,
|
|
"Number of locations along nose");
|
|
}
|
|
|
|
function BarcodeDetectorDetectionResultTest(detectionResult, mockTest) {
|
|
assert_equals(detectionResult.length, 2, "Number of barcodes");
|
|
assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
|
|
assert_equals(detectionResult[0].format, "qr_code", "barcode 1 format");
|
|
assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
|
|
assert_equals(detectionResult[1].format, "code_128", "barcode 2 format");
|
|
}
|
|
|
|
</script>
|