blob: 02d3b0eb4b1ec91d5f400ef590bde0176a315b44 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/mojo-helpers.js"></script>
<script src="resources/mock-shapedetection.js"></script>
<script>
var createTestForImageBitmap = function(detectorName, detectionResultTest) {
async_test(function(t) {
var img = new Image();
img.onload = function() {
var theImageBitmap = null;
var theMock = null;
createImageBitmap(img)
.then(imageBitmap => {
theImageBitmap = imageBitmap;
return mockShapeDetectionReady;
})
.catch(error => {
assert_unreached('createImageBitmap() error: ' + error);
})
.then(mock => {
theMock = mock;
var detector = eval("new " + detectorName + "();");
return detector;
})
.catch(error => {
assert_unreached("Error creating MockShapeDetection: " + error);
})
.then(detector => {
return detector.detect(theImageBitmap);
})
.then(detectionResult => {
detectionResultTest(detectionResult, theMock);
t.done();
})
.catch(error => {
assert_unreached("Error during detect(img): " + error);
});
}
img.src = '../media/content/greenbox.png';
}, 'Detector detect(ImageBitmap)');
};
function FaceDetectorDetectionResultTest(detectionResult, mock) {
const imageReceivedByMock = mock.getFrameData();
assert_equals(imageReceivedByMock.byteLength, 2500,"Image length");
const GREEN_PIXEL = 0xFF00FF00;
assert_equals(imageReceivedByMock[0], GREEN_PIXEL, "Pixel color");
assert_equals(detectionResult.length, 3, "Number of faces");
}
function BarcodeDetectorDetectionResultTest(detectionResult, mock) {
assert_equals(detectionResult.length, 2, "Number of barcodes");
assert_equals(detectionResult[0].rawValue, "cats", "barcode 1");
assert_equals(detectionResult[1].rawValue, "dogs", "barcode 2");
}
// These tests verify that a Detector's detect() works on an ImageBitmap.
// Use the mock mojo server implemented in mock-shapedetection.js.
generate_tests(createTestForImageBitmap, [
[ "Face", "FaceDetector", FaceDetectorDetectionResultTest ],
[ "Barcode", "BarcodeDetector", BarcodeDetectorDetectionResultTest ]
]);
</script>