| 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-shapedetection.js"></script> |
| 6 <script> | 6 <script> |
| 7 | 7 |
| 8 // This test verifies that FaceDetector can detect(ImageBitmap). Uses the mock | 8 // This test verifies that FaceDetector.detect works on an ImageBitmap. |
| 9 // mojo server under mock-shapedetection.js. | 9 // Uses the mock mojo server implemented in mock-shapedetection.js. |
| 10 async_test(function(t) { | 10 async_test(function(t) { |
| 11 var img = new Image(); | 11 var img = new Image(); |
| 12 | 12 |
| 13 img.onload = function() { | 13 img.onload = function() { |
| 14 var theImageBitmap = null; | 14 var theImageBitmap = null; |
| 15 var theMock = null; | 15 var theMock = null; |
| 16 | 16 |
| 17 createImageBitmap(img) | 17 createImageBitmap(img) |
| 18 .then(imageBitmap => { | 18 .then(imageBitmap => { |
| 19 theImageBitmap = imageBitmap; | 19 theImageBitmap = imageBitmap; |
| 20 return mockShapeDetectionReady; | 20 return mockShapeDetectionReady; |
| 21 }) | 21 }) |
| 22 .catch(error => { | 22 .catch(error => { |
| 23 assert_unreached('createImageBitmap() error: ' + error); | 23 assert_unreached('createImageBitmap() error: ' + error); |
| 24 }) | 24 }) |
| 25 .then(mock => { | 25 .then(mock => { |
| 26 theMock = mock; | 26 theMock = mock; |
| 27 return new FaceDetector(); | 27 return new FaceDetector(); |
| 28 }) | 28 }) |
| 29 .catch(error => { | 29 .catch(error => { |
| 30 assert_unreached("Error creating MockShapeDetection: " + error); | 30 assert_unreached("Error creating MockShapeDetection: " + error); |
| 31 }) | 31 }) |
| 32 .then(detector => { | 32 .then(detector => { |
| 33 return detector.detect(theImageBitmap); | 33 return detector.detect(theImageBitmap); |
| 34 }) | 34 }) |
| 35 .then(faceDetectionResult => { | 35 .then(faceDetectionResult => { |
| 36 const imageReceivedByMock = theMock.getFrameData(); | 36 const imageReceivedByMock = theMock.getFrameData(); |
| 37 assert_equals(imageReceivedByMock.byteLength, 2500, | 37 assert_equals(imageReceivedByMock.byteLength, 2500,"Image length"); |
| 38 "imageReceivedByMock.byteLength"); | |
| 39 const GREEN_PIXEL = 0xFF00FF00; | 38 const GREEN_PIXEL = 0xFF00FF00; |
| 40 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "pixel must be gree
n"); | 39 assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color"); |
| 41 assert_equals(faceDetectionResult.length, 3, "faceDetectionResult.leng
th"); | 40 assert_equals(faceDetectionResult.length, 3, "Number of faces"); |
| 42 t.done(); | 41 t.done(); |
| 43 }) | 42 }) |
| 44 .catch(error => { | 43 .catch(error => { |
| 45 assert_unreached("Error during detect(img): " + error); | 44 assert_unreached("Error during detect(img): " + error); |
| 46 }); | 45 }); |
| 47 } | 46 } |
| 48 img.src = '../media/content/greenbox.png'; | 47 img.src = '../media/content/greenbox.png'; |
| 49 }, 'exercises the ShapeDetection API detect(ImageBitmap)'); | 48 }, 'exercises the ShapeDetection API detect(ImageBitmap)'); |
| 50 | 49 |
| 51 </script> | 50 </script> |
| OLD | NEW |