| 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 createTestForImageBitmap = function(detectorName, detectionResultTest) { |
| 9 async_test(function(t) { |
| 10 var img = new Image(); |
| 11 |
| 12 img.onload = function() { |
| 13 var theImageBitmap = null; |
| 14 var theMock = null; |
| 15 |
| 16 createImageBitmap(img) |
| 17 .then(imageBitmap => { |
| 18 theImageBitmap = imageBitmap; |
| 19 return mockShapeDetectionReady; |
| 20 }) |
| 21 .catch(error => { |
| 22 assert_unreached('createImageBitmap() error: ' + error); |
| 23 }) |
| 24 .then(mock => { |
| 25 theMock = mock; |
| 26 var detector = eval("new " + detectorName + "();"); |
| 27 return detector; |
| 28 }) |
| 29 .catch(error => { |
| 30 assert_unreached("Error creating MockShapeDetection: " + error); |
| 31 }) |
| 32 .then(detector => { |
| 33 return detector.detect(theImageBitmap); |
| 34 }) |
| 35 .then(detectionResult => { |
| 36 detectionResultTest(detectionResult, theMock); |
| 37 t.done(); |
| 38 }) |
| 39 .catch(error => { |
| 40 assert_unreached("Error during detect(img): " + error); |
| 41 }); |
| 42 } |
| 43 img.src = '../media/content/greenbox.png'; |
| 44 }, 'Detector detect(ImageBitmap)'); |
| 45 }; |
| 46 |
| 47 function FaceDetectorDetectionResultTest(detectionResult, mock) { |
| 48 const imageReceivedByMock = mock.getFrameData(); |
| 49 assert_equals(imageReceivedByMock.byteLength, 2500,"Image length"); |
| 50 const GREEN_PIXEL = 0xFF00FF00; |
| 51 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color"); |
| 52 assert_equals(detectionResult.length, 3, "Number of faces"); |
| 53 } |
| 54 |
| 55 function BarcodeDetectorDetectionResultTest(detectionResult, mock) { |
| 56 assert_equals(detectionResult.length, 2, "Number of barcodes"); |
| 57 assert_equals(detectionResult[0].rawValue, "cats", "barcode 1"); |
| 58 assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2"); |
| 59 } |
| 60 |
| 61 // These tests verify that a Detector's detect() works on an ImageBitmap. |
| 62 // Use the mock mojo server implemented in mock-shapedetection.js. |
| 63 generate_tests(createTestForImageBitmap, [ |
| 64 [ "Face", "FaceDetector", FaceDetectorDetectionResultTest ], |
| 65 [ "Barcode", "BarcodeDetector", BarcodeDetectorDetectionResultTest ] |
| 66 ]); |
| 67 |
| 68 </script> |
| OLD | NEW |