| <!DOCTYPE html> | |
| <script src="../resources/testharness.js"></script> | |
| <script src="../resources/testharnessreport.js"></script> | |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> | |
| <script src="file:///gen/mojo/public/mojom/base/big_buffer.mojom.js"></script> | |
| <script src="file:///gen/services/shape_detection/public/mojom/barcodedetection.mojom.js"></script> | |
| <script src="file:///gen/services/shape_detection/public/mojom/barcodedetection_provider.mojom.js"></script> | |
| <script src="file:///gen/services/shape_detection/public/mojom/facedetection.mojom.js"></script> | |
| <script src="file:///gen/services/shape_detection/public/mojom/facedetection_provider.mojom.js"></script> | |
| <script src="file:///gen/services/shape_detection/public/mojom/textdetection.mojom.js"></script> | |
| <script src="resources/big-buffer-helpers.js"></script> | |
| <script src="resources/mock-barcodedetection.js"></script> | |
| <script src="resources/mock-facedetection.js"></script> | |
| <script src="resources/mock-textdetection.js"></script> | |
| <body> | |
| <img id="img" src="../media/content/greenbox.png"/> | |
| </body> | |
| <script> | |
| var createTestForImageElement = function(createDetector, mock, | |
| detectionResultTest) { | |
| promise_test(async function() { | |
| var img = document.getElementById("img"); | |
| var detector = createDetector(); | |
| try { | |
| var detectionResult = await detector.detect(img); | |
| detectionResultTest(detectionResult, mock); | |
| } catch(error) { | |
| assert_unreached("Error during detect(img): " + error); | |
| } | |
| }); | |
| }; | |
| function FaceDetectorDetectionResultTest(detectionResult, mock) { | |
| const imageReceivedByMock = mock.getFrameData(); | |
| assert_equals(imageReceivedByMock.byteLength, 2500, "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, mock) { | |
| assert_equals(detectionResult.length, 2, "Number of barcodes"); | |
| assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); | |
| assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); | |
| } | |
| function TextDetectorDetectionResultTest(detectionResult, mock) { | |
| assert_equals(detectionResult.length, 2, "Number of textBlocks"); | |
| assert_equals(detectionResult[0].rawValue, "cats", "textBlock 1"); | |
| assert_equals(detectionResult[1].rawValue, "dogs", "textBlock 2"); | |
| for (i = 0; i < detectionResult.length; i++) { | |
| assert_equals(detectionResult[i].boundingBox.x, detectionResult[i].cornerPoints[0].x); | |
| assert_equals(detectionResult[i].boundingBox.y, detectionResult[i].cornerPoints[0].y); | |
| assert_equals(detectionResult[i].boundingBox.width, | |
| detectionResult[i].cornerPoints[2].x - detectionResult[i].cornerPoints[3].x); | |
| assert_equals(detectionResult[i].boundingBox.height, | |
| detectionResult[i].cornerPoints[2].y - detectionResult[i].cornerPoints[1].y); | |
| } | |
| } | |
| // These tests verify that a Detector's detect() works on an HTMLImageElement. | |
| // Use the mock mojo server implemented in mock-{barcode,face}detection.js. | |
| generate_tests(createTestForImageElement, [ | |
| [ | |
| "Face - detect(HTMLImageElement)", | |
| () => { return new FaceDetector(); }, | |
| mockFaceDetectionProvider, | |
| FaceDetectorDetectionResultTest | |
| ], | |
| [ | |
| "Barcode - detect(HTMLImageElement)", | |
| () => { return new BarcodeDetector(); }, | |
| mockBarcodeDetectionProvider, | |
| BarcodeDetectorDetectionResultTest | |
| ], | |
| [ | |
| "Text - detect(HTMLImageElement)", | |
| () => { return new TextDetector(); }, | |
| mockTextDetection, | |
| TextDetectorDetectionResultTest | |
| ] | |
| ]); | |
| </script> |