| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> |
| 5 <script src="resources/mock-shapedetection.js"></script> |
| 6 <script> |
| 7 |
| 8 var createTestForVideoElement = function(detectorName, detectionResultTest) { |
| 9 async_test(function(t) { |
| 10 var video = document.createElement('video'); |
| 11 video.src = "../imported/wpt/media/white.webm"; |
| 12 video.loop = true; |
| 13 video.autoplay = true; |
| 14 video.onerror = this.unreached_func("<video> error"); |
| 15 video.onplay = this.step_func(function() { |
| 16 var theMock = null; |
| 17 mockShapeDetectionReady |
| 18 .then(mock => { |
| 19 theMock = mock; |
| 20 var detector = eval("new " + detectorName + "();"); |
| 21 return detector; |
| 22 }) |
| 23 .catch(error => { |
| 24 assert_unreached("Error creating MockShapeDetection: " + error); |
| 25 }) |
| 26 .then(detector => { |
| 27 return detector.detect(video); |
| 28 }) |
| 29 .then(detectionResult => { |
| 30 detectionResultTest(detectionResult, theMock); |
| 31 t.done(); |
| 32 }) |
| 33 .catch(error => { |
| 34 assert_unreached("Error during detect(video): " + error); |
| 35 }); |
| 36 }); |
| 37 |
| 38 video.load(); |
| 39 }, 'Detector detect(HTMLVideoElement)'); |
| 40 }; |
| 41 |
| 42 function FaceDetectorDetectionResultTest(detectionResult, mock) { |
| 43 const imageReceivedByMock = mock.getFrameData(); |
| 44 assert_equals(imageReceivedByMock.byteLength, 307200, |
| 45 "Image length"); |
| 46 const WHITE_PIXEL = 0xFFFFFFFF; |
| 47 assert_equals(imageReceivedByMock[0], WHITE_PIXEL, "Pixel color"); |
| 48 assert_equals(detectionResult.length, 3, "Number of faces"); |
| 49 } |
| 50 |
| 51 function BarcodeDetectorDetectionResultTest(detectionResult, mock) { |
| 52 assert_equals(detectionResult.length, 2, "Number of barcodes"); |
| 53 assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); |
| 54 assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); |
| 55 } |
| 56 |
| 57 // These tests verify that a Detector's detect() works on an HTMLVideoElement. |
| 58 // Use the mock mojo server implemented in mock-shapedetection.js. |
| 59 generate_tests(createTestForVideoElement, [ |
| 60 [ "Face", "FaceDetector", FaceDetectorDetectionResultTest ], |
| 61 [ "Barcode", "BarcodeDetector", BarcodeDetectorDetectionResultTest ] |
| 62 ]); |
| 63 |
| 64 </script> |
| OLD | NEW |