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