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