| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="../resources/mojo-helpers.js"></script> |
| <script src="resources/mock-shapedetection.js"></script> |
| <script> |
| |
| var createTestForVideoElement = function(detectorName, detectionResultTest) { |
| async_test(function(t) { |
| var video = document.createElement('video'); |
| video.src = "../imported/wpt/media/white.webm"; |
| video.loop = true; |
| video.autoplay = true; |
| video.onerror = this.unreached_func("<video> error"); |
| video.onplay = this.step_func(function() { |
| var theMock = null; |
| mockShapeDetectionReady |
| .then(mock => { |
| theMock = mock; |
| var detector = eval("new " + detectorName + "();"); |
| return detector; |
| }) |
| .catch(error => { |
| assert_unreached("Error creating MockShapeDetection: " + error); |
| }) |
| .then(detector => { |
| return detector.detect(video); |
| }) |
| .then(detectionResult => { |
| detectionResultTest(detectionResult, theMock); |
| t.done(); |
| }) |
| .catch(error => { |
| assert_unreached("Error during detect(video): " + error); |
| }); |
| }); |
| |
| video.load(); |
| }, 'Detector detect(HTMLVideoElement)'); |
| }; |
| |
| function FaceDetectorDetectionResultTest(detectionResult, mock) { |
| const imageReceivedByMock = mock.getFrameData(); |
| assert_equals(imageReceivedByMock.byteLength, 307200, |
| "Image length"); |
| const WHITE_PIXEL = 0xFFFFFFFF; |
| assert_equals(imageReceivedByMock[0], WHITE_PIXEL, "Pixel color"); |
| 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"); |
| } |
| |
| // These tests verify that a Detector's detect() works on an HTMLVideoElement. |
| // Use the mock mojo server implemented in mock-shapedetection.js. |
| generate_tests(createTestForVideoElement, [ |
| [ "Face", "FaceDetector", FaceDetectorDetectionResultTest ], |
| [ "Barcode", "BarcodeDetector", BarcodeDetectorDetectionResultTest ] |
| ]); |
| |
| </script> |