| <!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/services/shape_detection/public/interfaces/barcodedetection.mojom.js"></script> |
| <script src="file:///gen/services/shape_detection/public/interfaces/facedetection.mojom.js"></script> |
| <script src="file:///gen/services/shape_detection/public/interfaces/facedetection_provider.mojom.js"></script> |
| <script src="file:///gen/services/shape_detection/public/interfaces/textdetection.mojom.js"></script> |
| <script src="resources/mock-barcodedetection.js"></script> |
| <script src="resources/mock-facedetection.js"></script> |
| <script src="resources/mock-textdetection.js"></script> |
| <script> |
| |
| var createTestForVideoElement = function(createDetector, mock, |
| detectionResultTest) { |
| async_test(function(t) { |
| var video = document.createElement("video"); |
| video.src = "../external/wpt/media/white.webm"; |
| video.loop = true; |
| video.autoplay = true; |
| video.onerror = this.unreached_func("<video> error"); |
| video.onplay = this.step_func(async function() { |
| var detector = createDetector(); |
| try { |
| var detectionResult = await detector.detect(video); |
| detectionResultTest(detectionResult, mock); |
| t.done(); |
| } catch (error) { |
| assert_unreached("Error during detect(video): " + error); |
| } |
| }); |
| |
| video.load(); |
| }); |
| }; |
| |
| function FaceDetectorDetectionResultTest(detectionResult, mock) { |
| const imageReceivedByMock = mock.getFrameData(); |
| assert_equals(imageReceivedByMock.byteLength, 307200, "Image length"); |
| assert_equals(detectionResult.length, 3, "Number of faces"); |
| } |
| |
| 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"); |
| } |
| |
| // These tests verify that a Detector's detect() works on an HTMLVideoElement. |
| // Use the mock mojo server implemented in mock-{barcode,face}detection.js. |
| generate_tests(createTestForVideoElement, [ |
| [ |
| "Face - detect(HTMLVideoElement)", |
| () => { return new FaceDetector(); }, |
| mockFaceDetectionProvider, |
| FaceDetectorDetectionResultTest |
| ], |
| [ |
| "Barcode - detect(HTMLVideoElement)", |
| () => { return new BarcodeDetector(); }, |
| mockBarcodeDetection, |
| BarcodeDetectorDetectionResultTest |
| ], |
| [ |
| "Text - detect(HTMLVideoElement)", |
| () => { return new TextDetector(); }, |
| mockTextDetection, |
| TextDetectorDetectionResultTest |
| ] |
| ]); |
| |
| </script> |